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

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

Issue 22903025: Send Chrome's process id to the app shim. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix order in app_mode_common Created 7 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 | Annotate | Revision Log
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>
11 11
12 #include "apps/app_shim/app_shim_messages.h" 12 #include "apps/app_shim/app_shim_messages.h"
13 #include "base/at_exit.h" 13 #include "base/at_exit.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/mac/bundle_locations.h" 16 #include "base/mac/bundle_locations.h"
17 #include "base/mac/launch_services_util.h" 17 #include "base/mac/launch_services_util.h"
18 #include "base/mac/mac_logging.h" 18 #include "base/mac/mac_logging.h"
19 #include "base/mac/mac_util.h" 19 #include "base/mac/mac_util.h"
20 #include "base/mac/scoped_nsautorelease_pool.h" 20 #include "base/mac/scoped_nsautorelease_pool.h"
21 #include "base/mac/scoped_nsobject.h" 21 #include "base/mac/scoped_nsobject.h"
22 #include "base/message_loop/message_loop.h" 22 #include "base/message_loop/message_loop.h"
23 #include "base/path_service.h" 23 #include "base/path_service.h"
24 #include "base/strings/string_number_conversions.h"
24 #include "base/strings/sys_string_conversions.h" 25 #include "base/strings/sys_string_conversions.h"
25 #include "base/threading/thread.h" 26 #include "base/threading/thread.h"
26 #include "chrome/common/chrome_constants.h" 27 #include "chrome/common/chrome_constants.h"
27 #include "chrome/common/chrome_paths.h" 28 #include "chrome/common/chrome_paths.h"
28 #include "chrome/common/chrome_switches.h" 29 #include "chrome/common/chrome_switches.h"
29 #include "chrome/common/mac/app_mode_common.h" 30 #include "chrome/common/mac/app_mode_common.h"
30 #include "grit/generated_resources.h" 31 #include "grit/generated_resources.h"
31 #include "ipc/ipc_channel_proxy.h" 32 #include "ipc/ipc_channel_proxy.h"
32 #include "ipc/ipc_listener.h" 33 #include "ipc/ipc_listener.h"
33 #include "ipc/ipc_message.h" 34 #include "ipc/ipc_message.h"
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 ResourceBundle::InitSharedInstanceLocaleOnly(locale, NULL); 426 ResourceBundle::InitSharedInstanceLocaleOnly(locale, NULL);
426 427
427 // Launch the IO thread. 428 // Launch the IO thread.
428 base::Thread::Options io_thread_options; 429 base::Thread::Options io_thread_options;
429 io_thread_options.message_loop_type = base::MessageLoop::TYPE_IO; 430 io_thread_options.message_loop_type = base::MessageLoop::TYPE_IO;
430 base::Thread *io_thread = new base::Thread("CrAppShimIO"); 431 base::Thread *io_thread = new base::Thread("CrAppShimIO");
431 io_thread->StartWithOptions(io_thread_options); 432 io_thread->StartWithOptions(io_thread_options);
432 g_io_thread = io_thread; 433 g_io_thread = io_thread;
433 434
434 // Find already running instances of Chrome. 435 // Find already running instances of Chrome.
435 NSString* chrome_bundle_id = [base::mac::OuterBundle() bundleIdentifier]; 436 pid_t pid = -1;
436 NSArray* existing_chrome = [NSRunningApplication 437 std::string chrome_process_id = CommandLine::ForCurrentProcess()->
437 runningApplicationsWithBundleIdentifier:chrome_bundle_id]; 438 GetSwitchValueASCII(app_mode::kChromeProcessId);
439 if (!chrome_process_id.empty()) {
440 if (!base::StringToInt(chrome_process_id, &pid))
441 pid = -1;
tapted 2013/08/22 06:17:12 This implies it will try to start a new Chrome.. M
jackhou1 2013/08/22 06:52:53 Done.
442 } else {
443 NSString* chrome_bundle_id = [base::mac::OuterBundle() bundleIdentifier];
444 NSArray* existing_chrome = [NSRunningApplication
445 runningApplicationsWithBundleIdentifier:chrome_bundle_id];
446 if ([existing_chrome count] > 0)
447 pid = [[existing_chrome objectAtIndex:0] processIdentifier];
448 }
438 449
439 // Launch Chrome if it isn't already running. 450 // Launch Chrome if it isn't already running.
440 ProcessSerialNumber psn; 451 ProcessSerialNumber psn;
441 if ([existing_chrome count] > 0) { 452 if (pid > -1) {
442 OSStatus status = GetProcessForPID( 453 OSStatus status = GetProcessForPID(pid, &psn);
443 [[existing_chrome objectAtIndex:0] processIdentifier], &psn);
444 if (status) 454 if (status)
445 return 1; 455 return 1;
446 456
447 } else { 457 } else {
448 CommandLine command_line(CommandLine::NO_PROGRAM); 458 CommandLine command_line(CommandLine::NO_PROGRAM);
449 command_line.AppendSwitch(switches::kSilentLaunch); 459 command_line.AppendSwitch(switches::kSilentLaunch);
450 command_line.AppendSwitchPath(switches::kProfileDirectory, 460 command_line.AppendSwitchPath(switches::kProfileDirectory,
451 info->profile_dir); 461 info->profile_dir);
452 bool success = 462 bool success =
453 base::mac::OpenApplicationWithPath(base::mac::OuterBundlePath(), 463 base::mac::OpenApplicationWithPath(base::mac::OuterBundlePath(),
454 command_line, 464 command_line,
455 kLSLaunchDefaults, 465 kLSLaunchDefaults,
456 &psn); 466 &psn);
457 if (!success) 467 if (!success)
458 return 1; 468 return 1;
459 } 469 }
460 470
461 // This code abuses the fact that Apple Events sent before the process is 471 // This code abuses the fact that Apple Events sent before the process is
462 // fully initialized don't receive a reply until its run loop starts. Once 472 // fully initialized don't receive a reply until its run loop starts. Once
463 // the reply is received, Chrome will have opened its IPC port, guaranteed. 473 // the reply is received, Chrome will have opened its IPC port, guaranteed.
464 [ReplyEventHandler pingProcess:psn andCall:base::Bind(&OnPingChromeReply)]; 474 [ReplyEventHandler pingProcess:psn andCall:base::Bind(&OnPingChromeReply)];
465 475
466 base::MessageLoopForUI main_message_loop; 476 base::MessageLoopForUI main_message_loop;
467 main_message_loop.set_thread_name("MainThread"); 477 main_message_loop.set_thread_name("MainThread");
468 base::PlatformThread::SetName("CrAppShimMain"); 478 base::PlatformThread::SetName("CrAppShimMain");
469 main_message_loop.Run(); 479 main_message_loop.Run();
470 return 0; 480 return 0;
471 } 481 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/web_applications/web_app_mac.mm » ('j') | chrome/common/mac/app_mode_common.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698