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

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: review Created 7 years, 1 month 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/basictypes.h"
8 #include "base/strings/string_split.h"
9 #include "base/strings/string_util.h"
8 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
9 #include "base/time/time.h" 11 #include "base/time/time.h"
10 #include "chrome/installer/gcapi/gcapi.h" 12 #include "chrome/installer/gcapi/gcapi.h"
13 #include "chrome/installer/util/google_update_constants.h"
11 #include "chrome/installer/util/google_update_experiment_util.h" 14 #include "chrome/installer/util/google_update_experiment_util.h"
12 #include "chrome/installer/util/google_update_settings.h" 15 #include "chrome/installer/util/google_update_settings.h"
13 16
14 using base::Time; 17 using base::Time;
15 using base::TimeDelta; 18 using base::TimeDelta;
Alexei Svitkine (slow) 2013/11/05 23:05:23 Either remove these using decls and prefix the use
gab 2013/11/06 16:39:10 Done.
16 19
17 namespace { 20 namespace {
18 21
19 // Returns the number of weeks since 2/3/2003. 22 // Returns the number of weeks since 2/3/2003.
20 int GetCurrentRlzWeek() { 23 int GetCurrentRlzWeek(const base::Time& current_time) {
21 Time::Exploded february_third_2003_exploded = {2003, 2, 1, 3, 0, 0, 0, 0}; 24 Time::Exploded february_third_2003_exploded = {2003, 2, 1, 3, 0, 0, 0, 0};
22 Time f = Time::FromUTCExploded(february_third_2003_exploded); 25 Time f = Time::FromUTCExploded(february_third_2003_exploded);
23 TimeDelta delta = Time::Now() - f; 26 TimeDelta delta = current_time - f;
24 return delta.InDays() / 7; 27 return delta.InDays() / 7;
25 } 28 }
26 29
27 bool SetLabel(const wchar_t* brand_code, const wchar_t* label, int shell_mode) { 30 bool SetExperimentLabel(const wchar_t* brand_code,
31 const string16& label,
32 int shell_mode) {
28 if (!brand_code) { 33 if (!brand_code) {
29 return false; 34 return false;
30 } 35 }
31 36
32 int week_number = GetCurrentRlzWeek(); 37 const bool system_level = shell_mode == GCAPI_INVOKED_UAC_ELEVATION;
33 if (week_number < 0 || week_number > 999)
34 week_number = 999;
35 38
36 string16 experiment_labels; 39 string16 original_labels;
37 base::SStringPrintf(&experiment_labels, 40 if (!GoogleUpdateSettings::ReadExperimentLabels(system_level,
38 L"%ls=%ls_%d|%ls", 41 &original_labels)) {
39 label, 42 return false;
40 brand_code, 43 }
41 week_number,
42 installer::BuildExperimentDateString().c_str());
43 44
44 return GoogleUpdateSettings::SetExperimentLabels( 45 // Split the original labels by the label separator.
45 shell_mode == GCAPI_INVOKED_UAC_ELEVATION, 46 std::vector<string16> entries;
46 experiment_labels); 47 base::SplitStringUsingSubstr(
48 original_labels, google_update::kExperimentLabelSep, &entries);
49
50 // Keep all labels, but the one we want to add/replace.
51 string16 new_labels;
52 for (std::vector<string16>::const_iterator it = entries.begin();
53 it != entries.end(); ++it) {
54 if (!it->empty() && !StartsWith(*it + L"=", label, true)) {
Alexei Svitkine (slow) 2013/11/05 23:05:23 Shouldn't this be "StartsWith(*it, label + "L=", t
gab 2013/11/06 16:39:10 Good catch! Added a new test which fails with this
55 new_labels += *it;
56 new_labels += google_update::kExperimentLabelSep;
57 }
58 }
59
60 new_labels.append(
61 gcapi_internals::GetGCAPIExperimentLabel(brand_code, label));
62
63 return GoogleUpdateSettings::SetExperimentLabels(system_level,
64 new_labels);
47 } 65 }
48 66
49 } // namespace 67 } // namespace
50 68
69 namespace gcapi_internals {
70
71 const wchar_t kReactivationLabel[] = L"reacbrand";
72 const wchar_t kRelaunchLabel[] = L"relaunchbrand";
73
74 string16 GetGCAPIExperimentLabel(const wchar_t* brand_code,
75 const string16& label) {
76 // Keeps a fixed time state for this GCAPI instance; this makes tests reliable
77 // when crossing time boundaries on the system clock and doesn't otherwise
78 // affect results of this short lived binary.
79 static time_t instance_time_value = 0;
80 if (instance_time_value == 0)
81 instance_time_value = base::Time::Now().ToTimeT();
82
83 base::Time instance_time = base::Time::FromTimeT(instance_time_value);
84
85 string16 gcapi_experiment_label;
86 base::SStringPrintf(&gcapi_experiment_label,
87 L"%ls=%ls_%d|%ls",
88 label.c_str(),
89 brand_code,
90 GetCurrentRlzWeek(instance_time),
91 installer::BuildExperimentDateString(
92 instance_time).c_str());
93 return gcapi_experiment_label;
94 }
95
96 } // namespace gcapi_internals
97
51 bool SetReactivationExperimentLabels(const wchar_t* brand_code, 98 bool SetReactivationExperimentLabels(const wchar_t* brand_code,
52 int shell_mode) { 99 int shell_mode) {
53 return SetLabel(brand_code, L"reacbrand", shell_mode); 100 return SetExperimentLabel(brand_code, gcapi_internals::kReactivationLabel,
101 shell_mode);
54 } 102 }
55 103
56 bool SetRelaunchExperimentLabels(const wchar_t* brand_code, int shell_mode) { 104 bool SetRelaunchExperimentLabels(const wchar_t* brand_code, int shell_mode) {
57 return SetLabel(brand_code, L"relaunchbrand", shell_mode); 105 return SetExperimentLabel(brand_code, gcapi_internals::kRelaunchLabel,
106 shell_mode);
58 } 107 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698