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
3 // found in the LICENSE file.
5 #include "chrome/installer/gcapi/gcapi_reactivation.h"
7 #include "base/time/time.h"
8 #include "base/win/registry.h"
9 #include "chrome/installer/gcapi/gcapi.h"
10 #include "chrome/installer/util/google_update_constants.h"
13 using base::win::RegKey;
16 const wchar_t kReactivationHistoryKey[] = L"reactivation";
18 std::wstring GetReactivationHistoryKeyPath() {
19 std::wstring reactivation_path(google_update::kRegPathClientState);
20 reactivation_path += L"\\";
21 reactivation_path += google_update::kChromeUpgradeCode;
22 reactivation_path += L"\\";
23 reactivation_path += kReactivationHistoryKey;
24 return reactivation_path;
28 bool HasBeenReactivated() {
29 RegKey reactivation_key(HKEY_CURRENT_USER,
30 GetReactivationHistoryKeyPath().c_str(),
33 return reactivation_key.Valid();
36 bool SetReactivationBrandCode(const std::wstring& brand_code, int shell_mode) {
39 // This function currently only should be run in a non-elevated shell,
40 // so we return "true" if it is being invoked from an elevated shell.
41 if (shell_mode == GCAPI_INVOKED_UAC_ELEVATION)
44 std::wstring path(google_update::kRegPathClientState);
46 path += google_update::kChromeUpgradeCode;
48 RegKey client_state_key(HKEY_CURRENT_USER, path.c_str(), KEY_SET_VALUE);
49 if (client_state_key.Valid()) {
50 success = client_state_key.WriteValue(
51 google_update::kRegRLZReactivationBrandField,
52 brand_code.c_str()) == ERROR_SUCCESS;
56 // Store this brand code in the reactivation history. Store it with a
57 // a currently un-used timestamp for future proofing.
58 RegKey reactivation_key(HKEY_CURRENT_USER,
59 GetReactivationHistoryKeyPath().c_str(),
61 if (reactivation_key.Valid()) {
62 int64 timestamp = Time::Now().ToInternalValue();
63 reactivation_key.WriteValue(brand_code.c_str(),