OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #include "chrome/installer/gcapi/gcapi_reactivation.h" | |
6 | |
7 #include "base/time.h" | |
8 #include "base/win/registry.h" | |
9 #include "chrome/installer/util/google_update_constants.h" | |
10 | |
11 using base::Time; | |
12 using base::win::RegKey; | |
13 | |
14 namespace { | |
15 const wchar_t kReactivationHistoryKey[] = L"reactivation"; | |
16 | |
17 std::wstring GetReactivationHistoryKeyPath() { | |
18 std::wstring reactivation_path(google_update::kRegPathClientState); | |
19 reactivation_path += L"\\"; | |
20 reactivation_path += google_update::kChromeUpgradeCode; | |
21 reactivation_path += L"\\"; | |
22 reactivation_path += kReactivationHistoryKey; | |
23 return reactivation_path; | |
24 } | |
25 } // namespace | |
26 | |
27 bool HasBeenReactivatedByBrandCodes( | |
28 const std::vector<std::wstring>& brand_codes) { | |
29 bool success = false; | |
30 | |
31 RegKey reactivation_key(HKEY_CURRENT_USER, | |
32 GetReactivationHistoryKeyPath().c_str(), | |
33 KEY_QUERY_VALUE); | |
34 if (reactivation_key.Valid()) { | |
35 std::vector<std::wstring>::const_iterator brand_iter(brand_codes.begin()); | |
36 for (; brand_iter != brand_codes.end(); ++brand_iter) { | |
37 if (reactivation_key.HasValue(brand_iter->c_str())) { | |
38 success = true; | |
Roger Tawa OOO till Jul 10th
2012/01/29 16:32:42
no need for local var if you return true here and
robertshield
2012/01/30 02:40:39
True, but that can cause more code to be generated
| |
39 break; | |
40 } | |
41 } | |
42 } | |
43 | |
44 return success; | |
45 } | |
46 | |
47 bool SetReactivationBrandCode(const std::wstring& brand_code) { | |
48 bool success = false; | |
49 | |
50 std::wstring path(google_update::kRegPathClientState); | |
51 path += L"\\"; | |
52 path += google_update::kChromeUpgradeCode; | |
53 | |
54 RegKey client_state_key(HKEY_CURRENT_USER, path.c_str(), KEY_SET_VALUE); | |
55 if (client_state_key.Valid()) { | |
56 success = client_state_key.WriteValue( | |
57 google_update::kRegRLZReactivationBrandField, | |
58 brand_code.c_str()) == ERROR_SUCCESS; | |
59 } | |
60 | |
61 if (success) { | |
62 // Store this brand code in the reactivation history. Store it with a | |
63 // a currently un-used timestamp for future proofing. | |
64 RegKey reactivation_key(HKEY_CURRENT_USER, | |
65 GetReactivationHistoryKeyPath().c_str(), | |
66 KEY_WRITE); | |
67 if (reactivation_key.Valid()) { | |
68 int64 timestamp = Time::Now().ToInternalValue(); | |
69 reactivation_key.WriteValue(brand_code.c_str(), | |
70 ×tamp, | |
71 sizeof(timestamp), | |
72 REG_QWORD); | |
73 } | |
74 } | |
75 | |
76 return success; | |
77 } | |
OLD | NEW |