summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-22 23:37:12 +0000
committerviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-22 23:37:12 +0000
commit12dc3d42817c9ad8e72256c6abca7212da490a9a (patch)
tree2e904fe99aa1a90ebae9af382cc7f06dc9e327db /chrome
parent220089c14ea56be509e2d9292076decc497bc71f (diff)
downloadchromium_src-12dc3d42817c9ad8e72256c6abca7212da490a9a.zip
chromium_src-12dc3d42817c9ad8e72256c6abca7212da490a9a.tar.gz
chromium_src-12dc3d42817c9ad8e72256c6abca7212da490a9a.tar.bz2
Mac: record location of Chromium.app (or Google Chrome.app) bundle.
This will be needed by the app mode loader. BUG=13148 TEST=Run Chromium; do (from command line): "defaults read org.chromium.Chromium LastRunAppBundlePath" -- should get path to Chromium.app; move Chromium.app to another location and run it again; do "defaults ..." again -- should get path to Chromium.app at new location. Review URL: http://codereview.chromium.org/651061 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39665 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/app_controller_mac.mm38
-rw-r--r--chrome/chrome_common.gypi2
-rw-r--r--chrome/common/app_mode_constants_mac.h25
-rw-r--r--chrome/common/app_mode_constants_mac.mm17
4 files changed, 82 insertions, 0 deletions
diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm
index 75dc5cb..4f8e85a 100644
--- a/chrome/browser/app_controller_mac.mm
+++ b/chrome/browser/app_controller_mac.mm
@@ -17,6 +17,7 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_shutdown.h"
#include "chrome/browser/browser_window.h"
+#include "chrome/browser/chrome_thread.h"
#import "chrome/browser/cocoa/about_window_controller.h"
#import "chrome/browser/cocoa/bookmark_manager_controller.h"
#import "chrome/browser/cocoa/bookmark_menu_bridge.h"
@@ -42,6 +43,8 @@
#include "chrome/browser/sync/sync_ui_util.h"
#include "chrome/browser/sync/sync_ui_util_mac.h"
#include "chrome/browser/tab_contents/tab_contents.h"
+#include "chrome/common/app_mode_constants_mac.h"
+#include "chrome/common/chrome_paths_internal.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/pref_names.h"
@@ -100,6 +103,37 @@ Browser* ActivateOrCreateBrowser(Profile* profile) {
return CreateBrowser(profile);
}
+// This task synchronizes preferences (under "org.chromium.Chromium" or
+// "com.google.Chrome"), in particular, writes them out to disk.
+class PrefsSyncTask : public Task {
+ public:
+ PrefsSyncTask() {}
+ virtual ~PrefsSyncTask() {}
+ virtual void Run() {
+ if (!CFPreferencesAppSynchronize(app_mode::kAppPrefsID))
+ LOG(WARNING) << "Error recording application bundle path.";
+ }
+};
+
+// Record the location of the application bundle (containing the main framework)
+// from which Chromium was loaded. This is used by app mode shims to find
+// Chromium.
+void RecordLastRunAppBundlePath() {
+ // Going up three levels from |chrome::GetVersionedDirectory()| gives the
+ // real, user-visible app bundle directory. (The alternatives give either the
+ // framework's path or the initial app's path, which may be an app mode shim
+ // or a unit test.)
+ FilePath appBundlePath =
+ chrome::GetVersionedDirectory().DirName().DirName().DirName();
+ CFPreferencesSetAppValue(app_mode::kLastRunAppBundlePathPrefsKey,
+ base::SysUTF8ToCFStringRef(appBundlePath.value()),
+ app_mode::kAppPrefsID);
+
+ // Sync after a delay avoid I/O contention on startup; 1500 ms is plenty.
+ ChromeThread::PostDelayedTask(ChromeThread::FILE, FROM_HERE,
+ new PrefsSyncTask(), 1500);
+}
+
} // anonymous namespace
@interface AppController(Private)
@@ -385,6 +419,10 @@ Browser* ActivateOrCreateBrowser(Profile* profile) {
if (helpMenu_ && [NSApp respondsToSelector:@selector(setHelpMenu:)])
[NSApp setHelpMenu:helpMenu_];
+ // Record the path to the (browser) app bundle; this is used by the app mode
+ // shim.
+ RecordLastRunAppBundlePath();
+
startupComplete_ = YES;
// TODO(viettrungluu): This is very temporary, since this should be done "in"
diff --git a/chrome/chrome_common.gypi b/chrome/chrome_common.gypi
index 26dc2a2..199cac5 100644
--- a/chrome/chrome_common.gypi
+++ b/chrome/chrome_common.gypi
@@ -25,6 +25,8 @@
# Test files are not included.
'common/accessibility_events.h',
'common/accessibility_events.cc',
+ 'common/app_mode_constants_mac.h',
+ 'common/app_mode_constants_mac.mm',
'common/bindings_policy.h',
'common/child_process.cc',
'common/child_process.h',
diff --git a/chrome/common/app_mode_constants_mac.h b/chrome/common/app_mode_constants_mac.h
new file mode 100644
index 0000000..cd7f39f
--- /dev/null
+++ b/chrome/common/app_mode_constants_mac.h
@@ -0,0 +1,25 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_COMMON_APP_MODE_CONSTANTS_MAC_H_
+#define CHROME_COMMON_APP_MODE_CONSTANTS_MAC_H_
+
+#include <CoreFoundation/CoreFoundation.h>
+
+// This file contains constants which must be known both by the browser
+// application and by the app mode loader (a.k.a. shim).
+
+namespace app_mode {
+
+// The ID under which app mode preferences will be recorded
+// ("org.chromium.Chromium" or "com.google.Chrome").
+extern const CFStringRef kAppPrefsID;
+
+// The key under which to record the path to the (user-visible) application
+// bundle; this key is recorded under the ID given by |kAppPrefsID|.
+extern const CFStringRef kLastRunAppBundlePathPrefsKey;
+
+} // namespace app_mode
+
+#endif // CHROME_COMMON_APP_MODE_CONSTANTS_MAC_H_
diff --git a/chrome/common/app_mode_constants_mac.mm b/chrome/common/app_mode_constants_mac.mm
new file mode 100644
index 0000000..2be2ead
--- /dev/null
+++ b/chrome/common/app_mode_constants_mac.mm
@@ -0,0 +1,17 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/common/app_mode_constants_mac.h"
+
+namespace app_mode {
+
+#if defined(GOOGLE_CHROME_BUILD)
+extern const CFStringRef kAppPrefsID = CFSTR("com.google.Chrome");
+#else
+extern const CFStringRef kAppPrefsID = CFSTR("org.chromium.Chromium");
+#endif
+
+const CFStringRef kLastRunAppBundlePathPrefsKey = CFSTR("LastRunAppBundlePath");
+
+} // namespace app_mode