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

Side by Side Diff: chrome/service/service_process.cc

Issue 2139643003: Use ChannelMojo between browser and service processes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 3 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/service/service_process.h" 5 #include "chrome/service/service_process.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility>
8 9
9 #include "base/base_switches.h" 10 #include "base/base_switches.h"
10 #include "base/callback.h" 11 #include "base/callback.h"
11 #include "base/command_line.h" 12 #include "base/command_line.h"
12 #include "base/environment.h" 13 #include "base/environment.h"
13 #include "base/i18n/rtl.h" 14 #include "base/i18n/rtl.h"
14 #include "base/location.h" 15 #include "base/location.h"
15 #include "base/macros.h" 16 #include "base/macros.h"
16 #include "base/memory/ptr_util.h" 17 #include "base/memory/ptr_util.h"
17 #include "base/memory/singleton.h" 18 #include "base/memory/singleton.h"
(...skipping 13 matching lines...) Expand all
31 #include "chrome/common/pref_names.h" 32 #include "chrome/common/pref_names.h"
32 #include "chrome/common/service_process_util.h" 33 #include "chrome/common/service_process_util.h"
33 #include "chrome/grit/chromium_strings.h" 34 #include "chrome/grit/chromium_strings.h"
34 #include "chrome/grit/generated_resources.h" 35 #include "chrome/grit/generated_resources.h"
35 #include "chrome/service/cloud_print/cloud_print_message_handler.h" 36 #include "chrome/service/cloud_print/cloud_print_message_handler.h"
36 #include "chrome/service/cloud_print/cloud_print_proxy.h" 37 #include "chrome/service/cloud_print/cloud_print_proxy.h"
37 #include "chrome/service/net/service_url_request_context_getter.h" 38 #include "chrome/service/net/service_url_request_context_getter.h"
38 #include "chrome/service/service_process_prefs.h" 39 #include "chrome/service/service_process_prefs.h"
39 #include "components/prefs/json_pref_store.h" 40 #include "components/prefs/json_pref_store.h"
40 #include "mojo/edk/embedder/embedder.h" 41 #include "mojo/edk/embedder/embedder.h"
42 #include "mojo/edk/embedder/named_platform_handle.h"
43 #include "mojo/edk/embedder/named_platform_handle_utils.h"
44 #include "mojo/edk/embedder/platform_handle_utils.h"
41 #include "mojo/edk/embedder/scoped_ipc_support.h" 45 #include "mojo/edk/embedder/scoped_ipc_support.h"
42 #include "net/base/network_change_notifier.h" 46 #include "net/base/network_change_notifier.h"
43 #include "net/url_request/url_fetcher.h" 47 #include "net/url_request/url_fetcher.h"
44 #include "ui/base/l10n/l10n_util.h" 48 #include "ui/base/l10n/l10n_util.h"
45 #include "ui/base/material_design/material_design_controller.h" 49 #include "ui/base/material_design/material_design_controller.h"
46 #include "ui/base/resource/resource_bundle.h" 50 #include "ui/base/resource/resource_bundle.h"
47 #include "ui/base/ui_base_switches.h" 51 #include "ui/base/ui_base_switches.h"
48 52
49 #if defined(USE_GLIB) 53 #if defined(USE_GLIB)
50 #include <glib-object.h> 54 #include <glib-object.h>
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT))); 115 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT)));
112 base::i18n::AdjustStringForLocaleDirection(&adjusted_string); 116 base::i18n::AdjustStringForLocaleDirection(&adjusted_string);
113 dlg_strings.append(adjusted_string); 117 dlg_strings.append(adjusted_string);
114 dlg_strings.push_back('|'); 118 dlg_strings.push_back('|');
115 dlg_strings.append(base::ASCIIToUTF16( 119 dlg_strings.append(base::ASCIIToUTF16(
116 base::i18n::IsRTL() ? env_vars::kRtlLocale : env_vars::kLtrLocale)); 120 base::i18n::IsRTL() ? env_vars::kRtlLocale : env_vars::kLtrLocale));
117 121
118 env->SetVar(env_vars::kRestartInfo, base::UTF16ToUTF8(dlg_strings)); 122 env->SetVar(env_vars::kRestartInfo, base::UTF16ToUTF8(dlg_strings));
119 } 123 }
120 124
125 #if defined(OS_POSIX)
126 mojo::edk::ScopedPlatformHandle CreateServerHandle(
127 const IPC::ChannelHandle& channel_handle) {
128 #if defined(OS_MACOSX)
129 mojo::edk::PlatformHandle platform_handle(channel_handle.socket.fd);
130 platform_handle.needs_connection = true;
131 return mojo::edk::ScopedPlatformHandle(platform_handle);
132 #else
133 return mojo::edk::CreateServerHandle(
134 mojo::edk::NamedPlatformHandle(channel_handle.name), false);
135 #endif
136 }
137 #endif
138
121 } // namespace 139 } // namespace
122 140
123 ServiceProcess::ServiceProcess() 141 ServiceProcess::ServiceProcess()
124 : shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL, 142 : shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL,
125 base::WaitableEvent::InitialState::NOT_SIGNALED), 143 base::WaitableEvent::InitialState::NOT_SIGNALED),
126 main_message_loop_(NULL), 144 main_message_loop_(NULL),
127 enabled_services_(0), 145 enabled_services_(0),
128 update_available_(false) { 146 update_available_(false) {
129 DCHECK(!g_service_process); 147 DCHECK(!g_service_process);
130 g_service_process = this; 148 g_service_process = this;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 PrepareRestartOnCrashEnviroment(command_line); 216 PrepareRestartOnCrashEnviroment(command_line);
199 217
200 // Enable Cloud Print if needed. First check the command-line. 218 // Enable Cloud Print if needed. First check the command-line.
201 // Then check if the cloud print proxy was previously enabled. 219 // Then check if the cloud print proxy was previously enabled.
202 if (command_line.HasSwitch(switches::kEnableCloudPrintProxy) || 220 if (command_line.HasSwitch(switches::kEnableCloudPrintProxy) ||
203 service_prefs_->GetBoolean(prefs::kCloudPrintProxyEnabled, false)) { 221 service_prefs_->GetBoolean(prefs::kCloudPrintProxyEnabled, false)) {
204 GetCloudPrintProxy()->EnableForUser(); 222 GetCloudPrintProxy()->EnableForUser();
205 } 223 }
206 224
207 VLOG(1) << "Starting Service Process IPC Server"; 225 VLOG(1) << "Starting Service Process IPC Server";
208 ipc_server_.reset(new ServiceIPCServer( 226
209 this /* client */, 227 ipc_server_.reset(new ServiceIPCServer(this /* client */, io_task_runner(),
210 io_task_runner(), 228 &shutdown_event_));
211 service_process_state_->GetServiceProcessChannel(),
212 &shutdown_event_));
213 ipc_server_->AddMessageHandler(base::WrapUnique( 229 ipc_server_->AddMessageHandler(base::WrapUnique(
214 new cloud_print::CloudPrintMessageHandler(ipc_server_.get(), this))); 230 new cloud_print::CloudPrintMessageHandler(ipc_server_.get(), this)));
215 ipc_server_->Init(); 231 ipc_server_->Init();
216 232
217 // After the IPC server has started we signal that the service process is 233 // After the IPC server has started we signal that the service process is
218 // ready. 234 // ready.
219 if (!service_process_state_->SignalReady( 235 if (!service_process_state_->SignalReady(
220 io_task_runner().get(), 236 io_task_runner().get(),
221 base::Bind(&ServiceProcess::Terminate, base::Unretained(this)))) { 237 base::Bind(&ServiceProcess::Terminate, base::Unretained(this)))) {
222 return false; 238 return false;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 } 299 }
284 300
285 void ServiceProcess::OnShutdown() { 301 void ServiceProcess::OnShutdown() {
286 Shutdown(); 302 Shutdown();
287 } 303 }
288 304
289 void ServiceProcess::OnUpdateAvailable() { 305 void ServiceProcess::OnUpdateAvailable() {
290 update_available_ = true; 306 update_available_ = true;
291 } 307 }
292 308
309 void ServiceProcess::OnStayAliveForTesting() {
310 enabled_services_++;
311 }
312
293 bool ServiceProcess::OnIPCClientDisconnect() { 313 bool ServiceProcess::OnIPCClientDisconnect() {
294 // If there are no enabled services or if there is an update available 314 // If there are no enabled services or if there is an update available
295 // we want to shutdown right away. Else we want to keep listening for 315 // we want to shutdown right away. Else we want to keep listening for
296 // new connections. 316 // new connections.
297 if (!enabled_services_ || update_available_) { 317 if (!enabled_services_ || update_available_) {
298 Shutdown(); 318 Shutdown();
299 return false; 319 return false;
300 } 320 }
301 return true; 321 return true;
302 } 322 }
303 323
324 mojo::ScopedMessagePipeHandle ServiceProcess::CreateChannelMessagePipe() {
325 if (!server_handle_.is_valid()) {
326 #if defined(OS_POSIX)
327 server_handle_ =
328 CreateServerHandle(service_process_state_->GetServiceProcessChannel());
329 #elif defined(OS_WIN)
330 server_handle_ = mojo::edk::NamedPlatformHandle(
331 service_process_state_->GetServiceProcessChannel().name);
332 #endif
333 DCHECK(server_handle_.is_valid());
334 }
335
336 mojo::edk::ScopedPlatformHandle channel_handle;
337 #if defined(OS_POSIX)
338 channel_handle = mojo::edk::DuplicatePlatformHandle(server_handle_.get());
339 #elif defined(OS_WIN)
340 channel_handle = mojo::edk::CreateServerHandle(server_handle_, false);
341 #endif
342 CHECK(channel_handle.is_valid());
343
344 return mojo::edk::ConnectToPeerProcess(std::move(channel_handle));
345 }
346
304 cloud_print::CloudPrintProxy* ServiceProcess::GetCloudPrintProxy() { 347 cloud_print::CloudPrintProxy* ServiceProcess::GetCloudPrintProxy() {
305 if (!cloud_print_proxy_.get()) { 348 if (!cloud_print_proxy_.get()) {
306 cloud_print_proxy_.reset(new cloud_print::CloudPrintProxy()); 349 cloud_print_proxy_.reset(new cloud_print::CloudPrintProxy());
307 cloud_print_proxy_->Initialize(service_prefs_.get(), this); 350 cloud_print_proxy_->Initialize(service_prefs_.get(), this);
308 } 351 }
309 return cloud_print_proxy_.get(); 352 return cloud_print_proxy_.get();
310 } 353 }
311 354
312 void ServiceProcess::OnCloudPrintProxyEnabled(bool persist_state) { 355 void ServiceProcess::OnCloudPrintProxyEnabled(bool persist_state) {
313 if (persist_state) { 356 if (persist_state) {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 } else { 419 } else {
377 Shutdown(); 420 Shutdown();
378 } 421 }
379 } 422 }
380 } 423 }
381 424
382 ServiceProcess::~ServiceProcess() { 425 ServiceProcess::~ServiceProcess() {
383 Teardown(); 426 Teardown();
384 g_service_process = NULL; 427 g_service_process = NULL;
385 } 428 }
OLDNEW
« chrome/service/service_ipc_server_unittest.cc ('K') | « chrome/service/service_process.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698