Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_NETWORK_NETWORK_SERVICE_H_ | 5 #ifndef CONTENT_NETWORK_NETWORK_SERVICE_IMPL_H_ |
| 6 #define CONTENT_NETWORK_NETWORK_SERVICE_H_ | 6 #define CONTENT_NETWORK_NETWORK_SERVICE_IMPL_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "content/common/content_export.h" | 11 #include "content/common/content_export.h" |
| 12 #include "content/public/common/network_service.mojom.h" | 12 #include "content/public/common/network_service.mojom.h" |
| 13 #include "content/public/network/network_service.h" | |
| 13 #include "mojo/public/cpp/bindings/binding.h" | 14 #include "mojo/public/cpp/bindings/binding.h" |
| 14 #include "services/service_manager/public/cpp/binder_registry.h" | 15 #include "services/service_manager/public/cpp/binder_registry.h" |
| 15 #include "services/service_manager/public/cpp/service.h" | 16 #include "services/service_manager/public/cpp/service.h" |
| 16 | 17 |
| 18 namespace net { | |
| 19 class URLRequestContext; | |
| 20 class URLRequestContextBuilder; | |
| 21 } // namespace net | |
| 22 | |
| 17 namespace content { | 23 namespace content { |
| 18 | 24 |
| 19 class NetworkContext; | 25 class NetworkContext; |
| 20 | 26 |
| 21 class NetworkService : public service_manager::Service, | 27 class CONTENT_EXPORT NetworkServiceImpl : public service_manager::Service, |
| 22 public mojom::NetworkService { | 28 public NetworkService { |
| 23 public: | 29 public: |
| 24 explicit NetworkService( | 30 explicit NetworkServiceImpl( |
| 25 std::unique_ptr<service_manager::BinderRegistry> registry); | 31 std::unique_ptr<service_manager::BinderRegistry> registry); |
| 26 ~NetworkService() override; | |
| 27 | 32 |
| 28 CONTENT_EXPORT static std::unique_ptr<NetworkService> CreateForTesting(); | 33 ~NetworkServiceImpl() override; |
| 34 | |
| 35 std::unique_ptr<mojom::NetworkContext> CreateNetworkContextWithBuilder( | |
| 36 content::mojom::NetworkContextRequest request, | |
| 37 content::mojom::NetworkContextParamsPtr params, | |
| 38 std::unique_ptr<net::URLRequestContextBuilder> builder, | |
| 39 net::URLRequestContext** url_request_context) override; | |
| 40 | |
| 41 static std::unique_ptr<NetworkService> CreateForTesting(); | |
| 29 | 42 |
| 30 // These are called by NetworkContexts as they are being created and | 43 // These are called by NetworkContexts as they are being created and |
| 31 // destroyed. | 44 // destroyed. |
| 32 void RegisterNetworkContext(NetworkContext* network_context); | 45 void RegisterNetworkContext(NetworkContext* network_context); |
| 33 void DeregisterNetworkContext(NetworkContext* network_context); | 46 void DeregisterNetworkContext(NetworkContext* network_context); |
| 34 | 47 |
| 35 // mojom::NetworkService implementation: | 48 // mojom::NetworkService implementation: |
| 36 void CreateNetworkContext(mojom::NetworkContextRequest request, | 49 void CreateNetworkContext(mojom::NetworkContextRequest request, |
| 37 mojom::NetworkContextParamsPtr params) override; | 50 mojom::NetworkContextParamsPtr params) override; |
| 38 | 51 |
| 39 private: | 52 private: |
| 53 friend class NetworkService; | |
|
jam
2017/07/08 01:30:08
why is this needed?
mmenke
2017/07/10 15:52:22
Removed. It's not, added it for a new private con
| |
| 54 | |
| 40 class MojoNetLog; | 55 class MojoNetLog; |
| 41 | 56 |
| 42 // Used for tests. | |
| 43 NetworkService(); | |
| 44 | |
| 45 // service_manager::Service implementation. | 57 // service_manager::Service implementation. |
| 46 void OnBindInterface(const service_manager::BindSourceInfo& source_info, | 58 void OnBindInterface(const service_manager::BindSourceInfo& source_info, |
| 47 const std::string& interface_name, | 59 const std::string& interface_name, |
| 48 mojo::ScopedMessagePipeHandle interface_pipe) override; | 60 mojo::ScopedMessagePipeHandle interface_pipe) override; |
| 49 | 61 |
| 50 void Create(const service_manager::BindSourceInfo& source_info, | 62 void Create(const service_manager::BindSourceInfo& source_info, |
| 51 mojom::NetworkServiceRequest request); | 63 mojom::NetworkServiceRequest request); |
| 52 | 64 |
| 53 std::unique_ptr<MojoNetLog> net_log_; | 65 std::unique_ptr<MojoNetLog> net_log_; |
| 54 | 66 |
| 55 std::unique_ptr<service_manager::BinderRegistry> registry_; | 67 std::unique_ptr<service_manager::BinderRegistry> registry_; |
| 56 | 68 |
| 57 mojo::Binding<mojom::NetworkService> binding_; | 69 mojo::Binding<mojom::NetworkService> binding_; |
| 58 | 70 |
| 59 // NetworkContexts register themselves with the NetworkService so that they | 71 // NetworkContexts register themselves with the NetworkService so that they |
| 60 // can be cleaned up when the NetworkService goes away. This is needed as | 72 // can be cleaned up when the NetworkService goes away. This is needed as |
| 61 // NetworkContexts share global state with the NetworkService, so must be | 73 // NetworkContexts share global state with the NetworkService, so must be |
| 62 // destroyed first. | 74 // destroyed first. |
| 63 std::set<NetworkContext*> network_contexts_; | 75 std::set<NetworkContext*> network_contexts_; |
| 64 | 76 |
| 65 DISALLOW_COPY_AND_ASSIGN(NetworkService); | 77 DISALLOW_COPY_AND_ASSIGN(NetworkServiceImpl); |
| 66 }; | 78 }; |
| 67 | 79 |
| 68 } // namespace content | 80 } // namespace content |
| 69 | 81 |
| 70 #endif // CONTENT_NETWORK_NETWORK_SERVICE_H_ | 82 #endif // CONTENT_NETWORK_NETWORK_SERVICE_IMPL_H_ |
| OLD | NEW |