| 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" |
| 16 #include "content/common/url_loader_factory.mojom.h" |
| 17 #include "mojo/public/cpp/bindings/binding.h" |
| 18 #include "mojo/public/cpp/bindings/strong_binding_set.h" |
| 15 | 19 |
| 16 namespace net { | 20 namespace net { |
| 17 class URLRequestContext; | 21 class URLRequestContext; |
| 18 } | 22 } |
| 19 | 23 |
| 20 namespace content { | 24 namespace content { |
| 21 class URLLoaderImpl; | 25 class URLLoaderImpl; |
| 22 | 26 |
| 23 class CONTENT_EXPORT NetworkContext { | 27 class NetworkContext : public mojom::NetworkContext { |
| 24 public: | 28 public: |
| 25 NetworkContext(); | 29 NetworkContext(mojom::NetworkContextRequest request, |
| 26 ~NetworkContext(); | 30 mojom::NetworkContextParamsPtr params); |
| 31 ~NetworkContext() override; |
| 32 |
| 33 CONTENT_EXPORT static std::unique_ptr<NetworkContext> CreateForTesting(); |
| 27 | 34 |
| 28 net::URLRequestContext* url_request_context() { | 35 net::URLRequestContext* url_request_context() { |
| 29 return url_request_context_.get(); | 36 return url_request_context_.get(); |
| 30 } | 37 } |
| 31 | 38 |
| 32 // 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 |
| 33 // destroyed. | 40 // destroyed. |
| 34 void RegisterURLLoader(URLLoaderImpl* url_loader); | 41 void RegisterURLLoader(URLLoaderImpl* url_loader); |
| 35 void DeregisterURLLoader(URLLoaderImpl* url_loader); | 42 void DeregisterURLLoader(URLLoaderImpl* url_loader); |
| 36 | 43 |
| 44 // mojom::NetworkContext implementation: |
| 45 void CreateURLLoaderFactory(mojom::URLLoaderFactoryRequest request, |
| 46 uint32_t process_id) override; |
| 47 void HandleViewCacheRequest(const GURL& url, |
| 48 mojom::URLLoaderClientPtr client) override; |
| 49 |
| 37 private: | 50 private: |
| 38 class MojoNetLog; | 51 NetworkContext(); |
| 39 std::unique_ptr<MojoNetLog> net_log_; | |
| 40 | 52 |
| 41 std::unique_ptr<net::URLRequestContext> url_request_context_; | 53 std::unique_ptr<net::URLRequestContext> url_request_context_; |
| 42 | 54 |
| 55 // Put it below |url_request_context_| so that it outlives all the |
| 56 // NetworkServiceURLLoaderFactoryImpl instances. |
| 57 mojo::StrongBindingSet<mojom::URLLoaderFactory> loader_factory_bindings_; |
| 58 |
| 43 // URLLoaderImpls register themselves with the NetworkContext so that they can | 59 // URLLoaderImpls register themselves with the NetworkContext so that they can |
| 44 // 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 |
| 45 // net::URLRequests held by URLLoaderImpls have to be gone when | 61 // net::URLRequests held by URLLoaderImpls have to be gone when |
| 46 // net::URLRequestContext (held by NetworkContext) is destroyed. | 62 // net::URLRequestContext (held by NetworkContext) is destroyed. |
| 47 std::set<URLLoaderImpl*> url_loaders_; | 63 std::set<URLLoaderImpl*> url_loaders_; |
| 48 | 64 |
| 49 // Set when entering the destructor, in order to avoid manipulations of the | 65 // Set when entering the destructor, in order to avoid manipulations of the |
| 50 // |url_loaders_| (as a url_loader might delete itself in Cleanup()). | 66 // |url_loaders_| (as a url_loader might delete itself in Cleanup()). |
| 51 bool in_shutdown_; | 67 bool in_shutdown_; |
| 52 | 68 |
| 69 mojom::NetworkContextParamsPtr params_; |
| 70 |
| 71 mojo::Binding<mojom::NetworkContext> binding_; |
| 72 |
| 53 DISALLOW_COPY_AND_ASSIGN(NetworkContext); | 73 DISALLOW_COPY_AND_ASSIGN(NetworkContext); |
| 54 }; | 74 }; |
| 55 | 75 |
| 56 } // namespace content | 76 } // namespace content |
| 57 | 77 |
| 58 #endif // CONTENT_NETWORK_NETWORK_CONTEXT_H_ | 78 #endif // CONTENT_NETWORK_NETWORK_CONTEXT_H_ |
| OLD | NEW |