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

Side by Side Diff: chrome/app_shim/chrome_main_app_mode_mac.mm

Issue 2295063002: Use ChannelMojo between app shims and the browser process. (Closed)
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/app_shim/DEPS ('k') | chrome/browser/apps/app_shim/DEPS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 // On Mac, one can't make shortcuts with command-line arguments. Instead, we 5 // On Mac, one can't make shortcuts with command-line arguments. Instead, we
6 // produce small app bundles which locate the Chromium framework and load it, 6 // produce small app bundles which locate the Chromium framework and load it,
7 // passing the appropriate data. This is the entry point into the framework for 7 // passing the appropriate data. This is the entry point into the framework for
8 // those app bundles. 8 // those app bundles.
9 9
10 #import <Cocoa/Cocoa.h> 10 #import <Cocoa/Cocoa.h>
(...skipping 16 matching lines...) Expand all
27 #include "base/message_loop/message_loop.h" 27 #include "base/message_loop/message_loop.h"
28 #include "base/strings/string_number_conversions.h" 28 #include "base/strings/string_number_conversions.h"
29 #include "base/strings/sys_string_conversions.h" 29 #include "base/strings/sys_string_conversions.h"
30 #include "base/threading/thread.h" 30 #include "base/threading/thread.h"
31 #include "chrome/common/chrome_constants.h" 31 #include "chrome/common/chrome_constants.h"
32 #include "chrome/common/chrome_paths.h" 32 #include "chrome/common/chrome_paths.h"
33 #include "chrome/common/chrome_switches.h" 33 #include "chrome/common/chrome_switches.h"
34 #include "chrome/common/mac/app_mode_common.h" 34 #include "chrome/common/mac/app_mode_common.h"
35 #include "chrome/common/mac/app_shim_messages.h" 35 #include "chrome/common/mac/app_shim_messages.h"
36 #include "chrome/grit/generated_resources.h" 36 #include "chrome/grit/generated_resources.h"
37 #include "ipc/ipc_channel_mojo.h"
37 #include "ipc/ipc_channel_proxy.h" 38 #include "ipc/ipc_channel_proxy.h"
38 #include "ipc/ipc_listener.h" 39 #include "ipc/ipc_listener.h"
39 #include "ipc/ipc_message.h" 40 #include "ipc/ipc_message.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/scoped_ipc_support.h"
45 #include "mojo/edk/embedder/scoped_platform_handle.h"
40 #include "ui/base/l10n/l10n_util.h" 46 #include "ui/base/l10n/l10n_util.h"
41 #include "ui/base/resource/resource_bundle.h" 47 #include "ui/base/resource/resource_bundle.h"
42 48
43 namespace { 49 namespace {
44 50
45 // Timeout in seconds to wait for a reply for the initial Apple Event. Note that 51 // Timeout in seconds to wait for a reply for the initial Apple Event. Note that
46 // kAEDefaultTimeout on Mac is "about one minute" according to Apple's 52 // kAEDefaultTimeout on Mac is "about one minute" according to Apple's
47 // documentation, but is no longer supported for asynchronous Apple Events. 53 // documentation, but is no longer supported for asynchronous Apple Events.
48 const int kPingChromeTimeoutSeconds = 60; 54 const int kPingChromeTimeoutSeconds = 60;
49 55
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 return; 211 return;
206 } 212 }
207 213
208 app_mode::VerifySocketPermissions(socket_path); 214 app_mode::VerifySocketPermissions(socket_path);
209 215
210 CreateChannelAndSendLaunchApp(socket_path); 216 CreateChannelAndSendLaunchApp(socket_path);
211 } 217 }
212 218
213 void AppShimController::CreateChannelAndSendLaunchApp( 219 void AppShimController::CreateChannelAndSendLaunchApp(
214 const base::FilePath& socket_path) { 220 const base::FilePath& socket_path) {
215 IPC::ChannelHandle handle(socket_path.value()); 221 channel_ = IPC::ChannelProxy::Create(
216 channel_ = IPC::ChannelProxy::Create(handle, IPC::Channel::MODE_NAMED_CLIENT, 222 IPC::ChannelMojo::CreateClientFactory(
217 this, g_io_thread->task_runner().get()); 223 mojo::edk::ConnectToPeerProcess(mojo::edk::CreateClientHandle(
224 mojo::edk::NamedPlatformHandle(socket_path.value()))),
225 g_io_thread->task_runner().get()),
226 this, g_io_thread->task_runner().get());
218 227
219 bool launched_by_chrome = base::CommandLine::ForCurrentProcess()->HasSwitch( 228 bool launched_by_chrome = base::CommandLine::ForCurrentProcess()->HasSwitch(
220 app_mode::kLaunchedByChromeProcessId); 229 app_mode::kLaunchedByChromeProcessId);
221 apps::AppShimLaunchType launch_type = launched_by_chrome ? 230 apps::AppShimLaunchType launch_type = launched_by_chrome ?
222 apps::APP_SHIM_LAUNCH_REGISTER_ONLY : apps::APP_SHIM_LAUNCH_NORMAL; 231 apps::APP_SHIM_LAUNCH_REGISTER_ONLY : apps::APP_SHIM_LAUNCH_NORMAL;
223 232
224 [delegate_ setController:this]; 233 [delegate_ setController:this];
225 234
226 std::vector<base::FilePath> files; 235 std::vector<base::FilePath> files;
227 [delegate_ getFilesToOpenAtStartup:&files]; 236 [delegate_ getFilesToOpenAtStartup:&files];
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 ui::ResourceBundle::InitSharedInstanceWithLocale( 631 ui::ResourceBundle::InitSharedInstanceWithLocale(
623 locale, NULL, ui::ResourceBundle::DO_NOT_LOAD_COMMON_RESOURCES); 632 locale, NULL, ui::ResourceBundle::DO_NOT_LOAD_COMMON_RESOURCES);
624 633
625 // Launch the IO thread. 634 // Launch the IO thread.
626 base::Thread::Options io_thread_options; 635 base::Thread::Options io_thread_options;
627 io_thread_options.message_loop_type = base::MessageLoop::TYPE_IO; 636 io_thread_options.message_loop_type = base::MessageLoop::TYPE_IO;
628 base::Thread *io_thread = new base::Thread("CrAppShimIO"); 637 base::Thread *io_thread = new base::Thread("CrAppShimIO");
629 io_thread->StartWithOptions(io_thread_options); 638 io_thread->StartWithOptions(io_thread_options);
630 g_io_thread = io_thread; 639 g_io_thread = io_thread;
631 640
641 mojo::edk::Init();
642 mojo::edk::ScopedIPCSupport ipc_support(io_thread->task_runner());
643
632 // Find already running instances of Chrome. 644 // Find already running instances of Chrome.
633 pid_t pid = -1; 645 pid_t pid = -1;
634 std::string chrome_process_id = 646 std::string chrome_process_id =
635 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 647 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
636 app_mode::kLaunchedByChromeProcessId); 648 app_mode::kLaunchedByChromeProcessId);
637 if (!chrome_process_id.empty()) { 649 if (!chrome_process_id.empty()) {
638 if (!base::StringToInt(chrome_process_id, &pid)) 650 if (!base::StringToInt(chrome_process_id, &pid))
639 LOG(FATAL) << "Invalid PID: " << chrome_process_id; 651 LOG(FATAL) << "Invalid PID: " << chrome_process_id;
640 } else { 652 } else {
641 NSString* chrome_bundle_id = [base::mac::OuterBundle() bundleIdentifier]; 653 NSString* chrome_bundle_id = [base::mac::OuterBundle() bundleIdentifier];
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 // which is preferable to waiting for the Apple Event to timeout after one 708 // which is preferable to waiting for the Apple Event to timeout after one
697 // minute. 709 // minute.
698 main_message_loop.task_runner()->PostTask( 710 main_message_loop.task_runner()->PostTask(
699 FROM_HERE, 711 FROM_HERE,
700 base::Bind(&AppShimController::Init, base::Unretained(&controller))); 712 base::Bind(&AppShimController::Init, base::Unretained(&controller)));
701 } 713 }
702 714
703 main_message_loop.Run(); 715 main_message_loop.Run();
704 return 0; 716 return 0;
705 } 717 }
OLDNEW
« no previous file with comments | « chrome/app_shim/DEPS ('k') | chrome/browser/apps/app_shim/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698