OLD | NEW |
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> |
| 8 |
7 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
8 #include "base/base_paths.h" | 10 #include "base/base_paths.h" |
9 #include "base/bind.h" | 11 #include "base/bind.h" |
10 #include "base/command_line.h" | 12 #include "base/command_line.h" |
11 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
12 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
13 #include "base/path_service.h" | 15 #include "base/path_service.h" |
14 #include "mojo/application/public/cpp/application_connection.h" | 16 #include "mojo/application/public/cpp/application_connection.h" |
15 #include "mojo/message_pump/message_pump_mojo.h" | 17 #include "mojo/message_pump/message_pump_mojo.h" |
16 #include "mojo/services/network/cookie_store_impl.h" | 18 #include "mojo/services/network/cookie_store_impl.h" |
17 #include "mojo/services/network/network_service_delegate_observer.h" | 19 #include "mojo/services/network/network_service_delegate_observer.h" |
18 #include "mojo/services/network/network_service_impl.h" | 20 #include "mojo/services/network/network_service_impl.h" |
19 #include "mojo/services/network/url_loader_factory_impl.h" | 21 #include "mojo/services/network/url_loader_factory_impl.h" |
20 #include "mojo/services/network/web_socket_factory_impl.h" | 22 #include "mojo/services/network/web_socket_factory_impl.h" |
21 #include "mojo/util/capture_util.h" | 23 #include "mojo/util/capture_util.h" |
22 #include "sql/mojo/mojo_vfs.h" | 24 #include "sql/mojo/mojo_vfs.h" |
23 | 25 |
24 namespace { | 26 namespace { |
25 | 27 |
26 const char kSQLThreadName[] = "SQL_IO_Thread"; | 28 const char kSQLThreadName[] = "SQL_IO_Thread"; |
27 const char kUserDataDir[] = "user-data-dir"; | 29 const char kUserDataDir[] = "user-data-dir"; |
28 | 30 |
29 // SQL blocks on the filesystem service, so perform all SQL functions on a | 31 // SQL blocks on the filesystem service, so perform all SQL functions on a |
30 // separate thread. | 32 // separate thread. |
31 class SQLThread : public base::Thread { | 33 class SQLThread : public base::Thread { |
32 public: | 34 public: |
33 SQLThread(filesystem::DirectoryPtr directory) | 35 SQLThread(filesystem::DirectoryPtr directory) |
34 : base::Thread(kSQLThreadName), | 36 : base::Thread(kSQLThreadName), |
35 directory_info_(directory.PassInterface().Pass()) { | 37 directory_info_(directory.PassInterface()) { |
36 base::Thread::Options options; | 38 base::Thread::Options options; |
37 options.message_pump_factory = | 39 options.message_pump_factory = |
38 base::Bind(&mojo::common::MessagePumpMojo::Create); | 40 base::Bind(&mojo::common::MessagePumpMojo::Create); |
39 StartWithOptions(options); | 41 StartWithOptions(options); |
40 } | 42 } |
41 ~SQLThread() override { Stop(); } | 43 ~SQLThread() override { Stop(); } |
42 | 44 |
43 void Init() override { | 45 void Init() override { |
44 filesystem::DirectoryPtr directory; | 46 filesystem::DirectoryPtr directory; |
45 directory.Bind(directory_info_.Pass()); | 47 directory.Bind(std::move(directory_info_)); |
46 vfs_.reset(new sql::ScopedMojoFilesystemVFS(directory.Pass())); | 48 vfs_.reset(new sql::ScopedMojoFilesystemVFS(std::move(directory))); |
47 } | 49 } |
48 | 50 |
49 void CleanUp() override { | 51 void CleanUp() override { |
50 vfs_.reset(); | 52 vfs_.reset(); |
51 } | 53 } |
52 | 54 |
53 private: | 55 private: |
54 // Our VFS which wraps sqlite so that we can reuse the current sqlite code. | 56 // Our VFS which wraps sqlite so that we can reuse the current sqlite code. |
55 scoped_ptr<sql::ScopedMojoFilesystemVFS> vfs_; | 57 scoped_ptr<sql::ScopedMojoFilesystemVFS> vfs_; |
56 | 58 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 // to OpenFileSystem, the entire mojo system hangs to the point where writes | 95 // to OpenFileSystem, the entire mojo system hangs to the point where writes |
94 // to stderr that previously would have printed to our console aren't. The | 96 // to stderr that previously would have printed to our console aren't. The |
95 // apptests are also fairly resistant to being run under gdb on android. | 97 // apptests are also fairly resistant to being run under gdb on android. |
96 app_->ConnectToService("mojo:filesystem", &files_); | 98 app_->ConnectToService("mojo:filesystem", &files_); |
97 | 99 |
98 filesystem::FileSystemClientPtr client; | 100 filesystem::FileSystemClientPtr client; |
99 binding_.Bind(GetProxy(&client)); | 101 binding_.Bind(GetProxy(&client)); |
100 | 102 |
101 filesystem::FileError error = filesystem::FILE_ERROR_FAILED; | 103 filesystem::FileError error = filesystem::FILE_ERROR_FAILED; |
102 filesystem::DirectoryPtr directory; | 104 filesystem::DirectoryPtr directory; |
103 files_->OpenFileSystem("origin", GetProxy(&directory), client.Pass(), | 105 files_->OpenFileSystem("origin", GetProxy(&directory), std::move(client), |
104 Capture(&error)); | 106 Capture(&error)); |
105 files_.WaitForIncomingResponse(); | 107 files_.WaitForIncomingResponse(); |
106 | 108 |
107 io_worker_thread_.reset(new SQLThread(directory.Pass())); | 109 io_worker_thread_.reset(new SQLThread(std::move(directory))); |
108 #endif | 110 #endif |
109 | 111 |
110 // TODO(erg): Find everything else that writes to the filesystem and | 112 // TODO(erg): Find everything else that writes to the filesystem and |
111 // transition it to proxying mojo:filesystem. We shouldn't have any path | 113 // transition it to proxying mojo:filesystem. We shouldn't have any path |
112 // calculation code here, but sadly need it until the transition is done. In | 114 // calculation code here, but sadly need it until the transition is done. In |
113 // the mean time, manually handle the user-data-dir switch (which gets set in | 115 // the mean time, manually handle the user-data-dir switch (which gets set in |
114 // tests) so that tests are writing to a temp dir. | 116 // tests) so that tests are writing to a temp dir. |
115 base::FilePath base_path; | 117 base::FilePath base_path; |
116 const base::CommandLine* command_line = | 118 const base::CommandLine* command_line = |
117 base::CommandLine::ForCurrentProcess(); | 119 base::CommandLine::ForCurrentProcess(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 | 152 |
151 // Destroy the NetworkContext now as it requires MessageLoop::current() upon | 153 // 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 | 154 // destruction and it is the last moment we know for sure that it is |
153 // running. | 155 // running. |
154 context_.reset(); | 156 context_.reset(); |
155 } | 157 } |
156 | 158 |
157 void NetworkServiceDelegate::Create(ApplicationConnection* connection, | 159 void NetworkServiceDelegate::Create(ApplicationConnection* connection, |
158 InterfaceRequest<NetworkService> request) { | 160 InterfaceRequest<NetworkService> request) { |
159 new NetworkServiceImpl(app_->app_lifetime_helper()->CreateAppRefCount(), | 161 new NetworkServiceImpl(app_->app_lifetime_helper()->CreateAppRefCount(), |
160 request.Pass()); | 162 std::move(request)); |
161 } | 163 } |
162 | 164 |
163 void NetworkServiceDelegate::Create(ApplicationConnection* connection, | 165 void NetworkServiceDelegate::Create(ApplicationConnection* connection, |
164 InterfaceRequest<CookieStore> request) { | 166 InterfaceRequest<CookieStore> request) { |
165 new CookieStoreImpl(context_.get(), | 167 new CookieStoreImpl( |
166 GURL(connection->GetRemoteApplicationURL()).GetOrigin(), | 168 context_.get(), GURL(connection->GetRemoteApplicationURL()).GetOrigin(), |
167 app_->app_lifetime_helper()->CreateAppRefCount(), | 169 app_->app_lifetime_helper()->CreateAppRefCount(), std::move(request)); |
168 request.Pass()); | |
169 } | 170 } |
170 | 171 |
171 void NetworkServiceDelegate::Create( | 172 void NetworkServiceDelegate::Create( |
172 ApplicationConnection* connection, | 173 ApplicationConnection* connection, |
173 InterfaceRequest<WebSocketFactory> request) { | 174 InterfaceRequest<WebSocketFactory> request) { |
174 new WebSocketFactoryImpl(context_.get(), | 175 new WebSocketFactoryImpl(context_.get(), |
175 app_->app_lifetime_helper()->CreateAppRefCount(), | 176 app_->app_lifetime_helper()->CreateAppRefCount(), |
176 request.Pass()); | 177 std::move(request)); |
177 } | 178 } |
178 | 179 |
179 void NetworkServiceDelegate::Create( | 180 void NetworkServiceDelegate::Create( |
180 ApplicationConnection* connection, | 181 ApplicationConnection* connection, |
181 InterfaceRequest<URLLoaderFactory> request) { | 182 InterfaceRequest<URLLoaderFactory> request) { |
182 new URLLoaderFactoryImpl(context_.get(), | 183 new URLLoaderFactoryImpl(context_.get(), |
183 app_->app_lifetime_helper()->CreateAppRefCount(), | 184 app_->app_lifetime_helper()->CreateAppRefCount(), |
184 request.Pass()); | 185 std::move(request)); |
185 } | 186 } |
186 | 187 |
187 void NetworkServiceDelegate::OnFileSystemShutdown() { | 188 void NetworkServiceDelegate::OnFileSystemShutdown() { |
188 EnsureIOThreadShutdown(); | 189 EnsureIOThreadShutdown(); |
189 } | 190 } |
190 | 191 |
191 void NetworkServiceDelegate::EnsureIOThreadShutdown() { | 192 void NetworkServiceDelegate::EnsureIOThreadShutdown() { |
192 if (io_worker_thread_) { | 193 if (io_worker_thread_) { |
193 // Broadcast to the entire system that we have to shut down anything | 194 // Broadcast to the entire system that we have to shut down anything |
194 // depending on the worker thread. Either we're shutting down or the | 195 // depending on the worker thread. Either we're shutting down or the |
195 // filesystem service is shutting down. | 196 // filesystem service is shutting down. |
196 FOR_EACH_OBSERVER(NetworkServiceDelegateObserver, observers_, | 197 FOR_EACH_OBSERVER(NetworkServiceDelegateObserver, observers_, |
197 OnIOWorkerThreadShutdown()); | 198 OnIOWorkerThreadShutdown()); |
198 | 199 |
199 // Destroy the io worker thread here so that we can commit any pending | 200 // Destroy the io worker thread here so that we can commit any pending |
200 // cookies here. | 201 // cookies here. |
201 io_worker_thread_.reset(); | 202 io_worker_thread_.reset(); |
202 } | 203 } |
203 } | 204 } |
204 | 205 |
205 } // namespace mojo | 206 } // namespace mojo |
OLD | NEW |