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

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
« no previous file with comments | « chrome/service/service_process.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 // If there are no enabled services or if there is an update available 310 // 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 311 // we want to shutdown right away. Else we want to keep listening for
296 // new connections. 312 // new connections.
297 if (!enabled_services_ || update_available_) { 313 if (!enabled_services_ || update_available_) {
298 Shutdown(); 314 Shutdown();
299 return false; 315 return false;
300 } 316 }
301 return true; 317 return true;
302 } 318 }
303 319
320 mojo::ScopedMessagePipeHandle ServiceProcess::CreateChannelMessagePipe() {
321 if (!server_handle_.is_valid()) {
322 #if defined(OS_POSIX)
323 server_handle_ =
324 CreateServerHandle(service_process_state_->GetServiceProcessChannel());
325 #elif defined(OS_WIN)
326 server_handle_ = mojo::edk::NamedPlatformHandle(
327 service_process_state_->GetServiceProcessChannel().name);
328 #endif
329 DCHECK(server_handle_.is_valid());
330 }
331
332 mojo::edk::ScopedPlatformHandle channel_handle;
333 #if defined(OS_POSIX)
334 channel_handle = mojo::edk::DuplicatePlatformHandle(server_handle_.get());
335 #elif defined(OS_WIN)
336 channel_handle = mojo::edk::CreateServerHandle(server_handle_, false);
337 #endif
338 CHECK(channel_handle.is_valid());
339
340 return mojo::edk::ConnectToPeerProcess(std::move(channel_handle));
341 }
342
304 cloud_print::CloudPrintProxy* ServiceProcess::GetCloudPrintProxy() { 343 cloud_print::CloudPrintProxy* ServiceProcess::GetCloudPrintProxy() {
305 if (!cloud_print_proxy_.get()) { 344 if (!cloud_print_proxy_.get()) {
306 cloud_print_proxy_.reset(new cloud_print::CloudPrintProxy()); 345 cloud_print_proxy_.reset(new cloud_print::CloudPrintProxy());
307 cloud_print_proxy_->Initialize(service_prefs_.get(), this); 346 cloud_print_proxy_->Initialize(service_prefs_.get(), this);
308 } 347 }
309 return cloud_print_proxy_.get(); 348 return cloud_print_proxy_.get();
310 } 349 }
311 350
312 void ServiceProcess::OnCloudPrintProxyEnabled(bool persist_state) { 351 void ServiceProcess::OnCloudPrintProxyEnabled(bool persist_state) {
313 if (persist_state) { 352 if (persist_state) {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 } else { 415 } else {
377 Shutdown(); 416 Shutdown();
378 } 417 }
379 } 418 }
380 } 419 }
381 420
382 ServiceProcess::~ServiceProcess() { 421 ServiceProcess::~ServiceProcess() {
383 Teardown(); 422 Teardown();
384 g_service_process = NULL; 423 g_service_process = NULL;
385 } 424 }
OLDNEW
« no previous file with comments | « chrome/service/service_process.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698