diff options
author | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-30 14:24:01 +0000 |
---|---|---|
committer | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-30 14:24:01 +0000 |
commit | c9c1512e70096a0ce81ac7ebbbcafa2ce8e07205 (patch) | |
tree | 4d22f86a5ca128f27a1b856eb1f9e56775517c05 | |
parent | ef7aab90b0ac2ed31fab60c4a280355682015869 (diff) | |
download | chromium_src-c9c1512e70096a0ce81ac7ebbbcafa2ce8e07205.zip chromium_src-c9c1512e70096a0ce81ac7ebbbcafa2ce8e07205.tar.gz chromium_src-c9c1512e70096a0ce81ac7ebbbcafa2ce8e07205.tar.bz2 |
Enable brand codes and master preferences on the Mac.
BUG=93421
TEST=alter brand codes and master prefs files; should be read
Review URL: http://codereview.chromium.org/7655056
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@98811 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/first_run/first_run.cc | 6 | ||||
-rw-r--r-- | chrome/browser/first_run/first_run.h | 51 | ||||
-rw-r--r-- | chrome/browser/first_run/first_run_gtk.cc | 10 | ||||
-rw-r--r-- | chrome/browser/first_run/first_run_mac.mm | 14 | ||||
-rw-r--r-- | chrome/browser/first_run/first_run_win.cc | 10 | ||||
-rw-r--r-- | chrome/browser/mac/keystone_glue.h | 5 | ||||
-rw-r--r-- | chrome/browser/mac/keystone_glue.mm | 15 | ||||
-rw-r--r-- | chrome/browser/mac/master_prefs.h | 20 | ||||
-rw-r--r-- | chrome/browser/mac/master_prefs.mm | 43 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 2 | ||||
-rw-r--r-- | chrome/installer/util/master_preferences.h | 2 |
11 files changed, 150 insertions, 28 deletions
diff --git a/chrome/browser/first_run/first_run.cc b/chrome/browser/first_run/first_run.cc index 42388fc..205f12a 100644 --- a/chrome/browser/first_run/first_run.cc +++ b/chrome/browser/first_run/first_run.cc @@ -150,11 +150,9 @@ bool FirstRun::ProcessMasterPreferences(const FilePath& user_data_dir, MasterPrefs* out_prefs) { DCHECK(!user_data_dir.empty()); - // The standard location of the master prefs is next to the chrome binary. - FilePath master_prefs; - if (!PathService::Get(base::DIR_EXE, &master_prefs)) + FilePath master_prefs = MasterPrefsPath(); + if (master_prefs.empty()) return true; - master_prefs = master_prefs.AppendASCII(installer::kDefaultMasterPrefs); installer::MasterPreferences prefs(master_prefs); if (!prefs.read_from_file()) return true; diff --git a/chrome/browser/first_run/first_run.h b/chrome/browser/first_run/first_run.h index 1bdf1cd..35c82ac0 100644 --- a/chrome/browser/first_run/first_run.h +++ b/chrome/browser/first_run/first_run.h @@ -74,12 +74,6 @@ class FirstRun { bool make_chrome_default, ProcessSingleton* process_singleton); - // Does platform specific setup. Called at the start of AutoImport. - static void PlatformSetup(); - - // Returns whether the first run should be "organic". - static bool IsOrganicFirstRun(); - // The master preferences is a JSON file with the same entries as the // 'Default\Preferences' file. This function locates this file from a standard // location and processes it so it becomes the default preferences in the @@ -106,14 +100,6 @@ class FirstRun { // sentinel file could not be removed. static bool RemoveSentinel(); - // Imports settings. This may be done in a separate process depending on the - // platform, but it will always block until done. The return value indicates - // success. - static bool ImportSettings(Profile* profile, - scoped_refptr<ImporterHost> importer_host, - scoped_refptr<ImporterList> importer_list, - int items_to_import); - // Sets the kShouldShowFirstRunBubble local state pref so that the browser // shows the bubble once the main message loop gets going (or refrains from // showing the bubble, if |show_bubble| is false). Returns false if the pref @@ -145,10 +131,38 @@ class FirstRun { // being shown. static bool SearchEngineSelectorDisallowed(); + // -- Platform-specific functions -- + + // Imports settings. This may be done in a separate process depending on the + // platform, but it will always block until done. The return value indicates + // success. + static bool ImportSettings(Profile* profile, + scoped_refptr<ImporterHost> importer_host, + scoped_refptr<ImporterList> importer_list, + int items_to_import); + + // Does platform specific setup. Called at the start of AutoImport. + static void PlatformSetup(); + + // Returns whether the first run should be "organic". + static bool IsOrganicFirstRun(); + + // Returns the path for the master preferences file. + static FilePath MasterPrefsPath(); + private: friend class FirstRunTest; FRIEND_TEST_ALL_PREFIXES(Toolbar5ImporterTest, BookmarkParse); + // Import bookmarks from an html file. The path to the file is provided in + // the command line. + static int ImportFromFile(Profile* profile, const CommandLine& cmdline); + + // Gives the full path to the sentinel file. The file might not exist. + static bool GetFirstRunSentinelFilePath(FilePath* path); + + // -- Platform-specific functions -- + #if defined(OS_WIN) // Writes the EULA to a temporary file, returned in |*eula_path|, and returns // true if successful. @@ -176,20 +190,13 @@ class FirstRun { gfx::NativeView parent_window); // Import browser items in this process. The browser and the items to - // import are encoded int the command line. + // import are encoded in the command line. static int ImportFromBrowser(Profile* profile, const CommandLine& cmdline); #else static bool ImportBookmarks(const FilePath& import_bookmarks_path); #endif - // Import bookmarks from an html file. The path to the file is provided in - // the command line. - static int ImportFromFile(Profile* profile, const CommandLine& cmdline); - - // Gives the full path to the sentinel file. The file might not exist. - static bool GetFirstRunSentinelFilePath(FilePath* path); - enum FirstRunState { FIRST_RUN_UNKNOWN, // The state is not tested or set yet. FIRST_RUN_TRUE, diff --git a/chrome/browser/first_run/first_run_gtk.cc b/chrome/browser/first_run/first_run_gtk.cc index bb79830..d970d21 100644 --- a/chrome/browser/first_run/first_run_gtk.cc +++ b/chrome/browser/first_run/first_run_gtk.cc @@ -16,6 +16,7 @@ #include "chrome/browser/shell_integration.h" #include "chrome/common/chrome_switches.h" #include "chrome/installer/util/google_update_settings.h" +#include "chrome/installer/util/master_preferences.h" #include "content/common/result_codes.h" #include "googleurl/src/gurl.h" #include "ui/base/ui_base_switches.h" @@ -57,3 +58,12 @@ void FirstRun::PlatformSetup() { // Things that Windows does here (creating a desktop icon, for example) are // handled at install time on Linux. } + +// static +FilePath FirstRun::MasterPrefsPath() { + // The standard location of the master prefs is next to the chrome binary. + FilePath master_prefs; + if (!PathService::Get(base::DIR_EXE, &master_prefs)) + return FilePath(); + return master_prefs.AppendASCII(installer::kDefaultMasterPrefs); +} diff --git a/chrome/browser/first_run/first_run_mac.mm b/chrome/browser/first_run/first_run_mac.mm index c866583..7ddea47 100644 --- a/chrome/browser/first_run/first_run_mac.mm +++ b/chrome/browser/first_run/first_run_mac.mm @@ -5,6 +5,9 @@ #include "chrome/browser/first_run/first_run.h" #include "base/file_path.h" +#include "base/string_util.h" +#include "chrome/browser/mac/keystone_glue.h" +#include "chrome/browser/mac/master_prefs.h" bool FirstRun::ImportBookmarks(const FilePath& import_bookmarks_path) { // http://crbug.com/48880 @@ -13,8 +16,10 @@ bool FirstRun::ImportBookmarks(const FilePath& import_bookmarks_path) { // static bool FirstRun::IsOrganicFirstRun() { - // We treat all installs as organic. - return true; + std::string brand = keystone_glue::BrandCode(); + return brand.empty() || + StartsWithASCII(brand, "GG", true) || + StartsWithASCII(brand, "EU", true); } // static @@ -22,3 +27,8 @@ void FirstRun::PlatformSetup() { // Things that Windows does here (creating a desktop icon, for example) are // not needed. } + +// static +FilePath FirstRun::MasterPrefsPath() { + return master_prefs::MasterPrefsPath(); +} diff --git a/chrome/browser/first_run/first_run_win.cc b/chrome/browser/first_run/first_run_win.cc index d4c91ceb..867d02c 100644 --- a/chrome/browser/first_run/first_run_win.cc +++ b/chrome/browser/first_run/first_run_win.cc @@ -35,6 +35,7 @@ #include "chrome/installer/util/google_update_constants.h" #include "chrome/installer/util/google_update_settings.h" #include "chrome/installer/util/install_util.h" +#include "chrome/installer/util/master_preferences.h" #include "chrome/installer/util/shell_util.h" #include "chrome/installer/util/util_constants.h" #include "content/browser/user_metrics.h" @@ -308,6 +309,15 @@ bool FirstRun::IsOrganicFirstRun() { } // static +FilePath FirstRun::MasterPrefsPath() { + // The standard location of the master prefs is next to the chrome binary. + FilePath master_prefs; + if (!PathService::Get(base::DIR_EXE, &master_prefs)) + return FilePath(); + return master_prefs.AppendASCII(installer::kDefaultMasterPrefs); +} + +// static bool FirstRun::ImportSettings(Profile* profile, int importer_type, int items_to_import, diff --git a/chrome/browser/mac/keystone_glue.h b/chrome/browser/mac/keystone_glue.h index 615b5e9..65bdc70 100644 --- a/chrome/browser/mac/keystone_glue.h +++ b/chrome/browser/mac/keystone_glue.h @@ -198,6 +198,11 @@ enum BrandFileType { // Functions that may be accessed from non-Objective-C C/C++ code. namespace keystone_glue { +// Returns the brand code of the installation. Note that beta, dev, and canary +// channels, as well as some stable builds, may have an empty string as a brand +// code. +std::string BrandCode(); + // True if Keystone is enabled. bool KeystoneEnabled(); diff --git a/chrome/browser/mac/keystone_glue.mm b/chrome/browser/mac/keystone_glue.mm index 2472312..2b34466 100644 --- a/chrome/browser/mac/keystone_glue.mm +++ b/chrome/browser/mac/keystone_glue.mm @@ -9,6 +9,7 @@ #include <vector> +#include "base/file_util.h" #include "base/logging.h" #include "base/mac/mac_util.h" #include "base/mac/scoped_nsautorelease_pool.h" @@ -917,6 +918,20 @@ NSString* const kVersionKey = @"KSVersion"; namespace keystone_glue { +std::string BrandCode() { + KeystoneGlue* keystoneGlue = [KeystoneGlue defaultKeystoneGlue]; + NSString* brand_path = [keystoneGlue brandFilePath]; + + if (![brand_path length]) + return std::string(); + + std::string brand_code; + file_util::ReadFileToString(FilePath([brand_path fileSystemRepresentation]), + &brand_code); + + return brand_code; +} + bool KeystoneEnabled() { return [KeystoneGlue defaultKeystoneGlue] != nil; } diff --git a/chrome/browser/mac/master_prefs.h b/chrome/browser/mac/master_prefs.h new file mode 100644 index 0000000..ce2e330 --- /dev/null +++ b/chrome/browser/mac/master_prefs.h @@ -0,0 +1,20 @@ +// Copyright (c) 2011 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_BROWSER_MAC_MASTER_PREFS_H_ +#define CHROME_BROWSER_MAC_MASTER_PREFS_H_ +#pragma once + +#include "base/file_path.h" + +namespace master_prefs { + +// Returns the path to the master preferences file. Note that this path may be +// empty (in the case where this type of build cannot have a master preferences +// file) or may not actually exist on the filesystem. +FilePath MasterPrefsPath(); + +} // namespace master_prefs + +#endif // CHROME_BROWSER_MAC_MASTER_PREFS_H_ diff --git a/chrome/browser/mac/master_prefs.mm b/chrome/browser/mac/master_prefs.mm new file mode 100644 index 0000000..dae0f2e --- /dev/null +++ b/chrome/browser/mac/master_prefs.mm @@ -0,0 +1,43 @@ +// Copyright (c) 2011 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/browser/mac/master_prefs.h" + +#include "base/mac/foundation_util.h" +#include "chrome/common/chrome_version_info.h" + +#if defined(GOOGLE_CHROME_BUILD) + +namespace { + +const char kGoogleDirectory[] = "Google"; +const char kMasterPreferencesFileName[] = "Google Chrome Master Preferences"; + +} // namespace + +#endif // GOOGLE_CHROME_BUILD + +namespace master_prefs { + +FilePath MasterPrefsPath() { +#if defined(GOOGLE_CHROME_BUILD) + // There is only a system-level master preferences file, and only for the + // official build, and not for the canary. + chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); + + if (channel == chrome::VersionInfo::CHANNEL_CANARY) + return FilePath(); + + FilePath library_path; + if (!base::mac::GetLocalDirectory(NSLibraryDirectory, &library_path)) + return FilePath(); + + return library_path.Append(kGoogleDirectory) + .Append(kMasterPreferencesFileName); +#else + return FilePath(); +#endif // GOOGLE_CHROME_BUILD +} + +} // namespace master_prefs diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index d9150a1..4dbb767 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1424,6 +1424,8 @@ 'browser/mac/keystone_registration.mm', 'browser/mac/launchd.cc', 'browser/mac/launchd.h', + 'browser/mac/master_prefs.h', + 'browser/mac/master_prefs.mm', 'browser/mac/relauncher.cc', 'browser/mac/relauncher.h', 'browser/mac/scoped_authorizationref.h', diff --git a/chrome/installer/util/master_preferences.h b/chrome/installer/util/master_preferences.h index a05ae92..28175c5 100644 --- a/chrome/installer/util/master_preferences.h +++ b/chrome/installer/util/master_preferences.h @@ -24,9 +24,11 @@ class DictionaryValue; namespace installer { +#if !defined(OS_MACOSX) // This is the default name for the master preferences file used to pre-set // values in the user profile at first run. const char kDefaultMasterPrefs[] = "master_preferences"; +#endif // The master preferences is a JSON file with the same entries as the // 'Default\Preferences' file. This function parses the distribution |