| 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.h" | 7 #include "base/time.h" |
| 8 #include "base/win/registry.h" | 8 #include "base/win/registry.h" |
| 9 #include "chrome/installer/util/google_update_constants.h" | 9 #include "chrome/installer/util/google_update_constants.h" |
| 10 #include "chrome/installer/gcapi/gcapi.h" |
| 10 | 11 |
| 11 using base::Time; | 12 using base::Time; |
| 12 using base::win::RegKey; | 13 using base::win::RegKey; |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 const wchar_t kReactivationHistoryKey[] = L"reactivation"; | 16 const wchar_t kReactivationHistoryKey[] = L"reactivation"; |
| 16 | 17 |
| 17 std::wstring GetReactivationHistoryKeyPath() { | 18 std::wstring GetReactivationHistoryKeyPath() { |
| 18 std::wstring reactivation_path(google_update::kRegPathClientState); | 19 std::wstring reactivation_path(google_update::kRegPathClientState); |
| 19 reactivation_path += L"\\"; | 20 reactivation_path += L"\\"; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 37 if (reactivation_key.HasValue(brand_iter->c_str())) { | 38 if (reactivation_key.HasValue(brand_iter->c_str())) { |
| 38 success = true; | 39 success = true; |
| 39 break; | 40 break; |
| 40 } | 41 } |
| 41 } | 42 } |
| 42 } | 43 } |
| 43 | 44 |
| 44 return success; | 45 return success; |
| 45 } | 46 } |
| 46 | 47 |
| 47 bool SetReactivationBrandCode(const std::wstring& brand_code) { | 48 bool SetReactivationBrandCode(const std::wstring& brand_code, int shell_mode) { |
| 48 bool success = false; | 49 bool success = false; |
| 49 | 50 |
| 51 // This function currently only should be run in a non-elevated shell, |
| 52 // so we return "true" if it is being invoked from an elevated shell. |
| 53 if (shell_mode == GCAPI_INVOKED_UAC_ELEVATION) |
| 54 return true; |
| 55 |
| 50 std::wstring path(google_update::kRegPathClientState); | 56 std::wstring path(google_update::kRegPathClientState); |
| 51 path += L"\\"; | 57 path += L"\\"; |
| 52 path += google_update::kChromeUpgradeCode; | 58 path += google_update::kChromeUpgradeCode; |
| 53 | 59 |
| 54 RegKey client_state_key(HKEY_CURRENT_USER, path.c_str(), KEY_SET_VALUE); | 60 RegKey client_state_key(HKEY_CURRENT_USER, path.c_str(), KEY_SET_VALUE); |
| 55 if (client_state_key.Valid()) { | 61 if (client_state_key.Valid()) { |
| 56 success = client_state_key.WriteValue( | 62 success = client_state_key.WriteValue( |
| 57 google_update::kRegRLZReactivationBrandField, | 63 google_update::kRegRLZReactivationBrandField, |
| 58 brand_code.c_str()) == ERROR_SUCCESS; | 64 brand_code.c_str()) == ERROR_SUCCESS; |
| 59 } | 65 } |
| 60 | 66 |
| 61 if (success) { | 67 if (success) { |
| 62 // Store this brand code in the reactivation history. Store it with a | 68 // Store this brand code in the reactivation history. Store it with a |
| 63 // a currently un-used timestamp for future proofing. | 69 // a currently un-used timestamp for future proofing. |
| 64 RegKey reactivation_key(HKEY_CURRENT_USER, | 70 RegKey reactivation_key(HKEY_CURRENT_USER, |
| 65 GetReactivationHistoryKeyPath().c_str(), | 71 GetReactivationHistoryKeyPath().c_str(), |
| 66 KEY_WRITE); | 72 KEY_WRITE); |
| 67 if (reactivation_key.Valid()) { | 73 if (reactivation_key.Valid()) { |
| 68 int64 timestamp = Time::Now().ToInternalValue(); | 74 int64 timestamp = Time::Now().ToInternalValue(); |
| 69 reactivation_key.WriteValue(brand_code.c_str(), | 75 reactivation_key.WriteValue(brand_code.c_str(), |
| 70 ×tamp, | 76 ×tamp, |
| 71 sizeof(timestamp), | 77 sizeof(timestamp), |
| 72 REG_QWORD); | 78 REG_QWORD); |
| 73 } | 79 } |
| 74 } | 80 } |
| 75 | 81 |
| 76 return success; | 82 return success; |
| 77 } | 83 } |
| OLD | NEW |