Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(266)

Side by Side Diff: content/network/network_service.cc

Issue 2962693002: NetworkService: Destroy NetworkContexts on NetworkService teardown. (Closed)
Patch Set: Fix a couple comments Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/network/network_service.h ('k') | content/network/network_service_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_service.h" 5 #include "content/network/network_service.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/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "content/network/network_context.h" 10 #include "content/network/network_context.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 } 48 }
49 49
50 private: 50 private:
51 std::unique_ptr<net::WriteToFileNetLogObserver> write_to_file_observer_; 51 std::unique_ptr<net::WriteToFileNetLogObserver> write_to_file_observer_;
52 DISALLOW_COPY_AND_ASSIGN(MojoNetLog); 52 DISALLOW_COPY_AND_ASSIGN(MojoNetLog);
53 }; 53 };
54 54
55 NetworkService::NetworkService( 55 NetworkService::NetworkService(
56 std::unique_ptr<service_manager::BinderRegistry> registry) 56 std::unique_ptr<service_manager::BinderRegistry> registry)
57 : net_log_(new MojoNetLog), registry_(std::move(registry)), binding_(this) { 57 : net_log_(new MojoNetLog), registry_(std::move(registry)), binding_(this) {
58 registry_->AddInterface<mojom::NetworkService>( 58 // |registry_| may be nullptr in tests.
59 base::Bind(&NetworkService::Create, base::Unretained(this))); 59 if (registry_) {
60 registry_->AddInterface<mojom::NetworkService>(
61 base::Bind(&NetworkService::Create, base::Unretained(this)));
62 }
60 } 63 }
61 64
62 NetworkService::~NetworkService() = default; 65 NetworkService::~NetworkService() {
66 // Call each Network and ask it to release its net::URLRequestContext, as they
67 // may have references to shared objects owned by the NetworkService. The
68 // NetworkContexts deregister themselves in Cleanup(), so have to be careful.
69 while (!network_contexts_.empty())
70 (*network_contexts_.begin())->Cleanup();
71 }
72
73 std::unique_ptr<NetworkService> NetworkService::CreateForTesting() {
74 return base::WrapUnique(new NetworkService());
75 }
76
77 void NetworkService::RegisterNetworkContext(NetworkContext* network_context) {
78 DCHECK_EQ(0u, network_contexts_.count(network_context));
79 network_contexts_.insert(network_context);
80 }
81
82 void NetworkService::DeregisterNetworkContext(NetworkContext* network_context) {
83 DCHECK_EQ(1u, network_contexts_.count(network_context));
84 network_contexts_.erase(network_context);
85 }
86
87 void NetworkService::CreateNetworkContext(
88 mojom::NetworkContextRequest request,
89 mojom::NetworkContextParamsPtr params) {
90 // The NetworkContext will destroy itself on connection error, or when the
91 // service is destroyed.
92 new NetworkContext(this, std::move(request), std::move(params));
93 }
94
95 NetworkService::NetworkService() : NetworkService(nullptr) {}
63 96
64 void NetworkService::OnBindInterface( 97 void NetworkService::OnBindInterface(
65 const service_manager::BindSourceInfo& source_info, 98 const service_manager::BindSourceInfo& source_info,
66 const std::string& interface_name, 99 const std::string& interface_name,
67 mojo::ScopedMessagePipeHandle interface_pipe) { 100 mojo::ScopedMessagePipeHandle interface_pipe) {
68 registry_->BindInterface(source_info, interface_name, 101 registry_->BindInterface(source_info, interface_name,
69 std::move(interface_pipe)); 102 std::move(interface_pipe));
70 } 103 }
71 104
72 void NetworkService::Create(const service_manager::BindSourceInfo& source_info, 105 void NetworkService::Create(const service_manager::BindSourceInfo& source_info,
73 mojom::NetworkServiceRequest request) { 106 mojom::NetworkServiceRequest request) {
74 DCHECK(!binding_.is_bound()); 107 DCHECK(!binding_.is_bound());
75 binding_.Bind(std::move(request)); 108 binding_.Bind(std::move(request));
76 } 109 }
77 110
78 void NetworkService::CreateNetworkContext(
79 mojom::NetworkContextRequest request,
80 mojom::NetworkContextParamsPtr params) {
81 mojo::MakeStrongBinding(
82 base::MakeUnique<NetworkContext>(std::move(request), std::move(params)),
83 std::move(request));
84 }
85
86 } // namespace content 111 } // namespace content
OLDNEW
« no previous file with comments | « content/network/network_service.h ('k') | content/network/network_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698