Commit da891ec5 authored by stevet@chromium.org's avatar stevet@chromium.org

Add a method to read the Omaha experiment_labels value.

This includes updated unit tests.

BUG=160251


Review URL: https://chromiumcodereview.appspot.com/11826028

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@176154 0039d316-1c4b-4281-b951-d872f2087c98
parent 8f0e33c9
......@@ -668,3 +668,23 @@ bool GoogleUpdateSettings::SetExperimentLabels(
return success;
}
bool GoogleUpdateSettings::ReadExperimentLabels(
bool system_install,
string16* experiment_labels) {
HKEY reg_root = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
// If this distribution does not set the experiment labels, don't bother
// reading.
bool success = false;
BrowserDistribution* dist = BrowserDistribution::GetDistribution();
if (dist->ShouldSetExperimentLabels()) {
string16 client_state_path(
system_install ? dist->GetStateMediumKey() : dist->GetStateKey());
RegKey client_state(reg_root, client_state_path.c_str(), KEY_QUERY_VALUE);
success = client_state.ReadValue(google_update::kExperimentLabels,
experiment_labels) == ERROR_SUCCESS;
}
return success;
}
......@@ -257,6 +257,14 @@ class GoogleUpdateSettings {
static bool SetExperimentLabels(bool system_install,
const string16& experiment_labels);
// Reads the Omaha experiment_labels value in the ClientState key for this
// Chrome product and writes it into |experiment_labels|. If this distribution
// of Chrome does not set the experiment_labels value, this will do nothing to
// |experiment_labels|. This will return true if the label was successfully
// read.
static bool ReadExperimentLabels(bool system_install,
string16* experiment_labels);
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(GoogleUpdateSettings);
};
......
......@@ -119,6 +119,7 @@ class GoogleUpdateSettingsTest : public testing::Test {
BrowserDistribution* chrome =
BrowserDistribution::GetSpecificDistribution(
BrowserDistribution::CHROME_BROWSER);
std::wstring value;
#if defined(GOOGLE_CHROME_BUILD)
EXPECT_TRUE(chrome->ShouldSetExperimentLabels());
......@@ -127,7 +128,6 @@ class GoogleUpdateSettingsTest : public testing::Test {
// Validate that something is written. Only worry about the label itself.
RegKey key;
std::wstring value;
HKEY root = install == SYSTEM_INSTALL ?
HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
string16 state_key = install == SYSTEM_INSTALL ?
......@@ -138,6 +138,9 @@ class GoogleUpdateSettingsTest : public testing::Test {
EXPECT_EQ(ERROR_SUCCESS,
key.ReadValue(google_update::kExperimentLabels, &value));
EXPECT_EQ(kTestExperimentLabel, value);
EXPECT_TRUE(GoogleUpdateSettings::ReadExperimentLabels(
install == SYSTEM_INSTALL, &value));
EXPECT_EQ(kTestExperimentLabel, value);
key.Close();
// Now that the label is set, test the delete functionality. An empty label
......@@ -148,9 +151,13 @@ class GoogleUpdateSettingsTest : public testing::Test {
key.Open(root, state_key.c_str(), KEY_QUERY_VALUE));
EXPECT_EQ(ERROR_FILE_NOT_FOUND,
key.ReadValue(google_update::kExperimentLabels, &value));
EXPECT_FALSE(GoogleUpdateSettings::ReadExperimentLabels(
install == SYSTEM_INSTALL, &value));
key.Close();
#else
EXPECT_FALSE(chrome->ShouldSetExperimentLabels());
EXPECT_FALSE(GoogleUpdateSettings::ReadExperimentLabels(
install == SYSTEM_INSTALL, &value));
#endif // GOOGLE_CHROME_BUILD
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment