summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/chrome_installer.gypi4
-rw-r--r--chrome/installer/gcapi/gcapi.cc9
-rw-r--r--chrome/installer/gcapi/gcapi_omaha_experiment.cc109
-rw-r--r--chrome/installer/gcapi/gcapi_omaha_experiment.h11
-rw-r--r--chrome/installer/gcapi/gcapi_reactivation.h2
-rw-r--r--chrome/installer/gcapi/gcapi_reactivation_test.cc51
6 files changed, 181 insertions, 5 deletions
diff --git a/chrome/chrome_installer.gypi b/chrome/chrome_installer.gypi
index 77e138c..84ec4a9 100644
--- a/chrome/chrome_installer.gypi
+++ b/chrome/chrome_installer.gypi
@@ -25,6 +25,8 @@
'installer/gcapi/gcapi.cc',
'installer/gcapi/gcapi.def',
'installer/gcapi/gcapi.h',
+ 'installer/gcapi/gcapi_omaha_experiment.cc',
+ 'installer/gcapi/gcapi_omaha_experiment.h',
'installer/gcapi/gcapi_reactivation.cc',
'installer/gcapi/gcapi_reactivation.h',
],
@@ -43,6 +45,8 @@
'sources': [
'installer/gcapi/gcapi.cc',
'installer/gcapi/gcapi.h',
+ 'installer/gcapi/gcapi_omaha_experiment.cc',
+ 'installer/gcapi/gcapi_omaha_experiment.h',
'installer/gcapi/gcapi_reactivation.cc',
'installer/gcapi/gcapi_reactivation.h',
],
diff --git a/chrome/installer/gcapi/gcapi.cc b/chrome/installer/gcapi/gcapi.cc
index 79d3a3c..ae786e9 100644
--- a/chrome/installer/gcapi/gcapi.cc
+++ b/chrome/installer/gcapi/gcapi.cc
@@ -29,6 +29,7 @@
#include "base/win/scoped_com_initializer.h"
#include "base/win/scoped_comptr.h"
#include "base/win/scoped_handle.h"
+#include "chrome/installer/gcapi/gcapi_omaha_experiment.h"
#include "chrome/installer/gcapi/gcapi_reactivation.h"
#include "chrome/installer/util/google_update_constants.h"
#include "chrome/installer/util/util_constants.h"
@@ -564,7 +565,7 @@ BOOL __stdcall CanOfferReactivation(const wchar_t* brand_code,
}
int days_since_last_run = GoogleChromeDaysSinceLastRun();
- if (days_since_last_run > 0 &&
+ if (days_since_last_run >= 0 &&
days_since_last_run < kReactivationMinDaysDormant) {
if (error_code)
*error_code = REACTIVATE_ERROR_NOTDORMANT;
@@ -599,8 +600,10 @@ BOOL __stdcall ReactivateChrome(wchar_t* brand_code,
previous_brand_codes,
error_code)) {
if (SetReactivationBrandCode(brand_code)) {
- // TODO(robertshield): Set Omaha reg key to add experiment label for
- // tracking 7DA.
+ // Currently set this as a best-effort thing. We return TRUE if
+ // reactivation succeeded regardless of the experiment label result.
+ SetOmahaExperimentLabel(brand_code);
+
result = TRUE;
} else {
if (error_code)
diff --git a/chrome/installer/gcapi/gcapi_omaha_experiment.cc b/chrome/installer/gcapi/gcapi_omaha_experiment.cc
new file mode 100644
index 0000000..539bd6f
--- /dev/null
+++ b/chrome/installer/gcapi/gcapi_omaha_experiment.cc
@@ -0,0 +1,109 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/installer/gcapi/gcapi_omaha_experiment.h"
+
+#include "base/string16.h"
+#include "base/stringprintf.h"
+#include "base/string_number_conversions.h"
+#include "base/time.h"
+#include "base/win/registry.h"
+#include "chrome/installer/util/browser_distribution.h"
+#include "chrome/installer/util/google_update_constants.h"
+
+using base::Time;
+using base::TimeDelta;
+using base::win::RegKey;
+
+namespace {
+
+const wchar_t kExperimentLabels[] = L"experiment_labels";
+
+const wchar_t* kExperimentAppGuids[] = {
+ L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}",
+ L"{8A69D345-D564-463C-AFF1-A69D9E530F96}",
+};
+
+const wchar_t* kDays[] =
+ { L"Sun", L"Mon", L"Tue", L"Wed", L"Thu", L"Fri", L"Sat" };
+
+const wchar_t* kMonths[] = {L"Jan", L"Feb", L"Mar", L"Apr", L"May", L"Jun",
+ L"Jul", L"Aug", L"Sep", L"Oct", L"Nov", L"Dec"};
+
+// Constructs a date string of the following format for the current time plus
+// one year:
+// "DAY, DD0 MON YYYY HH0:MI0:SE0 TZ"
+// DAY = 3 character day of week,
+// DD0 = 2 digit day of month,
+// MON = 3 character month of year,
+// YYYY = 4 digit year,
+// HH0 = 2 digit hour,
+// MI0 = 2 digit minute,
+// SE0 = 2 digit second,
+// TZ = 3 character timezone)
+string16 BuildOmahaExperimentDateString() {
+ Time then_time = Time::Now() + TimeDelta::FromDays(365);
+ Time::Exploded then = {};
+ then_time.UTCExplode(&then);
+
+ if (!then.HasValidValues())
+ return L"";
+
+ string16 date_string;
+ base::SStringPrintf(&date_string,
+ L"%ls, %02d %ls %d %02d:%02d:%02d GMT",
+ kDays[then.day_of_week],
+ then.day_of_month,
+ kMonths[then.month - 1],
+ then.year,
+ then.hour,
+ then.minute,
+ then.second);
+ return date_string;
+}
+
+// Returns the number of weeks since 2/3/2003.
+int GetCurrentRlzWeek() {
+ Time::Exploded february_third_2003_exploded = {2003, 2, 1, 3, 0, 0, 0, 0};
+ Time f = Time::FromUTCExploded(february_third_2003_exploded);
+ TimeDelta delta = Time::Now() - f;
+ return delta.InDays() / 7;
+}
+
+} // namespace
+
+bool SetOmahaExperimentLabel(const wchar_t* brand_code) {
+ if (!brand_code) {
+ return false;
+ }
+
+ int week_number = GetCurrentRlzWeek();
+ if (week_number < 0 || week_number > 999)
+ week_number = 999;
+
+ string16 experiment_label;
+ base::SStringPrintf(&experiment_label,
+ L"%ls_%d|%ls",
+ brand_code,
+ week_number,
+ BuildOmahaExperimentDateString().c_str());
+
+ int successful_writes = 0;
+ for (int i = 0; i < arraysize(kExperimentAppGuids); ++i) {
+ string16 experiment_path(google_update::kRegPathClientState);
+ experiment_path += L"\\";
+ experiment_path += kExperimentAppGuids[i];
+
+ RegKey client_state(HKEY_LOCAL_MACHINE, experiment_path.c_str(),
+ KEY_SET_VALUE);
+ if (client_state.Valid()) {
+ if (client_state.WriteValue(kExperimentLabels,
+ experiment_label.c_str()) == ERROR_SUCCESS) {
+ successful_writes++;
+ }
+ }
+ }
+
+ return (successful_writes == arraysize(kExperimentAppGuids));
+}
diff --git a/chrome/installer/gcapi/gcapi_omaha_experiment.h b/chrome/installer/gcapi/gcapi_omaha_experiment.h
new file mode 100644
index 0000000..0550305
--- /dev/null
+++ b/chrome/installer/gcapi/gcapi_omaha_experiment.h
@@ -0,0 +1,11 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_INSTALLER_GCAPI_GCAPI_OMAHA_EXPERIMENT_H_
+#define CHROME_INSTALLER_GCAPI_GCAPI_OMAHA_EXPERIMENT_H_
+#pragma once
+
+bool SetOmahaExperimentLabel(const wchar_t* brand_code);
+
+#endif // CHROME_INSTALLER_GCAPI_GCAPI_OMAHA_EXPERIMENT_H_
diff --git a/chrome/installer/gcapi/gcapi_reactivation.h b/chrome/installer/gcapi/gcapi_reactivation.h
index 5ace0b8..d9e5db8 100644
--- a/chrome/installer/gcapi/gcapi_reactivation.h
+++ b/chrome/installer/gcapi/gcapi_reactivation.h
@@ -6,8 +6,6 @@
#define CHROME_INSTALLER_GCAPI_GCAPI_REACTIVATION_H_
#pragma once
-#include <windows.h>
-
#include <string>
#include <vector>
diff --git a/chrome/installer/gcapi/gcapi_reactivation_test.cc b/chrome/installer/gcapi/gcapi_reactivation_test.cc
index 9cadafc..822cb80 100644
--- a/chrome/installer/gcapi/gcapi_reactivation_test.cc
+++ b/chrome/installer/gcapi/gcapi_reactivation_test.cc
@@ -13,6 +13,7 @@
#include "base/win/registry.h"
#include "chrome/common/guid.h"
#include "chrome/installer/gcapi/gcapi.h"
+#include "chrome/installer/gcapi/gcapi_omaha_experiment.h"
#include "chrome/installer/gcapi/gcapi_reactivation.h"
#include "chrome/installer/util/google_update_constants.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -21,6 +22,16 @@ using base::Time;
using base::TimeDelta;
using base::win::RegKey;
+namespace {
+
+const wchar_t kExperimentLabels[] = L"experiment_labels";
+
+const wchar_t* kExperimentAppGuids[] = {
+ L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}",
+ L"{8A69D345-D564-463C-AFF1-A69D9E530F96}",
+};
+
+}
class GCAPIReactivationTest : public ::testing::Test {
protected:
@@ -29,6 +40,9 @@ class GCAPIReactivationTest : public ::testing::Test {
std::wstring hkcu_override = base::StringPrintf(
L"hkcu_override\\%ls", ASCIIToWide(guid::GenerateGUID()));
override_manager_.OverrideRegistry(HKEY_CURRENT_USER, hkcu_override);
+ std::wstring hklm_override = base::StringPrintf(
+ L"hklm_override\\%ls", ASCIIToWide(guid::GenerateGUID()));
+ override_manager_.OverrideRegistry(HKEY_LOCAL_MACHINE, hklm_override);
}
bool SetChromeInstallMarker(HKEY hive) {
@@ -64,6 +78,24 @@ class GCAPIReactivationTest : public ::testing::Test {
last_run_time_string.c_str()) == ERROR_SUCCESS);
}
+ bool HasExperimentLabels() {
+ int label_count = 0;
+ for (int i = 0; i < arraysize(kExperimentAppGuids); ++i) {
+ string16 client_state_path(google_update::kRegPathClientState);
+ client_state_path += L"\\";
+ client_state_path += kExperimentAppGuids[i];
+
+ RegKey client_state_key(HKEY_LOCAL_MACHINE,
+ client_state_path.c_str(),
+ KEY_QUERY_VALUE);
+ if (client_state_key.Valid() &&
+ client_state_key.HasValue(kExperimentLabels)) {
+ label_count++;
+ }
+ }
+ return label_count == arraysize(kExperimentAppGuids);
+ }
+
std::wstring GetReactivationString(HKEY hive) {
const wchar_t* base_path =
(hive == HKEY_LOCAL_MACHINE) ?
@@ -184,3 +216,22 @@ TEST_F(GCAPIReactivationTest, Reactivation_Flow) {
EXPECT_EQ(REACTIVATE_ERROR_ALREADY_REACTIVATED, error);
EXPECT_EQ(L"MAMA", GetReactivationString(HKEY_CURRENT_USER));
}
+
+TEST_F(GCAPIReactivationTest, ExperimentLabelCheck) {
+ const wchar_t* previous_brands[] = {L"GOOGOO", L"MAMA", L"DADA"};
+ DWORD error;
+
+ // Set us up as a candidate for reactivation.
+ EXPECT_TRUE(SetChromeInstallMarker(HKEY_CURRENT_USER));
+
+ Time hkcu_last_run = Time::NowFromSystemTime() -
+ TimeDelta::FromDays(kReactivationMinDaysDormant);
+ EXPECT_TRUE(SetLastRunTime(HKEY_CURRENT_USER,
+ hkcu_last_run.ToInternalValue()));
+
+ EXPECT_TRUE(ReactivateChrome(L"GAGA", arraysize(previous_brands),
+ previous_brands, &error));
+ EXPECT_EQ(L"GAGA", GetReactivationString(HKEY_CURRENT_USER));
+
+ EXPECT_TRUE(HasExperimentLabels());
+}