| 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 #include "content/network/network_context.h" | 5 #include "content/network/network_context.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "components/network_session_configurator/common/network_switches.h" | 10 #include "components/network_session_configurator/common/network_switches.h" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 } | 82 } |
| 83 | 83 |
| 84 return builder.Build(); | 84 return builder.Build(); |
| 85 } | 85 } |
| 86 | 86 |
| 87 } // namespace | 87 } // namespace |
| 88 | 88 |
| 89 NetworkContext::NetworkContext(mojom::NetworkContextRequest request, | 89 NetworkContext::NetworkContext(mojom::NetworkContextRequest request, |
| 90 mojom::NetworkContextParamsPtr params) | 90 mojom::NetworkContextParamsPtr params) |
| 91 : url_request_context_(MakeURLRequestContext()), | 91 : url_request_context_(MakeURLRequestContext()), |
| 92 in_shutdown_(false), | |
| 93 params_(std::move(params)), | 92 params_(std::move(params)), |
| 94 binding_(this, std::move(request)) {} | 93 binding_(this, std::move(request)) {} |
| 95 | 94 |
| 96 NetworkContext::~NetworkContext() { | 95 NetworkContext::~NetworkContext() { |
| 97 in_shutdown_ = true; | |
| 98 // Call each URLLoaderImpl and ask it to release its net::URLRequest, as the | 96 // Call each URLLoaderImpl and ask it to release its net::URLRequest, as the |
| 99 // corresponding net::URLRequestContext is going away with this | 97 // corresponding net::URLRequestContext is going away with this |
| 100 // NetworkContext. The loaders can be deregistering themselves in Cleanup(), | 98 // NetworkContext. The loaders can be deregistering themselves in Cleanup(), |
| 101 // so iterate over a copy. | 99 // so have to be careful. |
| 102 for (auto* url_loader : url_loaders_) | 100 while (!url_loaders_.empty()) |
| 103 url_loader->Cleanup(); | 101 (*url_loaders_.begin())->Cleanup(); |
| 104 } | 102 } |
| 105 | 103 |
| 106 std::unique_ptr<NetworkContext> NetworkContext::CreateForTesting() { | 104 std::unique_ptr<NetworkContext> NetworkContext::CreateForTesting() { |
| 107 return base::WrapUnique(new NetworkContext); | 105 return base::WrapUnique(new NetworkContext); |
| 108 } | 106 } |
| 109 | 107 |
| 110 void NetworkContext::RegisterURLLoader(URLLoaderImpl* url_loader) { | 108 void NetworkContext::RegisterURLLoader(URLLoaderImpl* url_loader) { |
| 111 DCHECK(url_loaders_.count(url_loader) == 0); | 109 DCHECK(url_loaders_.count(url_loader) == 0); |
| 112 url_loaders_.insert(url_loader); | 110 url_loaders_.insert(url_loader); |
| 113 } | 111 } |
| 114 | 112 |
| 115 void NetworkContext::DeregisterURLLoader(URLLoaderImpl* url_loader) { | 113 void NetworkContext::DeregisterURLLoader(URLLoaderImpl* url_loader) { |
| 116 if (!in_shutdown_) { | 114 size_t removed_count = url_loaders_.erase(url_loader); |
| 117 size_t removed_count = url_loaders_.erase(url_loader); | 115 DCHECK(removed_count); |
| 118 DCHECK(removed_count); | |
| 119 } | |
| 120 } | 116 } |
| 121 | 117 |
| 122 void NetworkContext::CreateURLLoaderFactory( | 118 void NetworkContext::CreateURLLoaderFactory( |
| 123 mojom::URLLoaderFactoryRequest request, | 119 mojom::URLLoaderFactoryRequest request, |
| 124 uint32_t process_id) { | 120 uint32_t process_id) { |
| 125 loader_factory_bindings_.AddBinding( | 121 loader_factory_bindings_.AddBinding( |
| 126 base::MakeUnique<NetworkServiceURLLoaderFactoryImpl>(this, process_id), | 122 base::MakeUnique<NetworkServiceURLLoaderFactoryImpl>(this, process_id), |
| 127 std::move(request)); | 123 std::move(request)); |
| 128 } | 124 } |
| 129 | 125 |
| 130 void NetworkContext::HandleViewCacheRequest(const GURL& url, | 126 void NetworkContext::HandleViewCacheRequest(const GURL& url, |
| 131 mojom::URLLoaderClientPtr client) { | 127 mojom::URLLoaderClientPtr client) { |
| 132 StartCacheURLLoader(url, url_request_context_.get(), std::move(client)); | 128 StartCacheURLLoader(url, url_request_context_.get(), std::move(client)); |
| 133 } | 129 } |
| 134 | 130 |
| 135 NetworkContext::NetworkContext() | 131 NetworkContext::NetworkContext() |
| 136 : url_request_context_(MakeURLRequestContext()), | 132 : url_request_context_(MakeURLRequestContext()), |
| 137 in_shutdown_(false), | |
| 138 binding_(this) {} | 133 binding_(this) {} |
| 139 | 134 |
| 140 } // namespace content | 135 } // namespace content |
| OLD | NEW |