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

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

Issue 1290323002: HTMLViewer no longer connects to NetworkService interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years, 4 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 "base/at_exit.h" 7 #include "base/at_exit.h"
8 #include "base/base_paths.h" 8 #include "base/base_paths.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/path_service.h" 13 #include "base/path_service.h"
14 #include "mojo/application/public/cpp/application_connection.h" 14 #include "mojo/application/public/cpp/application_connection.h"
15 #include "mojo/message_pump/message_pump_mojo.h" 15 #include "mojo/message_pump/message_pump_mojo.h"
16 #include "mojo/services/network/cookie_store_impl.h"
16 #include "mojo/services/network/network_service_delegate_observer.h" 17 #include "mojo/services/network/network_service_delegate_observer.h"
17 #include "mojo/services/network/network_service_impl.h" 18 #include "mojo/services/network/network_service_impl.h"
18 #include "mojo/services/network/url_loader_factory_impl.h" 19 #include "mojo/services/network/url_loader_factory_impl.h"
20 #include "mojo/services/network/web_socket_factory_impl.h"
19 #include "mojo/util/capture_util.h" 21 #include "mojo/util/capture_util.h"
20 #include "sql/mojo/mojo_vfs.h" 22 #include "sql/mojo/mojo_vfs.h"
21 23
22 namespace { 24 namespace {
23 25
24 const char kSQLThreadName[] = "SQL_IO_Thread"; 26 const char kSQLThreadName[] = "SQL_IO_Thread";
25 const char kUserDataDir[] = "user-data-dir"; 27 const char kUserDataDir[] = "user-data-dir";
26 28
27 // SQL blocks on the filesystem service, so perform all SQL functions on a 29 // SQL blocks on the filesystem service, so perform all SQL functions on a
28 // separate thread. 30 // separate thread.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 void NetworkServiceDelegate::AddObserver( 76 void NetworkServiceDelegate::AddObserver(
75 NetworkServiceDelegateObserver* observer) { 77 NetworkServiceDelegateObserver* observer) {
76 observers_.AddObserver(observer); 78 observers_.AddObserver(observer);
77 } 79 }
78 80
79 void NetworkServiceDelegate::RemoveObserver( 81 void NetworkServiceDelegate::RemoveObserver(
80 NetworkServiceDelegateObserver* observer) { 82 NetworkServiceDelegateObserver* observer) {
81 observers_.RemoveObserver(observer); 83 observers_.RemoveObserver(observer);
82 } 84 }
83 85
84 void NetworkServiceDelegate::Initialize(mojo::ApplicationImpl* app) { 86 void NetworkServiceDelegate::Initialize(ApplicationImpl* app) {
85 app_ = app; 87 app_ = app;
86 88
87 #if !defined(OS_ANDROID) 89 #if !defined(OS_ANDROID)
88 // TODO(erg): The following doesn't work when running the android 90 // TODO(erg): The following doesn't work when running the android
89 // apptests. It works in the mandoline shell (on desktop and on android), and 91 // apptests. It works in the mandoline shell (on desktop and on android), and
90 // in the apptests on desktop. However, on android, whenever we make the call 92 // in the apptests on desktop. However, on android, whenever we make the call
91 // to OpenFileSystem, the entire mojo system hangs to the point where writes 93 // to OpenFileSystem, the entire mojo system hangs to the point where writes
92 // to stderr that previously would have printed to our console aren't. The 94 // to stderr that previously would have printed to our console aren't. The
93 // apptests are also fairly resistant to being run under gdb on android. 95 // apptests are also fairly resistant to being run under gdb on android.
94 mojo::URLRequestPtr request(mojo::URLRequest::New()); 96 URLRequestPtr request(URLRequest::New());
95 request->url = mojo::String::From("mojo:filesystem"); 97 request->url = String::From("mojo:filesystem");
96 app_->ConnectToService(request.Pass(), &files_); 98 app_->ConnectToService(request.Pass(), &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), client.Pass(),
104 mojo::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(directory.Pass()));
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();
118 if (command_line->HasSwitch(kUserDataDir)) { 120 if (command_line->HasSwitch(kUserDataDir)) {
119 base_path = command_line->GetSwitchValuePath(kUserDataDir); 121 base_path = command_line->GetSwitchValuePath(kUserDataDir);
120 } else { 122 } else {
121 CHECK(PathService::Get(base::DIR_TEMP, &base_path)); 123 CHECK(PathService::Get(base::DIR_TEMP, &base_path));
122 base_path = base_path.Append(FILE_PATH_LITERAL("network_service")); 124 base_path = base_path.Append(FILE_PATH_LITERAL("network_service"));
123 } 125 }
124 126
125 scoped_refptr<base::SequencedTaskRunner> worker_thread; 127 scoped_refptr<base::SequencedTaskRunner> worker_thread;
126 #if !defined(OS_ANDROID) 128 #if !defined(OS_ANDROID)
127 worker_thread = io_worker_thread_->task_runner(); 129 worker_thread = io_worker_thread_->task_runner();
128 #endif 130 #endif
129 context_.reset(new mojo::NetworkContext(base_path, worker_thread, this)); 131 context_.reset(new NetworkContext(base_path, worker_thread, this));
130 } 132 }
131 133
132 bool NetworkServiceDelegate::ConfigureIncomingConnection( 134 bool NetworkServiceDelegate::ConfigureIncomingConnection(
133 mojo::ApplicationConnection* connection) { 135 ApplicationConnection* connection) {
134 DCHECK(context_); 136 DCHECK(context_);
135 connection->AddService<mojo::NetworkService>(this); 137 connection->AddService<CookieStore>(this);
136 connection->AddService<mojo::URLLoaderFactory>(this); 138 connection->AddService<NetworkService>(this);
139 connection->AddService<URLLoaderFactory>(this);
140 connection->AddService<WebSocketFactory>(this);
137 return true; 141 return true;
138 } 142 }
139 143
140 bool NetworkServiceDelegate::OnShellConnectionError() { 144 bool NetworkServiceDelegate::OnShellConnectionError() {
141 EnsureIOThreadShutdown(); 145 EnsureIOThreadShutdown();
142 return true; 146 return true;
143 } 147 }
144 148
145 void NetworkServiceDelegate::Quit() { 149 void NetworkServiceDelegate::Quit() {
146 EnsureIOThreadShutdown(); 150 EnsureIOThreadShutdown();
147 151
148 // Destroy the NetworkContext now as it requires MessageLoop::current() upon 152 // Destroy the NetworkContext now as it requires MessageLoop::current() upon
149 // 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
150 // running. 154 // running.
151 context_.reset(); 155 context_.reset();
152 } 156 }
153 157
154 void NetworkServiceDelegate::Create( 158 void NetworkServiceDelegate::Create(ApplicationConnection* connection,
155 mojo::ApplicationConnection* connection, 159 InterfaceRequest<NetworkService> request) {
156 mojo::InterfaceRequest<mojo::NetworkService> request) { 160 new NetworkServiceImpl(app_->app_lifetime_helper()->CreateAppRefCount(),
157 new mojo::NetworkServiceImpl( 161 request.Pass());
158 connection, 162 }
159 context_.get(), 163
160 app_->app_lifetime_helper()->CreateAppRefCount(), 164 void NetworkServiceDelegate::Create(ApplicationConnection* connection,
161 request.Pass()); 165 InterfaceRequest<CookieStore> request) {
166 new CookieStoreImpl(context_.get(),
167 GURL(connection->GetRemoteApplicationURL()).GetOrigin(),
168 app_->app_lifetime_helper()->CreateAppRefCount(),
169 request.Pass());
162 } 170 }
163 171
164 void NetworkServiceDelegate::Create( 172 void NetworkServiceDelegate::Create(
165 mojo::ApplicationConnection* connection, 173 ApplicationConnection* connection,
166 mojo::InterfaceRequest<mojo::URLLoaderFactory> request) { 174 InterfaceRequest<WebSocketFactory> request) {
167 new mojo::URLLoaderFactoryImpl( 175 new WebSocketFactoryImpl(context_.get(),
168 connection, 176 app_->app_lifetime_helper()->CreateAppRefCount(),
169 context_.get(), 177 request.Pass());
170 app_->app_lifetime_helper()->CreateAppRefCount(), 178 }
171 request.Pass()); 179
180 void NetworkServiceDelegate::Create(
181 ApplicationConnection* connection,
182 InterfaceRequest<URLLoaderFactory> request) {
183 new URLLoaderFactoryImpl(context_.get(),
184 app_->app_lifetime_helper()->CreateAppRefCount(),
185 request.Pass());
172 } 186 }
173 187
174 void NetworkServiceDelegate::OnFileSystemShutdown() { 188 void NetworkServiceDelegate::OnFileSystemShutdown() {
175 EnsureIOThreadShutdown(); 189 EnsureIOThreadShutdown();
176 } 190 }
177 191
178 void NetworkServiceDelegate::EnsureIOThreadShutdown() { 192 void NetworkServiceDelegate::EnsureIOThreadShutdown() {
179 if (io_worker_thread_) { 193 if (io_worker_thread_) {
180 // 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
181 // 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
182 // filesystem service is shutting down. 196 // filesystem service is shutting down.
183 FOR_EACH_OBSERVER(NetworkServiceDelegateObserver, observers_, 197 FOR_EACH_OBSERVER(NetworkServiceDelegateObserver, observers_,
184 OnIOWorkerThreadShutdown()); 198 OnIOWorkerThreadShutdown());
185 199
186 // 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
187 // cookies here. 201 // cookies here.
188 io_worker_thread_.reset(); 202 io_worker_thread_.reset();
189 } 203 }
190 } 204 }
191 205
192 } // namespace mojo 206 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/services/network/network_service_delegate.h ('k') | mojo/services/network/network_service_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698