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

Side by Side Diff: mojo/services/network/network_service_delegate.cc

Issue 1674903003: Extract shell methods from ApplicationImpl into a base class, and pass this to Initialize() instead. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mojom
Patch Set: . Created 4 years, 10 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "mojo/services/network/network_service_delegate.h" 5 #include "mojo/services/network/network_service_delegate.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/at_exit.h" 9 #include "base/at_exit.h"
10 #include "base/base_paths.h" 10 #include "base/base_paths.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 mojo::InterfacePtrInfo<filesystem::Directory> directory_info_; 62 mojo::InterfacePtrInfo<filesystem::Directory> directory_info_;
63 63
64 DISALLOW_COPY_AND_ASSIGN(SQLThread); 64 DISALLOW_COPY_AND_ASSIGN(SQLThread);
65 }; 65 };
66 66
67 } // namespace 67 } // namespace
68 68
69 namespace mojo { 69 namespace mojo {
70 70
71 NetworkServiceDelegate::NetworkServiceDelegate() 71 NetworkServiceDelegate::NetworkServiceDelegate()
72 : app_(nullptr), 72 : shell_(nullptr),
73 binding_(this) { 73 binding_(this) {
74 } 74 }
75 75
76 NetworkServiceDelegate::~NetworkServiceDelegate() { 76 NetworkServiceDelegate::~NetworkServiceDelegate() {
77 } 77 }
78 78
79 void NetworkServiceDelegate::AddObserver( 79 void NetworkServiceDelegate::AddObserver(
80 NetworkServiceDelegateObserver* observer) { 80 NetworkServiceDelegateObserver* observer) {
81 observers_.AddObserver(observer); 81 observers_.AddObserver(observer);
82 } 82 }
83 83
84 void NetworkServiceDelegate::RemoveObserver( 84 void NetworkServiceDelegate::RemoveObserver(
85 NetworkServiceDelegateObserver* observer) { 85 NetworkServiceDelegateObserver* observer) {
86 observers_.RemoveObserver(observer); 86 observers_.RemoveObserver(observer);
87 } 87 }
88 88
89 void NetworkServiceDelegate::Initialize(ApplicationImpl* app) { 89 void NetworkServiceDelegate::Initialize(Shell* shell, const std::string& url,
90 app_ = app; 90 uint32_t id) {
91 shell_ = shell;
91 92
92 #if !defined(OS_ANDROID) 93 #if !defined(OS_ANDROID)
93 // TODO(erg): The following doesn't work when running the android 94 // TODO(erg): The following doesn't work when running the android
94 // apptests. It works in the mandoline shell (on desktop and on android), and 95 // apptests. It works in the mandoline shell (on desktop and on android), and
95 // in the apptests on desktop. However, on android, whenever we make the call 96 // in the apptests on desktop. However, on android, whenever we make the call
96 // to OpenFileSystem, the entire mojo system hangs to the point where writes 97 // to OpenFileSystem, the entire mojo system hangs to the point where writes
97 // to stderr that previously would have printed to our console aren't. The 98 // to stderr that previously would have printed to our console aren't. The
98 // apptests are also fairly resistant to being run under gdb on android. 99 // apptests are also fairly resistant to being run under gdb on android.
99 app_->ConnectToService("mojo:filesystem", &files_); 100 shell_->ConnectToService("mojo:filesystem", &files_);
100 101
101 filesystem::FileError error = filesystem::FileError::FAILED; 102 filesystem::FileError error = filesystem::FileError::FAILED;
102 filesystem::DirectoryPtr directory; 103 filesystem::DirectoryPtr directory;
103 files_->OpenFileSystem("origin", GetProxy(&directory), 104 files_->OpenFileSystem("origin", GetProxy(&directory),
104 binding_.CreateInterfacePtrAndBind(), Capture(&error)); 105 binding_.CreateInterfacePtrAndBind(), Capture(&error));
105 files_.WaitForIncomingResponse(); 106 files_.WaitForIncomingResponse();
106 107
107 io_worker_thread_.reset(new SQLThread(std::move(directory))); 108 io_worker_thread_.reset(new SQLThread(std::move(directory)));
108 #endif 109 #endif
109 110
(...skipping 10 matching lines...) Expand all
120 } else { 121 } else {
121 CHECK(PathService::Get(base::DIR_TEMP, &base_path)); 122 CHECK(PathService::Get(base::DIR_TEMP, &base_path));
122 base_path = base_path.Append(FILE_PATH_LITERAL("network_service")); 123 base_path = base_path.Append(FILE_PATH_LITERAL("network_service"));
123 } 124 }
124 125
125 scoped_refptr<base::SequencedTaskRunner> worker_thread; 126 scoped_refptr<base::SequencedTaskRunner> worker_thread;
126 #if !defined(OS_ANDROID) 127 #if !defined(OS_ANDROID)
127 worker_thread = io_worker_thread_->task_runner(); 128 worker_thread = io_worker_thread_->task_runner();
128 #endif 129 #endif
129 context_.reset(new NetworkContext(base_path, worker_thread, this)); 130 context_.reset(new NetworkContext(base_path, worker_thread, this));
130 tracing_.Initialize(app); 131 tracing_.Initialize(shell_, url);
131 } 132 }
132 133
133 bool NetworkServiceDelegate::AcceptConnection( 134 bool NetworkServiceDelegate::AcceptConnection(
134 ApplicationConnection* connection) { 135 ApplicationConnection* connection) {
135 DCHECK(context_); 136 DCHECK(context_);
136 connection->AddService<CookieStore>(this); 137 connection->AddService<CookieStore>(this);
137 connection->AddService<NetworkService>(this); 138 connection->AddService<NetworkService>(this);
138 connection->AddService<URLLoaderFactory>(this); 139 connection->AddService<URLLoaderFactory>(this);
139 connection->AddService<WebSocketFactory>(this); 140 connection->AddService<WebSocketFactory>(this);
140 return true; 141 return true;
141 } 142 }
142 143
143 bool NetworkServiceDelegate::ShellConnectionLost() { 144 bool NetworkServiceDelegate::ShellConnectionLost() {
144 EnsureIOThreadShutdown(); 145 EnsureIOThreadShutdown();
145 return true; 146 return true;
146 } 147 }
147 148
148 void NetworkServiceDelegate::Quit() { 149 void NetworkServiceDelegate::Quit() {
149 EnsureIOThreadShutdown(); 150 EnsureIOThreadShutdown();
150 151
151 // Destroy the NetworkContext now as it requires MessageLoop::current() upon 152 // Destroy the NetworkContext now as it requires MessageLoop::current() upon
152 // destruction and it is the last moment we know for sure that it is 153 // destruction and it is the last moment we know for sure that it is
153 // running. 154 // running.
154 context_.reset(); 155 context_.reset();
155 } 156 }
156 157
157 void NetworkServiceDelegate::Create(ApplicationConnection* connection, 158 void NetworkServiceDelegate::Create(ApplicationConnection* connection,
158 InterfaceRequest<NetworkService> request) { 159 InterfaceRequest<NetworkService> request) {
159 new NetworkServiceImpl(app_->app_lifetime_helper()->CreateAppRefCount(), 160 new NetworkServiceImpl(shell_->CreateAppRefCount(), std::move(request));
160 std::move(request));
161 } 161 }
162 162
163 void NetworkServiceDelegate::Create(ApplicationConnection* connection, 163 void NetworkServiceDelegate::Create(ApplicationConnection* connection,
164 InterfaceRequest<CookieStore> request) { 164 InterfaceRequest<CookieStore> request) {
165 new CookieStoreImpl( 165 new CookieStoreImpl(
166 context_.get(), GURL(connection->GetRemoteApplicationURL()).GetOrigin(), 166 context_.get(), GURL(connection->GetRemoteApplicationURL()).GetOrigin(),
167 app_->app_lifetime_helper()->CreateAppRefCount(), std::move(request)); 167 shell_->CreateAppRefCount(), std::move(request));
168 } 168 }
169 169
170 void NetworkServiceDelegate::Create( 170 void NetworkServiceDelegate::Create(
171 ApplicationConnection* connection, 171 ApplicationConnection* connection,
172 InterfaceRequest<WebSocketFactory> request) { 172 InterfaceRequest<WebSocketFactory> request) {
173 new WebSocketFactoryImpl(context_.get(), 173 new WebSocketFactoryImpl(context_.get(), shell_->CreateAppRefCount(),
174 app_->app_lifetime_helper()->CreateAppRefCount(),
175 std::move(request)); 174 std::move(request));
176 } 175 }
177 176
178 void NetworkServiceDelegate::Create( 177 void NetworkServiceDelegate::Create(
179 ApplicationConnection* connection, 178 ApplicationConnection* connection,
180 InterfaceRequest<URLLoaderFactory> request) { 179 InterfaceRequest<URLLoaderFactory> request) {
181 new URLLoaderFactoryImpl(context_.get(), 180 new URLLoaderFactoryImpl(context_.get(), shell_->CreateAppRefCount(),
182 app_->app_lifetime_helper()->CreateAppRefCount(),
183 std::move(request)); 181 std::move(request));
184 } 182 }
185 183
186 void NetworkServiceDelegate::OnFileSystemShutdown() { 184 void NetworkServiceDelegate::OnFileSystemShutdown() {
187 EnsureIOThreadShutdown(); 185 EnsureIOThreadShutdown();
188 } 186 }
189 187
190 void NetworkServiceDelegate::EnsureIOThreadShutdown() { 188 void NetworkServiceDelegate::EnsureIOThreadShutdown() {
191 if (io_worker_thread_) { 189 if (io_worker_thread_) {
192 // Broadcast to the entire system that we have to shut down anything 190 // Broadcast to the entire system that we have to shut down anything
193 // depending on the worker thread. Either we're shutting down or the 191 // depending on the worker thread. Either we're shutting down or the
194 // filesystem service is shutting down. 192 // filesystem service is shutting down.
195 FOR_EACH_OBSERVER(NetworkServiceDelegateObserver, observers_, 193 FOR_EACH_OBSERVER(NetworkServiceDelegateObserver, observers_,
196 OnIOWorkerThreadShutdown()); 194 OnIOWorkerThreadShutdown());
197 195
198 // Destroy the io worker thread here so that we can commit any pending 196 // Destroy the io worker thread here so that we can commit any pending
199 // cookies here. 197 // cookies here.
200 io_worker_thread_.reset(); 198 io_worker_thread_.reset();
201 } 199 }
202 } 200 }
203 201
204 } // namespace mojo 202 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/services/network/network_service_delegate.h ('k') | mojo/services/network/udp_socket_apptest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698