summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorcpu@google.com <cpu@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-17 18:05:54 +0000
committercpu@google.com <cpu@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-17 18:05:54 +0000
commit09da32d543461c90fcf3490966e0c4a670b9a2a8 (patch)
tree9503fe2d5a63b14bab3b5f00d6119770ec2a99d8 /chrome
parent937bcde53a86ea06ac8379e882de339ed95e3897 (diff)
downloadchromium_src-09da32d543461c90fcf3490966e0c4a670b9a2a8.zip
chromium_src-09da32d543461c90fcf3490966e0c4a670b9a2a8.tar.gz
chromium_src-09da32d543461c90fcf3490966e0c4a670b9a2a8.tar.bz2
Add processing for a master profile json file on first run. Allows:
- set home page / show home button - show bookmarks bar Review URL: http://codereview.chromium.org/7369 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3542 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/browser_main.cc13
-rw-r--r--chrome/browser/first_run.cc51
-rw-r--r--chrome/browser/first_run.h55
-rw-r--r--chrome/browser/profile_manager.cc30
-rw-r--r--chrome/browser/profile_manager.h6
5 files changed, 137 insertions, 18 deletions
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc
index 6e819b2..5171c43 100644
--- a/chrome/browser/browser_main.cc
+++ b/chrome/browser/browser_main.cc
@@ -320,6 +320,7 @@ int BrowserMain(CommandLine &parsed_command_line, int show_command,
bool is_first_run = FirstRun::IsChromeFirstRun() ||
parsed_command_line.HasSwitch(switches::kFirstRun);
+ bool first_run_ui_bypass = false;
// Initialize ResourceBundle which handles files loaded from external
// sources. This has to be done before uninstall code path and before prefs
@@ -327,7 +328,7 @@ int BrowserMain(CommandLine &parsed_command_line, int show_command,
local_state->RegisterStringPref(prefs::kApplicationLocale, L"");
local_state->RegisterBooleanPref(prefs::kMetricsReportingEnabled, false);
- // During first run we read the google update registry key to find what
+ // During first run we read the google_update registry key to find what
// language the user selected when downloading the installer. This
// becomes our default language in the prefs.
if (is_first_run) {
@@ -336,6 +337,12 @@ int BrowserMain(CommandLine &parsed_command_line, int show_command,
local_state->SetString(prefs::kApplicationLocale, install_lang);
if (GoogleUpdateSettings::GetCollectStatsConsent())
local_state->SetBoolean(prefs::kMetricsReportingEnabled, true);
+ // On first run, we need to process the master preferences before the
+ // browser's profile_manager object is created.
+ FirstRun::MasterPrefResult master_pref_res =
+ FirstRun::ProcessMasterPreferences(user_data_dir, std::wstring());
+ first_run_ui_bypass =
+ (master_pref_res == FirstRun::MASTER_PROFILE_NO_FIRST_RUN_UI);
}
ResourceBundle::InitSharedInstance(
@@ -351,7 +358,7 @@ int BrowserMain(CommandLine &parsed_command_line, int show_command,
// Initialize histogram statistics gathering system.
StatisticsRecorder statistics;
- // Strart tracking the creation and deletion of Task instances
+ // Start tracking the creation and deletion of Task instances
bool tracking_objects = false;
#ifdef TRACK_ALL_TASK_OBJECTS
tracking_objects = tracked_objects::ThreadData::StartTracking(true);
@@ -453,7 +460,7 @@ int BrowserMain(CommandLine &parsed_command_line, int show_command,
// Note that this be done _after_ the PrefService is initialized and all
// preferences are registered, since some of the code that the importer
// touches reads preferences.
- if (is_first_run) {
+ if (is_first_run && !first_run_ui_bypass) {
// We need to avoid dispatching new tabs when we are doing the import
// because that will lead to data corruption or a crash. Lock() does that.
message_window.Lock();
diff --git a/chrome/browser/first_run.cc b/chrome/browser/first_run.cc
index 96ca07d..f0e7dd2 100644
--- a/chrome/browser/first_run.cc
+++ b/chrome/browser/first_run.cc
@@ -16,11 +16,13 @@
#include "base/process_util.h"
#include "base/string_util.h"
#include "chrome/app/result_codes.h"
+#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/hang_monitor/hung_window_detector.h"
#include "chrome/browser/importer/importer.h"
#include "chrome/browser/profile.h"
+#include "chrome/browser/profile_manager.h"
#include "chrome/browser/views/first_run_view.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths.h"
@@ -38,6 +40,10 @@ const wchar_t kSentinelFile[] = L"First Run";
const wchar_t kChromeUpgradeExe[] = L"new_chrome.exe";
const wchar_t kChromeBackupExe[] = L"old_chrome.exe";
+// This is the default name for the master preferences file used to pre-set
+// values in the user profile at first run.
+const wchar_t kDefaultMasterPrefs[] = L"master_preferences";
+
// Gives the full path to the sentinel file. The file might not exist.
bool GetFirstRunSentinelFilePath(std::wstring* path) {
std::wstring first_run_sentinel;
@@ -62,6 +68,19 @@ bool GetBackupChromeFile(std::wstring* path) {
return true;
}
+std::wstring GetDefaultPrefFilePath(bool create_profile_dir,
+ const std::wstring& user_data_dir) {
+ std::wstring default_pref_dir =
+ ProfileManager::GetDefaultProfileDir(user_data_dir);
+ if (create_profile_dir) {
+ if (!file_util::PathExists(default_pref_dir)) {
+ if (!file_util::CreateDirectory(default_pref_dir))
+ return std::wstring();
+ }
+ }
+ return ProfileManager::GetDefaultProfilePath(default_pref_dir);
+}
+
} // namespace
bool FirstRun::IsChromeFirstRun() {
@@ -132,6 +151,38 @@ bool FirstRun::CreateSentinel() {
return true;
}
+FirstRun::MasterPrefResult FirstRun::ProcessMasterPreferences(
+ const std::wstring& user_data_dir,
+ const std::wstring& master_prefs_path) {
+ DCHECK(!user_data_dir.empty());
+ std::wstring master_prefs;
+ if (master_prefs_path.empty()) {
+ // The default location of the master prefs is next to the chrome exe.
+ std::wstring master_path;
+ if (!PathService::Get(base::DIR_EXE, &master_path))
+ return MASTER_PROFILE_ERROR;
+ file_util::AppendToPath(&master_path, kDefaultMasterPrefs);
+ if (!file_util::PathExists(master_path))
+ return MASTER_PROFILE_NOT_FOUND;
+ master_prefs = master_path;
+ } else {
+ master_prefs = master_prefs_path;
+ }
+
+ std::wstring user_prefs = GetDefaultPrefFilePath(true, user_data_dir);
+ if (user_prefs.empty())
+ return MASTER_PROFILE_ERROR;
+
+ // The master prefs are regular prefs so we can just copy the file
+ // to the default place and they just work.
+ if (!file_util::CopyFile(master_prefs, user_prefs))
+ return MASTER_PROFILE_ERROR;
+
+ // TODO (cpu): Process the 'distribution' dictionary and return the
+ // appropriate values.
+ return MASTER_PROFILE_NO_FIRST_RUN_UI;
+}
+
bool Upgrade::SwapNewChromeExeIfPresent() {
std::wstring new_chrome_exe;
if (!GetNewerChromeFile(&new_chrome_exe))
diff --git a/chrome/browser/first_run.h b/chrome/browser/first_run.h
index 7d98580..c9e439c 100644
--- a/chrome/browser/first_run.h
+++ b/chrome/browser/first_run.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_BROWSER_FIRST_RUN_H__
-#define CHROME_BROWSER_FIRST_RUN_H__
+#ifndef CHROME_BROWSER_FIRST_RUN_H_
+#define CHROME_BROWSER_FIRST_RUN_H_
#include "base/basictypes.h"
#include "base/command_line.h"
@@ -50,9 +50,54 @@ class FirstRun {
// FirstRun::ImportSettings().
static int ImportWithUI(Profile* profile, const CommandLine& cmdline);
+ // These are the possible results of calling ProcessMasterPreferences.
+ enum MasterPrefResult {
+ MASTER_PROFILE_NOT_FOUND = 0,
+ MASTER_PROFILE_ERROR = 1,
+ MASTER_PROFILE_SHOW_EULA = 2,
+ MASTER_PROFILE_NO_FIRST_RUN_UI = 4
+ };
+
+ // The master preferences is a JSON file with the same entries as the
+ // 'Default\Preferences' file. This function locates this file from
+ // master_pref_path or if that path is empty from the default location
+ // which is '<path to chrome.exe>\master_preferences', and process it
+ // so it becomes the default preferences in profile pointed by user_data_dir.
+ //
+ // Since this function destroys any existing prefs file, it is meant to be
+ // invoked only on first run. The current use of this function is to set the
+ // following 3 properties:
+ // - default home page
+ // - show bookmark bar
+ // - show home page button
+ //
+ // A prototypical 'master_preferences' file looks like this:
+ //
+ // {
+ // "browser": {
+ // "show_home_button": true
+ // },
+ // "bookmark_bar": {
+ // "show_on_all_tabs": true
+ // },
+ // "homepage": "http://slashdot.org",
+ // "homepage_is_newtabpage": false
+ // }
+ //
+ // A reserved "distribution" entry in the file will be used to group
+ // other installation properties such as the EULA display. This entry will
+ // be ignored at other times.
+ // Currently only the following return values are used:
+ // MASTER_PROFILE_NOT_FOUND : Typical outcome for organic installs.
+ // MASTER_PROFILE_ERROR : A critical error processing the master profile.
+ // MASTER_PROFILE_SHOW_FIRST_RUN_UI : master profile processed ok.
+ static MasterPrefResult ProcessMasterPreferences(
+ const std::wstring& user_data_dir,
+ const std::wstring& master_prefs_path);
+
private:
// This class is for scoping purposes.
- DISALLOW_EVIL_CONSTRUCTORS(FirstRun);
+ DISALLOW_COPY_AND_ASSIGN(FirstRun);
};
// This class contains the actions that need to be performed when an upgrade
@@ -81,7 +126,7 @@ class FirstRunBrowserProcess : public BrowserProcessImpl {
virtual GoogleURLTracker* google_url_tracker() { return NULL; }
private:
- DISALLOW_EVIL_CONSTRUCTORS(FirstRunBrowserProcess);
+ DISALLOW_COPY_AND_ASSIGN(FirstRunBrowserProcess);
};
// Show the First Run UI to the user, allowing them to create shortcuts for
@@ -89,5 +134,5 @@ class FirstRunBrowserProcess : public BrowserProcessImpl {
// |profile| and perhaps some other tasks.
void OpenFirstRunDialog(Profile* profile);
-#endif // CHROME_BROWSER_FIRST_RUN_H__
+#endif // CHROME_BROWSER_FIRST_RUN_H_
diff --git a/chrome/browser/profile_manager.cc b/chrome/browser/profile_manager.cc
index c4dae3b..34ac0a6 100644
--- a/chrome/browser/profile_manager.cc
+++ b/chrome/browser/profile_manager.cc
@@ -58,21 +58,32 @@ ProfileManager::~ProfileManager() {
available_profiles_.clear();
}
+std::wstring ProfileManager::GetDefaultProfileDir(
+ const std::wstring& user_data_dir) {
+ std::wstring default_profile_dir(user_data_dir);
+ file_util::AppendToPath(&default_profile_dir, chrome::kNotSignedInProfile);
+ return default_profile_dir;
+}
+
+std::wstring ProfileManager::GetDefaultProfilePath(
+ const std::wstring &profile_dir) {
+ std::wstring default_prefs_path(profile_dir);
+ file_util::AppendToPath(&default_prefs_path, chrome::kPreferencesFilename);
+ return default_prefs_path;
+}
+
Profile* ProfileManager::GetDefaultProfile(const std::wstring& user_data_dir) {
// Initialize profile, creating default if necessary
- std::wstring default_profile_path = user_data_dir;
- file_util::AppendToPath(&default_profile_path,
- chrome::kNotSignedInProfile);
-
+ std::wstring default_profile_dir = GetDefaultProfileDir(user_data_dir);
// If the profile is already loaded (e.g., chrome.exe launched twice), just
// return it.
- Profile* profile = GetProfileByPath(default_profile_path);
+ Profile* profile = GetProfileByPath(default_profile_dir);
if (NULL != profile)
return profile;
- if (!ProfileManager::IsProfile(default_profile_path)) {
+ if (!ProfileManager::IsProfile(default_profile_dir)) {
// If the profile directory doesn't exist, create it.
- profile = ProfileManager::CreateProfile(default_profile_path,
+ profile = ProfileManager::CreateProfile(default_profile_dir,
L"", // No name.
L"", // No nickname.
chrome::kNotSignedInID);
@@ -82,7 +93,7 @@ Profile* ProfileManager::GetDefaultProfile(const std::wstring& user_data_dir) {
DCHECK(result);
} else {
// The profile already exists on disk, just load it.
- profile = AddProfileByPath(default_profile_path);
+ profile = AddProfileByPath(default_profile_dir);
if (!profile)
return NULL;
@@ -209,8 +220,7 @@ Profile* ProfileManager::GetProfileByID(const std::wstring& id) const {
// static
bool ProfileManager::IsProfile(const std::wstring& path) {
- std::wstring prefs_path = path;
- file_util::AppendToPath(&prefs_path, chrome::kPreferencesFilename);
+ std::wstring prefs_path = GetDefaultProfilePath(path);
std::wstring history_path = path;
file_util::AppendToPath(&history_path, chrome::kHistoryFilename);
diff --git a/chrome/browser/profile_manager.h b/chrome/browser/profile_manager.h
index 92ee707..5c3ad89 100644
--- a/chrome/browser/profile_manager.h
+++ b/chrome/browser/profile_manager.h
@@ -124,6 +124,12 @@ class ProfileManager {
// ------------------ static utility functions -------------------
+ // Returns the path to the profile directory based on the user data directory.
+ static std::wstring GetDefaultProfileDir(const std::wstring& user_data_dir);
+
+ // Returns the path to the profile given the user profile directory.
+ static std::wstring GetDefaultProfilePath(const std::wstring& profile_dir);
+
// Tries to determine whether the given path represents a profile
// directory, and returns true if it thinks it does.
static bool IsProfile(const std::wstring& path);