Chromium Code Reviews| Index: content/network/network_service_impl.cc |
| diff --git a/content/network/network_service.cc b/content/network/network_service_impl.cc |
| similarity index 66% |
| rename from content/network/network_service.cc |
| rename to content/network/network_service_impl.cc |
| index a133884b0251b8fe163c130f2c1922c39734b6e1..015997f804fc7b6180b68a49c4afef84e490dad5 100644 |
| --- a/content/network/network_service.cc |
| +++ b/content/network/network_service_impl.cc |
| @@ -2,21 +2,27 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "content/network/network_service.h" |
| +#include "content/network/network_service_impl.h" |
| #include "base/command_line.h" |
| #include "base/logging.h" |
| #include "base/memory/ptr_util.h" |
| +#include "build/build_config.h" |
| #include "content/network/network_context.h" |
| #include "content/public/common/content_switches.h" |
| #include "mojo/public/cpp/bindings/strong_binding.h" |
| #include "net/log/net_log_util.h" |
| #include "net/log/write_to_file_net_log_observer.h" |
| +#include "net/url_request/url_request_context_builder.h" |
| #include "services/service_manager/public/cpp/bind_source_info.h" |
| namespace content { |
| -class NetworkService::MojoNetLog : public net::NetLog { |
| +std::unique_ptr<NetworkService> NetworkService::Create() { |
| + return base::MakeUnique<NetworkServiceImpl>(nullptr); |
| +} |
| + |
| +class NetworkServiceImpl::MojoNetLog : public net::NetLog { |
| public: |
| MojoNetLog() { |
| const base::CommandLine* command_line = |
| @@ -52,17 +58,16 @@ class NetworkService::MojoNetLog : public net::NetLog { |
| DISALLOW_COPY_AND_ASSIGN(MojoNetLog); |
| }; |
| -NetworkService::NetworkService( |
| +NetworkServiceImpl::NetworkServiceImpl( |
| std::unique_ptr<service_manager::BinderRegistry> registry) |
| : net_log_(new MojoNetLog), registry_(std::move(registry)), binding_(this) { |
| - // |registry_| may be nullptr in tests. |
| if (registry_) { |
|
kinuko
2017/07/10 08:10:33
nit: might be still helpful to note when registry_
mmenke
2017/07/10 15:52:22
Done.
|
| registry_->AddInterface<mojom::NetworkService>( |
| - base::Bind(&NetworkService::Create, base::Unretained(this))); |
| + base::Bind(&NetworkServiceImpl::Create, base::Unretained(this))); |
| } |
| } |
| -NetworkService::~NetworkService() { |
| +NetworkServiceImpl::~NetworkServiceImpl() { |
| // Call each Network and ask it to release its net::URLRequestContext, as they |
| // may have references to shared objects owned by the NetworkService. The |
| // NetworkContexts deregister themselves in Cleanup(), so have to be careful. |
| @@ -70,21 +75,36 @@ NetworkService::~NetworkService() { |
| (*network_contexts_.begin())->Cleanup(); |
| } |
| -std::unique_ptr<NetworkService> NetworkService::CreateForTesting() { |
| - return base::WrapUnique(new NetworkService()); |
| +std::unique_ptr<mojom::NetworkContext> |
| +NetworkServiceImpl::CreateNetworkContextWithBuilder( |
| + content::mojom::NetworkContextRequest request, |
| + content::mojom::NetworkContextParamsPtr params, |
| + std::unique_ptr<net::URLRequestContextBuilder> builder, |
| + net::URLRequestContext** url_request_context) { |
| + std::unique_ptr<NetworkContext> network_context = |
| + base::MakeUnique<NetworkContext>(std::move(request), std::move(params), |
| + std::move(builder)); |
| + *url_request_context = network_context->url_request_context(); |
| + return network_context; |
| +} |
| + |
| +std::unique_ptr<NetworkService> NetworkServiceImpl::CreateForTesting() { |
| + return base::WrapUnique(new NetworkServiceImpl(nullptr)); |
| } |
| -void NetworkService::RegisterNetworkContext(NetworkContext* network_context) { |
| +void NetworkServiceImpl::RegisterNetworkContext( |
| + NetworkContext* network_context) { |
| DCHECK_EQ(0u, network_contexts_.count(network_context)); |
| network_contexts_.insert(network_context); |
| } |
| -void NetworkService::DeregisterNetworkContext(NetworkContext* network_context) { |
| +void NetworkServiceImpl::DeregisterNetworkContext( |
| + NetworkContext* network_context) { |
| DCHECK_EQ(1u, network_contexts_.count(network_context)); |
| network_contexts_.erase(network_context); |
| } |
| -void NetworkService::CreateNetworkContext( |
| +void NetworkServiceImpl::CreateNetworkContext( |
| mojom::NetworkContextRequest request, |
| mojom::NetworkContextParamsPtr params) { |
| // The NetworkContext will destroy itself on connection error, or when the |
| @@ -92,9 +112,7 @@ void NetworkService::CreateNetworkContext( |
| new NetworkContext(this, std::move(request), std::move(params)); |
| } |
| -NetworkService::NetworkService() : NetworkService(nullptr) {} |
| - |
| -void NetworkService::OnBindInterface( |
| +void NetworkServiceImpl::OnBindInterface( |
| const service_manager::BindSourceInfo& source_info, |
| const std::string& interface_name, |
| mojo::ScopedMessagePipeHandle interface_pipe) { |
| @@ -102,8 +120,9 @@ void NetworkService::OnBindInterface( |
| std::move(interface_pipe)); |
| } |
| -void NetworkService::Create(const service_manager::BindSourceInfo& source_info, |
| - mojom::NetworkServiceRequest request) { |
| +void NetworkServiceImpl::Create( |
| + const service_manager::BindSourceInfo& source_info, |
| + mojom::NetworkServiceRequest request) { |
| DCHECK(!binding_.is_bound()); |
| binding_.Bind(std::move(request)); |
| } |