summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/first_run.cc98
-rw-r--r--chrome/browser/first_run.h35
-rw-r--r--chrome/browser/views/first_run_view_base.cc14
3 files changed, 102 insertions, 45 deletions
diff --git a/chrome/browser/first_run.cc b/chrome/browser/first_run.cc
index ad3376c..51cc1f8 100644
--- a/chrome/browser/first_run.cc
+++ b/chrome/browser/first_run.cc
@@ -45,6 +45,15 @@ const wchar_t kChromeBackupExe[] = L"old_chrome.exe";
// values in the user profile at first run.
const wchar_t kDefaultMasterPrefs[] = L"master_preferences";
+// Boolean pref that triggers skipping the first run dialogs.
+const wchar_t kDistroSkipFirstRunPref[] = L"distribution.skip_first_run_ui";
+// Boolean pref that triggers silent import of the default search engine.
+const wchar_t kDistroImportSearchPref[] = L"distribution.import_search_engine";
+// Boolean pref that triggers silent import of the browse history.
+const wchar_t kDistroImportHistoryPref[] = L"distribution.import_history";
+// Boolean pref that triggers loading the welcome page.
+const wchar_t kDistroShowWelcomePage[] = L"distribution.show_welcome_page";
+
// Gives the full path to the sentinel file. The file might not exist.
bool GetFirstRunSentinelFilePath(std::wstring* path) {
std::wstring first_run_sentinel;
@@ -82,6 +91,24 @@ std::wstring GetDefaultPrefFilePath(bool create_profile_dir,
return ProfileManager::GetDefaultProfilePath(default_pref_dir);
}
+DictionaryValue* ReadJSONPrefs(const std::string& data) {
+ JSONStringValueSerializer json(data);
+ Value* root;
+ if (!json.Deserialize(&root))
+ return NULL;
+ if (!root->IsType(Value::TYPE_DICTIONARY)) {
+ delete root;
+ return NULL;
+ }
+ return static_cast<DictionaryValue*>(root);
+}
+
+bool GetBooleanPref(const DictionaryValue* prefs, const std::wstring& name) {
+ bool value = false;
+ prefs->GetBoolean(name, &value);
+ return value;
+}
+
} // namespace
bool FirstRun::IsChromeFirstRun() {
@@ -132,18 +159,6 @@ bool FirstRun::CreateSentinel() {
return true;
}
-DictionaryValue* ReadJSONPrefs(const std::wstring& file) {
- JSONFileValueSerializer json(file);
- Value* root;
- if (!json.Deserialize(&root))
- return NULL;
- if (!root->IsType(Value::TYPE_DICTIONARY)) {
- delete root;
- return NULL;
- }
- return static_cast<DictionaryValue*>(root);
-}
-
FirstRun::MasterPrefResult FirstRun::ProcessMasterPreferences(
const std::wstring& user_data_dir,
const std::wstring& master_prefs_path) {
@@ -160,30 +175,46 @@ FirstRun::MasterPrefResult FirstRun::ProcessMasterPreferences(
master_prefs = master_prefs_path;
}
+ std::string json_data;
+ if (!file_util::ReadFileToString(master_prefs, &json_data))
+ return MASTER_PROFILE_NOT_FOUND;
+
+ LOG(INFO) << "master profile found";
+
std::wstring user_prefs = GetDefaultPrefFilePath(true, user_data_dir);
if (user_prefs.empty())
return MASTER_PROFILE_ERROR;
- scoped_ptr<DictionaryValue> json_root(ReadJSONPrefs(master_prefs));
+ scoped_ptr<DictionaryValue> json_root(ReadJSONPrefs(json_data));
if (!json_root.get())
return MASTER_PROFILE_ERROR;
-
- bool skip_first_run_ui = false;
- json_root->GetBoolean(L"skip_first_run_ui", &skip_first_run_ui);
-
+
// 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;
- if (!skip_first_run_ui)
+ if (!GetBooleanPref(json_root.get(), kDistroSkipFirstRunPref))
return MASTER_PROFILE_DO_FIRST_RUN_UI;
- // Automatically import search provider. This launches the importer
- // process and blocks until done or until it fails. The second parameter
- // in zero means to use the default browser.
- FirstRun::ImportSettings(NULL, 0, SEARCH_ENGINES, NULL);
+ FirstRun::SetShowFirstRunBubblePref();
+ if (GetBooleanPref(json_root.get(), kDistroShowWelcomePage))
+ FirstRun::SetShowWelcomePagePref();
+
+ int import_items = 0;
+ if (GetBooleanPref(json_root.get(), kDistroImportSearchPref))
+ import_items += SEARCH_ENGINES;
+ if (GetBooleanPref(json_root.get(), kDistroImportHistoryPref))
+ import_items += HISTORY;
+
+ if (import_items) {
+ // There is something to import from the default browser. This launches
+ // the importer process and blocks until done or until it fails.
+ if (!FirstRun::ImportSettings(NULL, 0, import_items, NULL)) {
+ LOG(WARNING) << "silent import failed";
+ }
+ }
return MASTER_PROFILE_NO_FIRST_RUN_UI;
}
@@ -441,3 +472,26 @@ int FirstRun::ImportNow(Profile* profile, const CommandLine& cmdline) {
return observer.import_result();
}
+bool FirstRun::SetShowFirstRunBubblePref() {
+ PrefService* local_state = g_browser_process->local_state();
+ if (!local_state)
+ return false;
+ if (!local_state->IsPrefRegistered(prefs::kShouldShowFirstRunBubble)) {
+ local_state->RegisterBooleanPref(prefs::kShouldShowFirstRunBubble, false);
+ local_state->SetBoolean(prefs::kShouldShowFirstRunBubble, true);
+ }
+ return true;
+}
+
+bool FirstRun::SetShowWelcomePagePref() {
+ PrefService* local_state = g_browser_process->local_state();
+ if (!local_state)
+ return false;
+ if (!local_state->IsPrefRegistered(prefs::kShouldShowWelcomePage)) {
+ local_state->RegisterBooleanPref(prefs::kShouldShowWelcomePage, false);
+ local_state->SetBoolean(prefs::kShouldShowWelcomePage, true);
+ }
+ return true;
+}
+
+
diff --git a/chrome/browser/first_run.h b/chrome/browser/first_run.h
index 81f576a..85bac8d 100644
--- a/chrome/browser/first_run.h
+++ b/chrome/browser/first_run.h
@@ -61,37 +61,50 @@ class FirstRun {
// 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
+ // This function destroys any existing prefs file and it is meant to be
+ // invoked only on first run.
//
// A prototypical 'master_preferences' file looks like this:
//
// {
+ // "distribution": {
+ // "skip_first_run_ui": true,
+ // "show_welcome_page": true,
+ // "import_search_engine": true,
+ // "import_history": false
+ // },
// "browser": {
// "show_home_button": true
// },
// "bookmark_bar": {
// "show_on_all_tabs": true
// },
- // "homepage": "http://slashdot.org",
+ // "homepage": "http://example.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.
+ // A reserved "distribution" entry in the file is used to group related
+ // installation properties. 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.
+ // MASTER_PROFILE_NO_FIRST_RUN_UI : skip first run dialogs.
+ // MASTER_PROFILE_DO_FIRST_RUN_UI : show the first run dialogs.
static MasterPrefResult ProcessMasterPreferences(
const std::wstring& user_data_dir,
const std::wstring& master_prefs_path);
+ // Sets the kShouldShowFirstRunBubble local state pref so that the browser
+ // shows the bubble once the main message loop gets going. Returns false if
+ // the pref could not be set.
+ static bool SetShowFirstRunBubblePref();
+
+ // Sets the kShouldShowWelcomePage local state pref so that the browser
+ // loads the welcome tab once the message loop gets going. Returns false
+ // if the pref could not be set.
+ static bool SetShowWelcomePagePref();
+
private:
// This class is for scoping purposes.
DISALLOW_COPY_AND_ASSIGN(FirstRun);
diff --git a/chrome/browser/views/first_run_view_base.cc b/chrome/browser/views/first_run_view_base.cc
index 1fa049b..4875580 100644
--- a/chrome/browser/views/first_run_view_base.cc
+++ b/chrome/browser/views/first_run_view_base.cc
@@ -45,18 +45,8 @@ FirstRunViewBase::FirstRunViewBase(Profile* profile)
}
FirstRunViewBase::~FirstRunViewBase() {
- // Register and set the "show first run information bubble" state so that the
- // browser can read it later.
- PrefService* local_state = g_browser_process->local_state();
- if (!local_state->IsPrefRegistered(prefs::kShouldShowFirstRunBubble)) {
- local_state->RegisterBooleanPref(prefs::kShouldShowFirstRunBubble, false);
- local_state->SetBoolean(prefs::kShouldShowFirstRunBubble, true);
- }
-
- if (!local_state->IsPrefRegistered(prefs::kShouldShowWelcomePage)) {
- local_state->RegisterBooleanPref(prefs::kShouldShowWelcomePage, false);
- local_state->SetBoolean(prefs::kShouldShowWelcomePage, true);
- }
+ FirstRun::SetShowFirstRunBubblePref();
+ FirstRun::SetShowWelcomePagePref();
}
void FirstRunViewBase::SetupControls() {