Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(791)

Side by Side Diff: chrome/installer/gcapi/gcapi_omaha_experiment.cc

Issue 23579003: GCAPI should append to the existing experiment_labels instead of clobbering them. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: include string16.h Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/installer/gcapi/gcapi_omaha_experiment.h" 5 #include "chrome/installer/gcapi/gcapi_omaha_experiment.h"
6 6
7 #include "base/strings/string16.h" 7 #include "base/strings/string16.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "chrome/installer/gcapi/gcapi.h" 10 #include "chrome/installer/gcapi/gcapi.h"
11 #include "chrome/installer/util/google_update_constants.h"
11 #include "chrome/installer/util/google_update_experiment_util.h" 12 #include "chrome/installer/util/google_update_experiment_util.h"
12 #include "chrome/installer/util/google_update_settings.h" 13 #include "chrome/installer/util/google_update_settings.h"
13 14
14 using base::Time; 15 using base::Time;
15 using base::TimeDelta; 16 using base::TimeDelta;
16 17
17 namespace { 18 namespace {
18 19
19 // Returns the number of weeks since 2/3/2003. 20 // Returns the number of weeks since 2/3/2003.
20 int GetCurrentRlzWeek() { 21 int GetCurrentRlzWeek() {
21 Time::Exploded february_third_2003_exploded = {2003, 2, 1, 3, 0, 0, 0, 0}; 22 Time::Exploded february_third_2003_exploded = {2003, 2, 1, 3, 0, 0, 0, 0};
22 Time f = Time::FromUTCExploded(february_third_2003_exploded); 23 Time f = Time::FromUTCExploded(february_third_2003_exploded);
23 TimeDelta delta = Time::Now() - f; 24 TimeDelta delta = Time::Now() - f;
24 return delta.InDays() / 7; 25 return delta.InDays() / 7;
25 } 26 }
26 27
27 bool SetLabel(const wchar_t* brand_code, const wchar_t* label, int shell_mode) { 28 bool SetExperimentLabel(const wchar_t* brand_code,
29 const string16& label,
30 int shell_mode) {
28 if (!brand_code) { 31 if (!brand_code) {
29 return false; 32 return false;
30 } 33 }
31 34
35 const bool system_level = shell_mode == GCAPI_INVOKED_UAC_ELEVATION;
36
37 string16 experiment_labels;
38 if (!GoogleUpdateSettings::ReadExperimentLabels(system_level,
39 &experiment_labels)) {
40 return false;
41 }
42
43 // First erase this label from the existing experiment labels if it exists.
44 size_t existing_label_begin = experiment_labels.find(label + L"=");
45 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.
46 size_t existing_label_end =
47 experiment_labels.find(google_update::kExperimentLabelSep,
48 existing_label_begin);
49 // Note: if |existing_label_end == string16::npos| this will work anyways
50 // as npos is defined as the biggest possible unsigned integer and erase
51 // will thus, by definition, erase to the end of the string.
52 experiment_labels.erase(existing_label_begin,
53 existing_label_end - existing_label_begin);
54 }
55
32 int week_number = GetCurrentRlzWeek(); 56 int week_number = GetCurrentRlzWeek();
33 if (week_number < 0 || week_number > 999) 57 if (week_number < 0 || week_number > 999)
34 week_number = 999; 58 week_number = 999;
35 59
36 string16 experiment_labels; 60 string16 gcapi_experiment_label;
37 base::SStringPrintf(&experiment_labels, 61 base::SStringPrintf(&gcapi_experiment_label,
38 L"%ls=%ls_%d|%ls", 62 L"%ls=%ls_%d|%ls",
39 label, 63 label.c_str(),
40 brand_code, 64 brand_code,
41 week_number, 65 week_number,
42 installer::BuildExperimentDateString().c_str()); 66 installer::BuildExperimentDateString().c_str());
43 67
44 return GoogleUpdateSettings::SetExperimentLabels( 68 if (!experiment_labels.empty())
45 shell_mode == GCAPI_INVOKED_UAC_ELEVATION, 69 experiment_labels.append(google_update::kExperimentLabelSep);
46 experiment_labels); 70 experiment_labels.append(gcapi_experiment_label);
71
72 return GoogleUpdateSettings::SetExperimentLabels(system_level,
73 experiment_labels);
47 } 74 }
48 75
49 } // namespace 76 } // namespace
50 77
51 bool SetReactivationExperimentLabels(const wchar_t* brand_code, 78 bool SetReactivationExperimentLabels(const wchar_t* brand_code,
52 int shell_mode) { 79 int shell_mode) {
53 return SetLabel(brand_code, L"reacbrand", shell_mode); 80 return SetExperimentLabel(brand_code, L"reacbrand", shell_mode);
54 } 81 }
55 82
56 bool SetRelaunchExperimentLabels(const wchar_t* brand_code, int shell_mode) { 83 bool SetRelaunchExperimentLabels(const wchar_t* brand_code, int shell_mode) {
57 return SetLabel(brand_code, L"relaunchbrand", shell_mode); 84 return SetExperimentLabel(brand_code, L"relaunchbrand", shell_mode);
58 } 85 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698