summaryrefslogtreecommitdiffstats
path: root/chrome/installer/gcapi/gcapi_reactivation.cc
diff options
context:
space:
mode:
authorrobertshield@chromium.org <robertshield@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-31 03:59:20 +0000
committerrobertshield@chromium.org <robertshield@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-31 03:59:20 +0000
commitebcb5207a92da2acf2034d4e2d9054b76b41c6d5 (patch)
tree6d6f2244e08bf66427f9734cf35e9a29dfa6f3d8 /chrome/installer/gcapi/gcapi_reactivation.cc
parent716a6125dd1633606261ba49b30408a466a6fc44 (diff)
downloadchromium_src-ebcb5207a92da2acf2034d4e2d9054b76b41c6d5.zip
chromium_src-ebcb5207a92da2acf2034d4e2d9054b76b41c6d5.tar.gz
chromium_src-ebcb5207a92da2acf2034d4e2d9054b76b41c6d5.tar.bz2
Implementation of GCAPI reactivation.
Also, some cleanup in gcapi_tests such that it now only runs gtest tests by default. BUG=111453 TEST=gcapi_tests.exe Review URL: https://chromiumcodereview.appspot.com/9288056 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@119841 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/installer/gcapi/gcapi_reactivation.cc')
-rw-r--r--chrome/installer/gcapi/gcapi_reactivation.cc77
1 files changed, 77 insertions, 0 deletions
diff --git a/chrome/installer/gcapi/gcapi_reactivation.cc b/chrome/installer/gcapi/gcapi_reactivation.cc
new file mode 100644
index 0000000..6755e2f
--- /dev/null
+++ b/chrome/installer/gcapi/gcapi_reactivation.cc
@@ -0,0 +1,77 @@
+// 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_reactivation.h"
+
+#include "base/time.h"
+#include "base/win/registry.h"
+#include "chrome/installer/util/google_update_constants.h"
+
+using base::Time;
+using base::win::RegKey;
+
+namespace {
+const wchar_t kReactivationHistoryKey[] = L"reactivation";
+
+std::wstring GetReactivationHistoryKeyPath() {
+ std::wstring reactivation_path(google_update::kRegPathClientState);
+ reactivation_path += L"\\";
+ reactivation_path += google_update::kChromeUpgradeCode;
+ reactivation_path += L"\\";
+ reactivation_path += kReactivationHistoryKey;
+ return reactivation_path;
+}
+} // namespace
+
+bool HasBeenReactivatedByBrandCodes(
+ const std::vector<std::wstring>& brand_codes) {
+ bool success = false;
+
+ RegKey reactivation_key(HKEY_CURRENT_USER,
+ GetReactivationHistoryKeyPath().c_str(),
+ KEY_QUERY_VALUE);
+ if (reactivation_key.Valid()) {
+ std::vector<std::wstring>::const_iterator brand_iter(brand_codes.begin());
+ for (; brand_iter != brand_codes.end(); ++brand_iter) {
+ if (reactivation_key.HasValue(brand_iter->c_str())) {
+ success = true;
+ break;
+ }
+ }
+ }
+
+ return success;
+}
+
+bool SetReactivationBrandCode(const std::wstring& brand_code) {
+ bool success = false;
+
+ std::wstring path(google_update::kRegPathClientState);
+ path += L"\\";
+ path += google_update::kChromeUpgradeCode;
+
+ RegKey client_state_key(HKEY_CURRENT_USER, path.c_str(), KEY_SET_VALUE);
+ if (client_state_key.Valid()) {
+ success = client_state_key.WriteValue(
+ google_update::kRegRLZReactivationBrandField,
+ brand_code.c_str()) == ERROR_SUCCESS;
+ }
+
+ if (success) {
+ // Store this brand code in the reactivation history. Store it with a
+ // a currently un-used timestamp for future proofing.
+ RegKey reactivation_key(HKEY_CURRENT_USER,
+ GetReactivationHistoryKeyPath().c_str(),
+ KEY_WRITE);
+ if (reactivation_key.Valid()) {
+ int64 timestamp = Time::Now().ToInternalValue();
+ reactivation_key.WriteValue(brand_code.c_str(),
+ &timestamp,
+ sizeof(timestamp),
+ REG_QWORD);
+ }
+ }
+
+ return success;
+} \ No newline at end of file