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_H_ |
6 #define CONTENT_NETWORK_NETWORK_SERVICE_H_ | 6 #define CONTENT_NETWORK_NETWORK_SERVICE_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/network_service.mojom.h" | 12 #include "content/common/network_service.mojom.h" |
12 #include "mojo/public/cpp/bindings/binding.h" | 13 #include "mojo/public/cpp/bindings/binding.h" |
13 #include "services/service_manager/public/cpp/binder_registry.h" | 14 #include "services/service_manager/public/cpp/binder_registry.h" |
14 #include "services/service_manager/public/cpp/service.h" | 15 #include "services/service_manager/public/cpp/service.h" |
15 | 16 |
16 namespace content { | 17 namespace content { |
17 | 18 |
| 19 class NetworkContext; |
| 20 |
18 class NetworkService : public service_manager::Service, | 21 class NetworkService : public service_manager::Service, |
19 public mojom::NetworkService { | 22 public mojom::NetworkService { |
20 public: | 23 public: |
21 explicit NetworkService( | 24 explicit NetworkService( |
22 std::unique_ptr<service_manager::BinderRegistry> registry); | 25 std::unique_ptr<service_manager::BinderRegistry> registry); |
23 ~NetworkService() override; | 26 ~NetworkService() override; |
24 | 27 |
| 28 CONTENT_EXPORT static std::unique_ptr<NetworkService> CreateForTesting(); |
| 29 |
| 30 // These are called by NetworkContexts as they are being created and |
| 31 // destroyed. |
| 32 void RegisterNetworkContext(NetworkContext* network_context); |
| 33 void DeregisterNetworkContext(NetworkContext* network_context); |
| 34 |
| 35 // mojom::NetworkService implementation: |
| 36 void CreateNetworkContext(mojom::NetworkContextRequest request, |
| 37 mojom::NetworkContextParamsPtr params) override; |
| 38 |
25 private: | 39 private: |
26 class MojoNetLog; | 40 class MojoNetLog; |
27 | 41 |
| 42 // Used for tests. |
| 43 NetworkService(); |
| 44 |
28 // service_manager::Service implementation. | 45 // service_manager::Service implementation. |
29 void OnBindInterface(const service_manager::BindSourceInfo& source_info, | 46 void OnBindInterface(const service_manager::BindSourceInfo& source_info, |
30 const std::string& interface_name, | 47 const std::string& interface_name, |
31 mojo::ScopedMessagePipeHandle interface_pipe) override; | 48 mojo::ScopedMessagePipeHandle interface_pipe) override; |
32 | 49 |
33 void Create(const service_manager::BindSourceInfo& source_info, | 50 void Create(const service_manager::BindSourceInfo& source_info, |
34 mojom::NetworkServiceRequest request); | 51 mojom::NetworkServiceRequest request); |
35 | 52 |
36 // mojom::NetworkService implementation: | |
37 void CreateNetworkContext(mojom::NetworkContextRequest request, | |
38 mojom::NetworkContextParamsPtr params) override; | |
39 | |
40 std::unique_ptr<MojoNetLog> net_log_; | 53 std::unique_ptr<MojoNetLog> net_log_; |
41 | 54 |
42 std::unique_ptr<service_manager::BinderRegistry> registry_; | 55 std::unique_ptr<service_manager::BinderRegistry> registry_; |
43 | 56 |
44 mojo::Binding<mojom::NetworkService> binding_; | 57 mojo::Binding<mojom::NetworkService> binding_; |
45 | 58 |
| 59 // NetworkContexts register themselves with the NetworkService so that they |
| 60 // can be cleaned up when the NetworkService goes away. This is needed as |
| 61 // NetworkContexts share global state with the NetworkService, so must be |
| 62 // destroyed first. |
| 63 std::set<NetworkContext*> network_contexts_; |
| 64 |
46 DISALLOW_COPY_AND_ASSIGN(NetworkService); | 65 DISALLOW_COPY_AND_ASSIGN(NetworkService); |
47 }; | 66 }; |
48 | 67 |
49 } // namespace content | 68 } // namespace content |
50 | 69 |
51 #endif // CONTENT_NETWORK_NETWORK_SERVICE_H_ | 70 #endif // CONTENT_NETWORK_NETWORK_SERVICE_H_ |
OLD | NEW |