| 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> | 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" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
| 17 #include "mojo/message_pump/message_pump_mojo.h" | 17 #include "mojo/message_pump/message_pump_mojo.h" |
| 18 #include "mojo/services/network/cookie_store_impl.h" | 18 #include "mojo/services/network/cookie_store_impl.h" |
| 19 #include "mojo/services/network/network_service_delegate_observer.h" | 19 #include "mojo/services/network/network_service_delegate_observer.h" |
| 20 #include "mojo/services/network/network_service_impl.h" | 20 #include "mojo/services/network/network_service_impl.h" |
| 21 #include "mojo/services/network/url_loader_factory_impl.h" | 21 #include "mojo/services/network/url_loader_factory_impl.h" |
| 22 #include "mojo/services/network/web_socket_factory_impl.h" | 22 #include "mojo/services/network/web_socket_factory_impl.h" |
| 23 #include "mojo/shell/public/cpp/application_connection.h" | 23 #include "mojo/shell/public/cpp/connection.h" |
| 24 #include "mojo/util/capture_util.h" | 24 #include "mojo/util/capture_util.h" |
| 25 #include "sql/mojo/mojo_vfs.h" | 25 #include "sql/mojo/mojo_vfs.h" |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 const char kSQLThreadName[] = "SQL_IO_Thread"; | 29 const char kSQLThreadName[] = "SQL_IO_Thread"; |
| 30 const char kUserDataDir[] = "user-data-dir"; | 30 const char kUserDataDir[] = "user-data-dir"; |
| 31 | 31 |
| 32 // SQL blocks on the filesystem service, so perform all SQL functions on a | 32 // SQL blocks on the filesystem service, so perform all SQL functions on a |
| 33 // separate thread. | 33 // separate thread. |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 } | 124 } |
| 125 | 125 |
| 126 scoped_refptr<base::SequencedTaskRunner> worker_thread; | 126 scoped_refptr<base::SequencedTaskRunner> worker_thread; |
| 127 #if !defined(OS_ANDROID) | 127 #if !defined(OS_ANDROID) |
| 128 worker_thread = io_worker_thread_->task_runner(); | 128 worker_thread = io_worker_thread_->task_runner(); |
| 129 #endif | 129 #endif |
| 130 context_.reset(new NetworkContext(base_path, worker_thread, this)); | 130 context_.reset(new NetworkContext(base_path, worker_thread, this)); |
| 131 tracing_.Initialize(shell_, url); | 131 tracing_.Initialize(shell_, url); |
| 132 } | 132 } |
| 133 | 133 |
| 134 bool NetworkServiceDelegate::AcceptConnection( | 134 bool NetworkServiceDelegate::AcceptConnection(Connection* connection) { |
| 135 ApplicationConnection* connection) { | |
| 136 DCHECK(context_); | 135 DCHECK(context_); |
| 137 connection->AddService<CookieStore>(this); | 136 connection->AddService<CookieStore>(this); |
| 138 connection->AddService<NetworkService>(this); | 137 connection->AddService<NetworkService>(this); |
| 139 connection->AddService<URLLoaderFactory>(this); | 138 connection->AddService<URLLoaderFactory>(this); |
| 140 connection->AddService<WebSocketFactory>(this); | 139 connection->AddService<WebSocketFactory>(this); |
| 141 return true; | 140 return true; |
| 142 } | 141 } |
| 143 | 142 |
| 144 bool NetworkServiceDelegate::ShellConnectionLost() { | 143 bool NetworkServiceDelegate::ShellConnectionLost() { |
| 145 EnsureIOThreadShutdown(); | 144 EnsureIOThreadShutdown(); |
| 146 return true; | 145 return true; |
| 147 } | 146 } |
| 148 | 147 |
| 149 void NetworkServiceDelegate::Quit() { | 148 void NetworkServiceDelegate::Quit() { |
| 150 EnsureIOThreadShutdown(); | 149 EnsureIOThreadShutdown(); |
| 151 | 150 |
| 152 // Destroy the NetworkContext now as it requires MessageLoop::current() upon | 151 // Destroy the NetworkContext now as it requires MessageLoop::current() upon |
| 153 // destruction and it is the last moment we know for sure that it is | 152 // destruction and it is the last moment we know for sure that it is |
| 154 // running. | 153 // running. |
| 155 context_.reset(); | 154 context_.reset(); |
| 156 } | 155 } |
| 157 | 156 |
| 158 void NetworkServiceDelegate::Create(ApplicationConnection* connection, | 157 void NetworkServiceDelegate::Create(Connection* connection, |
| 159 InterfaceRequest<NetworkService> request) { | 158 InterfaceRequest<NetworkService> request) { |
| 160 new NetworkServiceImpl(shell_->CreateAppRefCount(), std::move(request)); | 159 new NetworkServiceImpl(shell_->CreateAppRefCount(), std::move(request)); |
| 161 } | 160 } |
| 162 | 161 |
| 163 void NetworkServiceDelegate::Create(ApplicationConnection* connection, | 162 void NetworkServiceDelegate::Create(Connection* connection, |
| 164 InterfaceRequest<CookieStore> request) { | 163 InterfaceRequest<CookieStore> request) { |
| 165 new CookieStoreImpl( | 164 new CookieStoreImpl( |
| 166 context_.get(), GURL(connection->GetRemoteApplicationURL()).GetOrigin(), | 165 context_.get(), GURL(connection->GetRemoteApplicationURL()).GetOrigin(), |
| 167 shell_->CreateAppRefCount(), std::move(request)); | 166 shell_->CreateAppRefCount(), std::move(request)); |
| 168 } | 167 } |
| 169 | 168 |
| 170 void NetworkServiceDelegate::Create( | 169 void NetworkServiceDelegate::Create( |
| 171 ApplicationConnection* connection, | 170 Connection* connection, |
| 172 InterfaceRequest<WebSocketFactory> request) { | 171 InterfaceRequest<WebSocketFactory> request) { |
| 173 new WebSocketFactoryImpl(context_.get(), shell_->CreateAppRefCount(), | 172 new WebSocketFactoryImpl(context_.get(), shell_->CreateAppRefCount(), |
| 174 std::move(request)); | 173 std::move(request)); |
| 175 } | 174 } |
| 176 | 175 |
| 177 void NetworkServiceDelegate::Create( | 176 void NetworkServiceDelegate::Create( |
| 178 ApplicationConnection* connection, | 177 Connection* connection, |
| 179 InterfaceRequest<URLLoaderFactory> request) { | 178 InterfaceRequest<URLLoaderFactory> request) { |
| 180 new URLLoaderFactoryImpl(context_.get(), shell_->CreateAppRefCount(), | 179 new URLLoaderFactoryImpl(context_.get(), shell_->CreateAppRefCount(), |
| 181 std::move(request)); | 180 std::move(request)); |
| 182 } | 181 } |
| 183 | 182 |
| 184 void NetworkServiceDelegate::OnFileSystemShutdown() { | 183 void NetworkServiceDelegate::OnFileSystemShutdown() { |
| 185 EnsureIOThreadShutdown(); | 184 EnsureIOThreadShutdown(); |
| 186 } | 185 } |
| 187 | 186 |
| 188 void NetworkServiceDelegate::EnsureIOThreadShutdown() { | 187 void NetworkServiceDelegate::EnsureIOThreadShutdown() { |
| 189 if (io_worker_thread_) { | 188 if (io_worker_thread_) { |
| 190 // Broadcast to the entire system that we have to shut down anything | 189 // Broadcast to the entire system that we have to shut down anything |
| 191 // depending on the worker thread. Either we're shutting down or the | 190 // depending on the worker thread. Either we're shutting down or the |
| 192 // filesystem service is shutting down. | 191 // filesystem service is shutting down. |
| 193 FOR_EACH_OBSERVER(NetworkServiceDelegateObserver, observers_, | 192 FOR_EACH_OBSERVER(NetworkServiceDelegateObserver, observers_, |
| 194 OnIOWorkerThreadShutdown()); | 193 OnIOWorkerThreadShutdown()); |
| 195 | 194 |
| 196 // Destroy the io worker thread here so that we can commit any pending | 195 // Destroy the io worker thread here so that we can commit any pending |
| 197 // cookies here. | 196 // cookies here. |
| 198 io_worker_thread_.reset(); | 197 io_worker_thread_.reset(); |
| 199 } | 198 } |
| 200 } | 199 } |
| 201 | 200 |
| 202 } // namespace mojo | 201 } // namespace mojo |
| OLD | NEW |