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_CONTEXT_H_ | 5 #ifndef CONTENT_NETWORK_NETWORK_CONTEXT_H_ |
6 #define CONTENT_NETWORK_NETWORK_CONTEXT_H_ | 6 #define CONTENT_NETWORK_NETWORK_CONTEXT_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <set> | 11 #include <set> |
12 | 12 |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
15 #include "content/public/common/network_service.mojom.h" | 15 #include "content/public/common/network_service.mojom.h" |
16 #include "content/public/common/url_loader_factory.mojom.h" | 16 #include "content/public/common/url_loader_factory.mojom.h" |
17 #include "mojo/public/cpp/bindings/binding.h" | 17 #include "mojo/public/cpp/bindings/binding.h" |
18 #include "mojo/public/cpp/bindings/strong_binding_set.h" | 18 #include "mojo/public/cpp/bindings/strong_binding_set.h" |
19 | 19 |
20 namespace net { | 20 namespace net { |
21 class URLRequestContext; | 21 class URLRequestContext; |
| 22 class URLRequestContextBuilder; |
22 } | 23 } |
23 | 24 |
24 namespace content { | 25 namespace content { |
25 class NetworkService; | 26 class NetworkServiceImpl; |
26 class URLLoaderImpl; | 27 class URLLoaderImpl; |
27 | 28 |
28 class NetworkContext : public mojom::NetworkContext { | 29 class NetworkContext : public mojom::NetworkContext { |
29 public: | 30 public: |
30 NetworkContext(NetworkService* network_service, | 31 NetworkContext(NetworkServiceImpl* network_service, |
31 mojom::NetworkContextRequest request, | 32 mojom::NetworkContextRequest request, |
32 mojom::NetworkContextParamsPtr params); | 33 mojom::NetworkContextParamsPtr params); |
| 34 |
| 35 // Temporary constructor that allows creating an in-process NetworkContext |
| 36 // with a pre-populated URLRequestContextBuilder. |
| 37 NetworkContext(mojom::NetworkContextRequest request, |
| 38 mojom::NetworkContextParamsPtr params, |
| 39 std::unique_ptr<net::URLRequestContextBuilder> builder); |
| 40 |
33 ~NetworkContext() override; | 41 ~NetworkContext() override; |
34 | 42 |
35 CONTENT_EXPORT static std::unique_ptr<NetworkContext> CreateForTesting(); | 43 CONTENT_EXPORT static std::unique_ptr<NetworkContext> CreateForTesting(); |
36 | 44 |
37 net::URLRequestContext* url_request_context() { | 45 net::URLRequestContext* url_request_context() { |
38 return url_request_context_.get(); | 46 return url_request_context_.get(); |
39 } | 47 } |
40 | 48 |
41 // These are called by individual url loaders as they are being created and | 49 // These are called by individual url loaders as they are being created and |
42 // destroyed. | 50 // destroyed. |
43 void RegisterURLLoader(URLLoaderImpl* url_loader); | 51 void RegisterURLLoader(URLLoaderImpl* url_loader); |
44 void DeregisterURLLoader(URLLoaderImpl* url_loader); | 52 void DeregisterURLLoader(URLLoaderImpl* url_loader); |
45 | 53 |
46 // mojom::NetworkContext implementation: | 54 // mojom::NetworkContext implementation: |
47 void CreateURLLoaderFactory(mojom::URLLoaderFactoryRequest request, | 55 void CreateURLLoaderFactory(mojom::URLLoaderFactoryRequest request, |
48 uint32_t process_id) override; | 56 uint32_t process_id) override; |
49 void HandleViewCacheRequest(const GURL& url, | 57 void HandleViewCacheRequest(const GURL& url, |
50 mojom::URLLoaderClientPtr client) override; | 58 mojom::URLLoaderClientPtr client) override; |
51 | 59 |
52 // Called when the associated NetworkService is going away. Guaranteed to | 60 // Called when the associated NetworkServiceImpl is going away. Guaranteed to |
53 // destroy NetworkContext's URLRequestContext. | 61 // destroy NetworkContext's URLRequestContext. |
54 void Cleanup(); | 62 void Cleanup(); |
55 | 63 |
56 private: | 64 private: |
57 NetworkContext(); | 65 NetworkContext(); |
58 | 66 |
59 // On connection errors the NetworkContext destroys itself. | 67 // On connection errors the NetworkContext destroys itself. |
60 void OnConnectionError(); | 68 void OnConnectionError(); |
61 | 69 |
62 NetworkService* const network_service_; | 70 NetworkServiceImpl* const network_service_; |
63 | 71 |
64 std::unique_ptr<net::URLRequestContext> url_request_context_; | 72 std::unique_ptr<net::URLRequestContext> url_request_context_; |
65 | 73 |
66 // Put it below |url_request_context_| so that it outlives all the | 74 // Put it below |url_request_context_| so that it outlives all the |
67 // NetworkServiceURLLoaderFactoryImpl instances. | 75 // NetworkServiceURLLoaderFactoryImpl instances. |
68 mojo::StrongBindingSet<mojom::URLLoaderFactory> loader_factory_bindings_; | 76 mojo::StrongBindingSet<mojom::URLLoaderFactory> loader_factory_bindings_; |
69 | 77 |
70 // URLLoaderImpls register themselves with the NetworkContext so that they can | 78 // URLLoaderImpls register themselves with the NetworkContext so that they can |
71 // be cleaned up when the NetworkContext goes away. This is needed as | 79 // be cleaned up when the NetworkContext goes away. This is needed as |
72 // net::URLRequests held by URLLoaderImpls have to be gone when | 80 // net::URLRequests held by URLLoaderImpls have to be gone when |
73 // net::URLRequestContext (held by NetworkContext) is destroyed. | 81 // net::URLRequestContext (held by NetworkContext) is destroyed. |
74 std::set<URLLoaderImpl*> url_loaders_; | 82 std::set<URLLoaderImpl*> url_loaders_; |
75 | 83 |
76 mojom::NetworkContextParamsPtr params_; | 84 mojom::NetworkContextParamsPtr params_; |
77 | 85 |
78 mojo::Binding<mojom::NetworkContext> binding_; | 86 mojo::Binding<mojom::NetworkContext> binding_; |
79 | 87 |
80 DISALLOW_COPY_AND_ASSIGN(NetworkContext); | 88 DISALLOW_COPY_AND_ASSIGN(NetworkContext); |
81 }; | 89 }; |
82 | 90 |
83 } // namespace content | 91 } // namespace content |
84 | 92 |
85 #endif // CONTENT_NETWORK_NETWORK_CONTEXT_H_ | 93 #endif // CONTENT_NETWORK_NETWORK_CONTEXT_H_ |
OLD | NEW |