OLD | NEW |
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_reactivation.h" | 5 #include "chrome/installer/gcapi/gcapi_reactivation.h" |
6 | 6 |
7 #include "base/time/time.h" | 7 #include "base/time/time.h" |
8 #include "base/win/registry.h" | 8 #include "base/win/registry.h" |
9 #include "chrome/installer/gcapi/gcapi.h" | 9 #include "chrome/installer/gcapi/gcapi.h" |
10 #include "chrome/installer/util/google_update_constants.h" | 10 #include "chrome/installer/util/google_update_constants.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 reactivation_path += google_update::kChromeUpgradeCode; | 21 reactivation_path += google_update::kChromeUpgradeCode; |
22 reactivation_path += L"\\"; | 22 reactivation_path += L"\\"; |
23 reactivation_path += kReactivationHistoryKey; | 23 reactivation_path += kReactivationHistoryKey; |
24 return reactivation_path; | 24 return reactivation_path; |
25 } | 25 } |
26 } // namespace | 26 } // namespace |
27 | 27 |
28 bool HasBeenReactivated() { | 28 bool HasBeenReactivated() { |
29 RegKey reactivation_key(HKEY_CURRENT_USER, | 29 RegKey reactivation_key(HKEY_CURRENT_USER, |
30 GetReactivationHistoryKeyPath().c_str(), | 30 GetReactivationHistoryKeyPath().c_str(), |
31 KEY_QUERY_VALUE | KEY_WOW64_32KEY); | 31 KEY_QUERY_VALUE); |
32 | 32 |
33 return reactivation_key.Valid(); | 33 return reactivation_key.Valid(); |
34 } | 34 } |
35 | 35 |
36 bool SetReactivationBrandCode(const std::wstring& brand_code, int shell_mode) { | 36 bool SetReactivationBrandCode(const std::wstring& brand_code, int shell_mode) { |
37 bool success = false; | 37 bool success = false; |
38 | 38 |
39 // This function currently only should be run in a non-elevated shell, | 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. | 40 // so we return "true" if it is being invoked from an elevated shell. |
41 if (shell_mode == GCAPI_INVOKED_UAC_ELEVATION) | 41 if (shell_mode == GCAPI_INVOKED_UAC_ELEVATION) |
42 return true; | 42 return true; |
43 | 43 |
44 std::wstring path(google_update::kRegPathClientState); | 44 std::wstring path(google_update::kRegPathClientState); |
45 path += L"\\"; | 45 path += L"\\"; |
46 path += google_update::kChromeUpgradeCode; | 46 path += google_update::kChromeUpgradeCode; |
47 | 47 |
48 RegKey client_state_key( | 48 RegKey client_state_key(HKEY_CURRENT_USER, path.c_str(), KEY_SET_VALUE); |
49 HKEY_CURRENT_USER, path.c_str(), KEY_SET_VALUE | KEY_WOW64_32KEY); | |
50 if (client_state_key.Valid()) { | 49 if (client_state_key.Valid()) { |
51 success = client_state_key.WriteValue( | 50 success = client_state_key.WriteValue( |
52 google_update::kRegRLZReactivationBrandField, | 51 google_update::kRegRLZReactivationBrandField, |
53 brand_code.c_str()) == ERROR_SUCCESS; | 52 brand_code.c_str()) == ERROR_SUCCESS; |
54 } | 53 } |
55 | 54 |
56 if (success) { | 55 if (success) { |
57 // Store this brand code in the reactivation history. Store it with a | 56 // Store this brand code in the reactivation history. Store it with a |
58 // a currently un-used timestamp for future proofing. | 57 // a currently un-used timestamp for future proofing. |
59 RegKey reactivation_key(HKEY_CURRENT_USER, | 58 RegKey reactivation_key(HKEY_CURRENT_USER, |
60 GetReactivationHistoryKeyPath().c_str(), | 59 GetReactivationHistoryKeyPath().c_str(), |
61 KEY_WRITE | KEY_WOW64_32KEY); | 60 KEY_WRITE); |
62 if (reactivation_key.Valid()) { | 61 if (reactivation_key.Valid()) { |
63 int64 timestamp = Time::Now().ToInternalValue(); | 62 int64 timestamp = Time::Now().ToInternalValue(); |
64 reactivation_key.WriteValue(brand_code.c_str(), | 63 reactivation_key.WriteValue(brand_code.c_str(), |
65 ×tamp, | 64 ×tamp, |
66 sizeof(timestamp), | 65 sizeof(timestamp), |
67 REG_QWORD); | 66 REG_QWORD); |
68 } | 67 } |
69 } | 68 } |
70 | 69 |
71 return success; | 70 return success; |
72 } | 71 } |
73 | 72 |
OLD | NEW |