proxy_resolver_factory_impl.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright 2015 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef SERVICES_PROXY_RESOLVER_PROXY_RESOLVER_FACTORY_IMPL_H_
  5. #define SERVICES_PROXY_RESOLVER_PROXY_RESOLVER_FACTORY_IMPL_H_
  6. #include <map>
  7. #include <memory>
  8. #include <string>
  9. #include "base/callback.h"
  10. #include "mojo/public/cpp/bindings/pending_receiver.h"
  11. #include "mojo/public/cpp/bindings/receiver.h"
  12. #include "mojo/public/cpp/bindings/unique_receiver_set.h"
  13. #include "services/proxy_resolver/public/mojom/proxy_resolver.mojom.h"
  14. namespace proxy_resolver {
  15. class ProxyResolverV8TracingFactory;
  16. // mojom::ProxyResolverFactory implementation that handles multiple bound pipes.
  17. class ProxyResolverFactoryImpl : public mojom::ProxyResolverFactory {
  18. public:
  19. explicit ProxyResolverFactoryImpl(
  20. mojo::PendingReceiver<mojom::ProxyResolverFactory> receiver);
  21. ProxyResolverFactoryImpl(const ProxyResolverFactoryImpl&) = delete;
  22. ProxyResolverFactoryImpl& operator=(const ProxyResolverFactoryImpl&) = delete;
  23. ~ProxyResolverFactoryImpl() override;
  24. // Used by jobs to pass ownership of a newly bound ProxyResolver to this
  25. // factory.
  26. void AddResolver(std::unique_ptr<mojom::ProxyResolver> resolver,
  27. mojo::PendingReceiver<mojom::ProxyResolver> receiver);
  28. protected:
  29. // Visible for tests.
  30. ProxyResolverFactoryImpl(
  31. mojo::PendingReceiver<mojom::ProxyResolverFactory> receiver,
  32. std::unique_ptr<ProxyResolverV8TracingFactory> proxy_resolver_factory);
  33. private:
  34. class Job;
  35. // mojom::ProxyResolverFactory override.
  36. void CreateResolver(
  37. const std::string& pac_script,
  38. mojo::PendingReceiver<mojom::ProxyResolver> receiver,
  39. mojo::PendingRemote<mojom::ProxyResolverFactoryRequestClient> client)
  40. override;
  41. void RemoveJob(Job* job);
  42. const std::unique_ptr<ProxyResolverV8TracingFactory>
  43. proxy_resolver_impl_factory_;
  44. std::map<Job*, std::unique_ptr<Job>> jobs_;
  45. mojo::Receiver<mojom::ProxyResolverFactory> receiver_;
  46. mojo::UniqueReceiverSet<mojom::ProxyResolver> resolvers_;
  47. };
  48. } // namespace proxy_resolver
  49. #endif // SERVICES_PROXY_RESOLVER_PROXY_RESOLVER_FACTORY_IMPL_H_