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