Chromium Code Reviews| Index: chrome/installer/gcapi/gcapi_omaha_experiment.cc |
| diff --git a/chrome/installer/gcapi/gcapi_omaha_experiment.cc b/chrome/installer/gcapi/gcapi_omaha_experiment.cc |
| index ac5899fe675e27fa09c8a2b557ae75fa38633b6a..0510d9cd58b9b77bfbc4bb7af4b47986c8a7a079 100644 |
| --- a/chrome/installer/gcapi/gcapi_omaha_experiment.cc |
| +++ b/chrome/installer/gcapi/gcapi_omaha_experiment.cc |
| @@ -8,6 +8,7 @@ |
| #include "base/strings/stringprintf.h" |
| #include "base/time/time.h" |
| #include "chrome/installer/gcapi/gcapi.h" |
| +#include "chrome/installer/util/google_update_constants.h" |
| #include "chrome/installer/util/google_update_experiment_util.h" |
| #include "chrome/installer/util/google_update_settings.h" |
| @@ -24,35 +25,61 @@ int GetCurrentRlzWeek() { |
| return delta.InDays() / 7; |
| } |
| -bool SetLabel(const wchar_t* brand_code, const wchar_t* label, int shell_mode) { |
| +bool SetExperimentLabel(const wchar_t* brand_code, |
| + const string16& label, |
| + int shell_mode) { |
| if (!brand_code) { |
| return false; |
| } |
| + const bool system_level = shell_mode == GCAPI_INVOKED_UAC_ELEVATION; |
| + |
| + string16 experiment_labels; |
| + if (!GoogleUpdateSettings::ReadExperimentLabels(system_level, |
| + &experiment_labels)) { |
| + return false; |
| + } |
| + |
| + // First erase this label from the existing experiment labels if it exists. |
| + size_t existing_label_begin = experiment_labels.find(label + L"="); |
| + if (existing_label_begin != string16::npos) { |
|
Alexei Svitkine (slow)
2013/08/30 14:17:19
I think it would be safer to also check that eithe
gab
2013/08/30 17:53:11
This is mitigated by searching for (label + "=");
Alexei Svitkine (slow)
2013/08/30 18:16:11
I guess it depends how they're parsed. If each ent
gab
2013/08/30 22:57:14
Added extra safety for this.
|
| + size_t existing_label_end = |
| + experiment_labels.find(google_update::kExperimentLabelSep, |
| + existing_label_begin); |
| + // Note: if |existing_label_end == string16::npos| this will work anyways |
| + // as npos is defined as the biggest possible unsigned integer and erase |
| + // will thus, by definition, erase to the end of the string. |
| + experiment_labels.erase(existing_label_begin, |
| + existing_label_end - existing_label_begin); |
| + } |
| + |
| int week_number = GetCurrentRlzWeek(); |
| if (week_number < 0 || week_number > 999) |
| week_number = 999; |
| - string16 experiment_labels; |
| - base::SStringPrintf(&experiment_labels, |
| + string16 gcapi_experiment_label; |
| + base::SStringPrintf(&gcapi_experiment_label, |
| L"%ls=%ls_%d|%ls", |
| - label, |
| + label.c_str(), |
| brand_code, |
| week_number, |
| installer::BuildExperimentDateString().c_str()); |
| - return GoogleUpdateSettings::SetExperimentLabels( |
| - shell_mode == GCAPI_INVOKED_UAC_ELEVATION, |
| - experiment_labels); |
| + if (!experiment_labels.empty()) |
| + experiment_labels.append(google_update::kExperimentLabelSep); |
| + experiment_labels.append(gcapi_experiment_label); |
| + |
| + return GoogleUpdateSettings::SetExperimentLabels(system_level, |
| + experiment_labels); |
| } |
| } // namespace |
| bool SetReactivationExperimentLabels(const wchar_t* brand_code, |
| int shell_mode) { |
| - return SetLabel(brand_code, L"reacbrand", shell_mode); |
| + return SetExperimentLabel(brand_code, L"reacbrand", shell_mode); |
| } |
| bool SetRelaunchExperimentLabels(const wchar_t* brand_code, int shell_mode) { |
| - return SetLabel(brand_code, L"relaunchbrand", shell_mode); |
| + return SetExperimentLabel(brand_code, L"relaunchbrand", shell_mode); |
| } |