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