1 // Copyright 2012 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/app/chrome_main_mac.h"
7 #import <Cocoa/Cocoa.h>
11 #import "base/apple/bundle_locations.h"
12 #import "base/apple/foundation_util.h"
13 #include "base/command_line.h"
14 #include "base/files/file_path.h"
15 #include "base/path_service.h"
16 #include "base/strings/string_util.h"
17 #include "base/strings/sys_string_conversions.h"
18 #include "chrome/common/chrome_constants.h"
19 #include "chrome/common/chrome_paths_internal.h"
20 #include "content/public/common/content_paths.h"
21 #include "content/public/common/content_switches.h"
23 void SetUpBundleOverrides() {
25 base::apple::SetOverrideFrameworkBundlePath(
26 chrome::GetFrameworkBundlePath());
28 NSBundle* base_bundle = chrome::OuterAppBundle();
29 base::apple::SetBaseBundleID(base_bundle.bundleIdentifier.UTF8String);
31 base::FilePath child_exe_path =
32 chrome::GetFrameworkBundlePath().Append("Helpers").Append(
33 chrome::kHelperProcessExecutablePath);
35 // On the Mac, the child executable lives at a predefined location within
36 // the app bundle's versioned directory.
37 base::PathService::OverrideAndCreateIfNeeded(
38 content::CHILD_PROCESS_EXE, child_exe_path, /*is_absolute=*/true,
43 bool IsAlertsHelperLaunchedViaNotificationAction() {
44 // We allow the main Chrome app to be launched via a notification action. We
45 // detect and log that to UMA by checking the passed in NSNotification in
46 // -applicationDidFinishLaunching: (//chrome/browser/app_controller_mac.mm).
47 if (!base::apple::IsBackgroundOnlyProcess()) {
51 // If we have a process type then we were not launched by the system.
52 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessType))
56 if (!base::PathService::Get(base::FILE_EXE, &path))
59 // Check if our executable name matches the helper app for notifications.
60 std::string helper_name = path.BaseName().value();
61 return base::EndsWith(helper_name, chrome::kMacHelperSuffixAlerts);