summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorasvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-15 06:36:03 +0000
committerasvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-15 06:36:03 +0000
commita723f0af50bf919cfbcfd7f8f1c05fee1c3f3c67 (patch)
tree362928a12d5cff2235e363a6b4b1cdef2bb1a044
parent900761ca90361bc35094b21185c8936e1f47fe6d (diff)
downloadchromium_src-a723f0af50bf919cfbcfd7f8f1c05fee1c3f3c67.zip
chromium_src-a723f0af50bf919cfbcfd7f8f1c05fee1c3f3c67.tar.gz
chromium_src-a723f0af50bf919cfbcfd7f8f1c05fee1c3f3c67.tar.bz2
Support variations_seed parameter in MasterPrefs.
Also, cleans up SetupMasterPrefsFromInstallPrefs() to be more conformant to the style guide and adds a unit test. BUG=175476 TEST=Test that specifying a custom variations_seed in a master prefs file to the installer (via --installerdata=path), results in that seed being used on first run. Review URL: https://chromiumcodereview.appspot.com/12223062 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@182631 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chrome_browser_main.cc13
-rw-r--r--chrome/browser/first_run/first_run.cc25
-rw-r--r--chrome/browser/first_run/first_run.h1
-rw-r--r--chrome/browser/first_run/first_run_internal.h4
-rw-r--r--chrome/browser/first_run/first_run_unittest.cc27
-rw-r--r--chrome/installer/util/master_preferences.cc7
-rw-r--r--chrome/installer/util/master_preferences.h3
7 files changed, 63 insertions, 17 deletions
diff --git a/chrome/browser/chrome_browser_main.cc b/chrome/browser/chrome_browser_main.cc
index 28337e5..4e02136 100644
--- a/chrome/browser/chrome_browser_main.cc
+++ b/chrome/browser/chrome_browser_main.cc
@@ -948,6 +948,19 @@ int ChromeBrowserMainParts::PreCreateThreadsImpl() {
if (do_first_run_tasks_) {
AddFirstRunNewTabs(browser_creator_.get(), master_prefs_->new_tabs);
+
+ // Store the initial VariationsService seed in local state, if it exists
+ // in master prefs.
+ if (!master_prefs_->variations_seed.empty()) {
+ local_state_->SetString(prefs::kVariationsSeed,
+ master_prefs_->variations_seed);
+ // Set the variation seed date to the current system time. If the user's
+ // clock is incorrect, this may cause some field trial expiry checks to
+ // not do the right thing until the next seed update from the server,
+ // when this value will be updated.
+ local_state_->SetInt64(prefs::kVariationsSeedDate,
+ base::Time::Now().ToInternalValue());
+ }
} else if (parsed_command_line().HasSwitch(switches::kNoFirstRun)) {
// Create the First Run beacon anyways if --no-first-run was passed on the
// command line.
diff --git a/chrome/browser/first_run/first_run.cc b/chrome/browser/first_run/first_run.cc
index c1406c8..253854e 100644
--- a/chrome/browser/first_run/first_run.cc
+++ b/chrome/browser/first_run/first_run.cc
@@ -250,10 +250,10 @@ bool CopyPrefFile(const base::FilePath& user_data_dir,
}
void SetupMasterPrefsFromInstallPrefs(
- MasterPrefs* out_prefs,
- installer::MasterPreferences* install_prefs) {
+ const installer::MasterPreferences& install_prefs,
+ MasterPrefs* out_prefs) {
bool value = false;
- if (install_prefs->GetBool(
+ if (install_prefs.GetBool(
installer::master_preferences::kDistroImportSearchPref, &value)) {
if (value) {
out_prefs->do_import_items |= importer::SEARCH_ENGINES;
@@ -266,12 +266,12 @@ void SetupMasterPrefsFromInstallPrefs(
// Otherwise, wait until the user has completed first run to set it, so the
// user is guaranteed to see the bubble iff he or she has completed the first
// run process.
- if (install_prefs->GetBool(
+ if (install_prefs.GetBool(
installer::master_preferences::kDistroSuppressFirstRunBubble,
&value) && value)
SetShowFirstRunBubblePref(FIRST_RUN_BUBBLE_SUPPRESS);
- if (install_prefs->GetBool(
+ if (install_prefs.GetBool(
installer::master_preferences::kDistroImportHistoryPref,
&value)) {
if (value) {
@@ -282,10 +282,10 @@ void SetupMasterPrefsFromInstallPrefs(
}
std::string not_used;
- out_prefs->homepage_defined = install_prefs->GetString(
+ out_prefs->homepage_defined = install_prefs.GetString(
prefs::kHomePage, &not_used);
- if (install_prefs->GetBool(
+ if (install_prefs.GetBool(
installer::master_preferences::kDistroImportHomePagePref,
&value)) {
if (value) {
@@ -296,7 +296,7 @@ void SetupMasterPrefsFromInstallPrefs(
}
// Bookmarks are never imported unless specifically turned on.
- if (install_prefs->GetBool(
+ if (install_prefs.GetBool(
installer::master_preferences::kDistroImportBookmarksPref,
&value)) {
if (value)
@@ -305,17 +305,19 @@ void SetupMasterPrefsFromInstallPrefs(
out_prefs->dont_import_items |= importer::FAVORITES;
}
- if (install_prefs->GetBool(
+ if (install_prefs.GetBool(
installer::master_preferences::kMakeChromeDefaultForUser,
&value) && value) {
out_prefs->make_chrome_default = true;
}
- if (install_prefs->GetBool(
+ if (install_prefs.GetBool(
installer::master_preferences::kSuppressFirstRunDefaultBrowserPrompt,
&value) && value) {
out_prefs->suppress_first_run_default_browser_prompt = true;
}
+
+ out_prefs->variations_seed = install_prefs.GetVariationsSeed();
}
void SetDefaultBrowser(installer::MasterPreferences* install_prefs){
@@ -595,8 +597,7 @@ ProcessMasterPreferencesResult ProcessMasterPreferences(
DoDelayedInstallExtensionsIfNeeded(install_prefs.get());
- internal::SetupMasterPrefsFromInstallPrefs(out_prefs,
- install_prefs.get());
+ internal::SetupMasterPrefsFromInstallPrefs(*install_prefs, out_prefs);
internal::SetImportPreferencesAndLaunchImport(out_prefs, install_prefs.get());
internal::SetDefaultBrowser(install_prefs.get());
diff --git a/chrome/browser/first_run/first_run.h b/chrome/browser/first_run/first_run.h
index 299d78d..f1edd92 100644
--- a/chrome/browser/first_run/first_run.h
+++ b/chrome/browser/first_run/first_run.h
@@ -71,6 +71,7 @@ struct MasterPrefs {
bool suppress_first_run_default_browser_prompt;
std::vector<GURL> new_tabs;
std::vector<GURL> bookmarks;
+ std::string variations_seed;
};
// Returns true if this is the first time chrome is run for this user.
diff --git a/chrome/browser/first_run/first_run_internal.h b/chrome/browser/first_run/first_run_internal.h
index 7f8bd14..d354e65 100644
--- a/chrome/browser/first_run/first_run_internal.h
+++ b/chrome/browser/first_run/first_run_internal.h
@@ -54,8 +54,8 @@ bool CopyPrefFile(const base::FilePath& user_data_dir,
// Sets up master preferences by preferences passed by installer.
void SetupMasterPrefsFromInstallPrefs(
- MasterPrefs* out_prefs,
- installer::MasterPreferences* install_prefs);
+ const installer::MasterPreferences& install_prefs,
+ MasterPrefs* out_prefs);
void SetShowWelcomePagePrefIfNeeded(
installer::MasterPreferences* install_prefs);
diff --git a/chrome/browser/first_run/first_run_unittest.cc b/chrome/browser/first_run/first_run_unittest.cc
index 70834a0..8cd1edf 100644
--- a/chrome/browser/first_run/first_run_unittest.cc
+++ b/chrome/browser/first_run/first_run_unittest.cc
@@ -10,15 +10,18 @@
#include "chrome/browser/first_run/first_run.h"
#include "chrome/browser/first_run/first_run_internal.h"
#include "chrome/common/chrome_paths.h"
+#include "chrome/installer/util/master_preferences.h"
#include "testing/gtest/include/gtest/gtest.h"
+namespace first_run {
+
class FirstRunTest : public testing::Test {
protected:
FirstRunTest() : user_data_dir_override_(chrome::DIR_USER_DATA) {}
virtual ~FirstRunTest() {}
virtual void SetUp() OVERRIDE {
- first_run::internal::GetFirstRunSentinelFilePath(&sentinel_path_);
+ internal::GetFirstRunSentinelFilePath(&sentinel_path_);
}
base::FilePath sentinel_path_;
@@ -30,9 +33,27 @@ class FirstRunTest : public testing::Test {
};
TEST_F(FirstRunTest, RemoveSentinel) {
- EXPECT_TRUE(first_run::CreateSentinel());
+ EXPECT_TRUE(CreateSentinel());
EXPECT_TRUE(file_util::PathExists(sentinel_path_));
- EXPECT_TRUE(first_run::RemoveSentinel());
+ EXPECT_TRUE(RemoveSentinel());
EXPECT_FALSE(file_util::PathExists(sentinel_path_));
}
+
+TEST_F(FirstRunTest, SetupMasterPrefsFromInstallPrefs_VariationsSeed) {
+ installer::MasterPreferences install_prefs("{ \"variations_seed\":\"xyz\" }");
+
+ MasterPrefs out_prefs;
+ internal::SetupMasterPrefsFromInstallPrefs(install_prefs, &out_prefs);
+ EXPECT_EQ("xyz", out_prefs.variations_seed);
+}
+
+TEST_F(FirstRunTest, SetupMasterPrefsFromInstallPrefs_NoVariationsSeed) {
+ installer::MasterPreferences install_prefs("{ }");
+
+ MasterPrefs out_prefs;
+ internal::SetupMasterPrefsFromInstallPrefs(install_prefs, &out_prefs);
+ EXPECT_TRUE(out_prefs.variations_seed.empty());
+}
+
+} // namespace first_run
diff --git a/chrome/installer/util/master_preferences.cc b/chrome/installer/util/master_preferences.cc
index cb8c5d6..f423964 100644
--- a/chrome/installer/util/master_preferences.cc
+++ b/chrome/installer/util/master_preferences.cc
@@ -12,6 +12,7 @@
#include "base/path_service.h"
#include "base/string_util.h"
#include "chrome/common/env_vars.h"
+#include "chrome/common/pref_names.h"
#include "chrome/installer/util/master_preferences_constants.h"
#include "chrome/installer/util/util_constants.h"
#include "googleurl/src/gurl.h"
@@ -314,6 +315,12 @@ bool MasterPreferences::GetExtensionsBlock(DictionaryValue** extensions) const {
master_preferences::kExtensionsBlock, extensions);
}
+std::string MasterPreferences::GetVariationsSeed() const {
+ std::string variations_seed;
+ master_dictionary_->GetString(prefs::kVariationsSeed, &variations_seed);
+ return variations_seed;
+}
+
// static
const MasterPreferences& MasterPreferences::ForCurrentProcess() {
return g_master_preferences.Get();
diff --git a/chrome/installer/util/master_preferences.h b/chrome/installer/util/master_preferences.h
index 773d603..931e394 100644
--- a/chrome/installer/util/master_preferences.h
+++ b/chrome/installer/util/master_preferences.h
@@ -158,6 +158,9 @@ class MasterPreferences {
//
bool GetExtensionsBlock(base::DictionaryValue** extensions) const;
+ // Returns the variations seed entry from the master prefs.
+ std::string GetVariationsSeed() const;
+
// Returns true iff the master preferences were successfully read from a file.
bool read_from_file() const {
return preferences_read_from_file_;