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 // NOTE: This code is a legacy utility API for partners to check whether | 5 // NOTE: This code is a legacy utility API for partners to check whether |
6 // Chrome can be installed and launched. Recent updates are being made | 6 // Chrome can be installed and launched. Recent updates are being made |
7 // to add new functionality. These updates use code from Chromium, the old | 7 // to add new functionality. These updates use code from Chromium, the old |
8 // coded against the win32 api directly. If you have an itch to shave a | 8 // coded against the win32 api directly. If you have an itch to shave a |
9 // yak, feel free to re-write the old code too. | 9 // yak, feel free to re-write the old code too. |
10 | 10 |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 } | 196 } |
197 | 197 |
198 ::RegCloseKey(key); | 198 ::RegCloseKey(key); |
199 } | 199 } |
200 | 200 |
201 return can_re_offer; | 201 return can_re_offer; |
202 } | 202 } |
203 | 203 |
204 bool IsChromeInstalled(HKEY root_key) { | 204 bool IsChromeInstalled(HKEY root_key) { |
205 RegKey key; | 205 RegKey key; |
206 return key.Open(root_key, kChromeRegClientsKey, KEY_READ) == ERROR_SUCCESS && | 206 return key.Open(root_key, |
| 207 kChromeRegClientsKey, |
| 208 KEY_READ | KEY_WOW64_32KEY) == ERROR_SUCCESS && |
207 key.HasValue(kChromeRegVersion); | 209 key.HasValue(kChromeRegVersion); |
208 } | 210 } |
209 | 211 |
210 // Returns true if the |subkey| in |root| has the kC1FKey entry set to 1. | 212 // Returns true if the |subkey| in |root| has the kC1FKey entry set to 1. |
211 bool RegKeyHasC1F(HKEY root, const wchar_t* subkey) { | 213 bool RegKeyHasC1F(HKEY root, const wchar_t* subkey) { |
212 RegKey key; | 214 RegKey key; |
213 DWORD value; | 215 DWORD value; |
214 return key.Open(root, subkey, KEY_READ) == ERROR_SUCCESS && | 216 return key.Open(root, subkey, KEY_READ | KEY_WOW64_32KEY) == ERROR_SUCCESS && |
215 key.ReadValueDW(kC1FKey, &value) == ERROR_SUCCESS && | 217 key.ReadValueDW(kC1FKey, &value) == ERROR_SUCCESS && |
216 value == static_cast<DWORD>(1); | 218 value == static_cast<DWORD>(1); |
217 } | 219 } |
218 | 220 |
219 bool IsC1FSent() { | 221 bool IsC1FSent() { |
220 // The C1F RLZ key can either be in HKCU or in HKLM (the HKLM RLZ key is made | 222 // The C1F RLZ key can either be in HKCU or in HKLM (the HKLM RLZ key is made |
221 // readable to all-users via rlz_lib::CreateMachineState()) and can either be | 223 // readable to all-users via rlz_lib::CreateMachineState()) and can either be |
222 // in sent or pending state. Return true if there is a match for any of these | 224 // in sent or pending state. Return true if there is a match for any of these |
223 // 4 states. | 225 // 4 states. |
224 return RegKeyHasC1F(HKEY_CURRENT_USER, kC1FSentKey) || | 226 return RegKeyHasC1F(HKEY_CURRENT_USER, kC1FSentKey) || |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 return (check == TRUE); | 271 return (check == TRUE); |
270 } | 272 } |
271 | 273 |
272 bool VerifyHKLMAccess() { | 274 bool VerifyHKLMAccess() { |
273 wchar_t str[] = L"test"; | 275 wchar_t str[] = L"test"; |
274 bool result = false; | 276 bool result = false; |
275 DWORD disposition = 0; | 277 DWORD disposition = 0; |
276 HKEY key = NULL; | 278 HKEY key = NULL; |
277 | 279 |
278 if (::RegCreateKeyEx(HKEY_LOCAL_MACHINE, kGCAPITempKey, 0, NULL, | 280 if (::RegCreateKeyEx(HKEY_LOCAL_MACHINE, kGCAPITempKey, 0, NULL, |
279 REG_OPTION_NON_VOLATILE, KEY_READ | KEY_WRITE, NULL, | 281 REG_OPTION_NON_VOLATILE, |
| 282 KEY_READ | KEY_WRITE | KEY_WOW64_32KEY, NULL, |
280 &key, &disposition) == ERROR_SUCCESS) { | 283 &key, &disposition) == ERROR_SUCCESS) { |
281 if (::RegSetValueEx(key, str, 0, REG_SZ, (LPBYTE)str, | 284 if (::RegSetValueEx(key, str, 0, REG_SZ, (LPBYTE)str, |
282 (DWORD)lstrlen(str)) == ERROR_SUCCESS) { | 285 (DWORD)lstrlen(str)) == ERROR_SUCCESS) { |
283 result = true; | 286 result = true; |
284 RegDeleteValue(key, str); | 287 RegDeleteValue(key, str); |
285 } | 288 } |
286 | 289 |
287 RegCloseKey(key); | 290 RegCloseKey(key); |
288 | 291 |
289 // If we create the main key, delete the entire key. | 292 // If we create the main key, delete the entire key. |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 | 591 |
589 BOOL __stdcall LaunchGoogleChromeInBackground() { | 592 BOOL __stdcall LaunchGoogleChromeInBackground() { |
590 return LaunchGoogleChromeWithDimensions(-1, -1, -1, -1, true); | 593 return LaunchGoogleChromeWithDimensions(-1, -1, -1, -1, true); |
591 } | 594 } |
592 | 595 |
593 int __stdcall GoogleChromeDaysSinceLastRun() { | 596 int __stdcall GoogleChromeDaysSinceLastRun() { |
594 int days_since_last_run = std::numeric_limits<int>::max(); | 597 int days_since_last_run = std::numeric_limits<int>::max(); |
595 | 598 |
596 if (IsChromeInstalled(HKEY_LOCAL_MACHINE) || | 599 if (IsChromeInstalled(HKEY_LOCAL_MACHINE) || |
597 IsChromeInstalled(HKEY_CURRENT_USER)) { | 600 IsChromeInstalled(HKEY_CURRENT_USER)) { |
598 RegKey client_state( | 601 RegKey client_state(HKEY_CURRENT_USER, |
599 HKEY_CURRENT_USER, kChromeRegClientStateKey, KEY_QUERY_VALUE); | 602 kChromeRegClientStateKey, |
| 603 KEY_QUERY_VALUE | KEY_WOW64_32KEY); |
600 if (client_state.Valid()) { | 604 if (client_state.Valid()) { |
601 std::wstring last_run; | 605 std::wstring last_run; |
602 int64 last_run_value = 0; | 606 int64 last_run_value = 0; |
603 if (client_state.ReadValue(google_update::kRegLastRunTimeField, | 607 if (client_state.ReadValue(google_update::kRegLastRunTimeField, |
604 &last_run) == ERROR_SUCCESS && | 608 &last_run) == ERROR_SUCCESS && |
605 base::StringToInt64(last_run, &last_run_value)) { | 609 base::StringToInt64(last_run, &last_run_value)) { |
606 Time last_run_time = Time::FromInternalValue(last_run_value); | 610 Time last_run_time = Time::FromInternalValue(last_run_value); |
607 TimeDelta difference = Time::NowFromSystemTime() - last_run_time; | 611 TimeDelta difference = Time::NowFromSystemTime() - last_run_time; |
608 | 612 |
609 // We can end up with negative numbers here, given changes in system | 613 // We can end up with negative numbers here, given changes in system |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
741 days_since_last_run < kRelaunchMinDaysDormant) { | 745 days_since_last_run < kRelaunchMinDaysDormant) { |
742 if (error_code) | 746 if (error_code) |
743 *error_code = RELAUNCH_ERROR_NOTDORMANT; | 747 *error_code = RELAUNCH_ERROR_NOTDORMANT; |
744 return FALSE; | 748 return FALSE; |
745 } | 749 } |
746 | 750 |
747 // e) a minimum period (6 months) must have passed since the previous | 751 // e) a minimum period (6 months) must have passed since the previous |
748 // relaunch offer for the current user; | 752 // relaunch offer for the current user; |
749 RegKey key; | 753 RegKey key; |
750 DWORD min_relaunch_date; | 754 DWORD min_relaunch_date; |
751 if (key.Open(HKEY_CURRENT_USER, kChromeRegClientStateKey, | 755 if (key.Open(HKEY_CURRENT_USER, |
752 KEY_QUERY_VALUE) == ERROR_SUCCESS && | 756 kChromeRegClientStateKey, |
| 757 KEY_QUERY_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS && |
753 key.ReadValueDW(kRelaunchAllowedAfterValue, | 758 key.ReadValueDW(kRelaunchAllowedAfterValue, |
754 &min_relaunch_date) == ERROR_SUCCESS && | 759 &min_relaunch_date) == ERROR_SUCCESS && |
755 FormatDateOffsetByMonths(0) < min_relaunch_date) { | 760 FormatDateOffsetByMonths(0) < min_relaunch_date) { |
756 if (error_code) | 761 if (error_code) |
757 *error_code = RELAUNCH_ERROR_ALREADY_RELAUNCHED; | 762 *error_code = RELAUNCH_ERROR_ALREADY_RELAUNCHED; |
758 return FALSE; | 763 return FALSE; |
759 } | 764 } |
760 | 765 |
761 return TRUE; | 766 return TRUE; |
762 } | 767 } |
763 | 768 |
764 BOOL __stdcall SetRelaunchOffered(const wchar_t** partner_brandcode_list, | 769 BOOL __stdcall SetRelaunchOffered(const wchar_t** partner_brandcode_list, |
765 int partner_brandcode_list_length, | 770 int partner_brandcode_list_length, |
766 const wchar_t* relaunch_brandcode, | 771 const wchar_t* relaunch_brandcode, |
767 int shell_mode, | 772 int shell_mode, |
768 DWORD* error_code) { | 773 DWORD* error_code) { |
769 if (!CanOfferRelaunch(partner_brandcode_list, partner_brandcode_list_length, | 774 if (!CanOfferRelaunch(partner_brandcode_list, partner_brandcode_list_length, |
770 shell_mode, error_code)) | 775 shell_mode, error_code)) |
771 return FALSE; | 776 return FALSE; |
772 | 777 |
773 // Store the relaunched brand code and the minimum date for relaunch (6 months | 778 // Store the relaunched brand code and the minimum date for relaunch (6 months |
774 // from now), and set the Omaha experiment label. | 779 // from now), and set the Omaha experiment label. |
775 RegKey key; | 780 RegKey key; |
776 if (key.Create(HKEY_CURRENT_USER, kChromeRegClientStateKey, | 781 if (key.Create(HKEY_CURRENT_USER, |
777 KEY_SET_VALUE) != ERROR_SUCCESS || | 782 kChromeRegClientStateKey, |
| 783 KEY_SET_VALUE | KEY_WOW64_32KEY) != ERROR_SUCCESS || |
778 key.WriteValue(kRelaunchBrandcodeValue, | 784 key.WriteValue(kRelaunchBrandcodeValue, |
779 relaunch_brandcode) != ERROR_SUCCESS || | 785 relaunch_brandcode) != ERROR_SUCCESS || |
780 key.WriteValue(kRelaunchAllowedAfterValue, | 786 key.WriteValue(kRelaunchAllowedAfterValue, |
781 FormatDateOffsetByMonths(6)) != ERROR_SUCCESS || | 787 FormatDateOffsetByMonths(6)) != ERROR_SUCCESS || |
782 !SetRelaunchExperimentLabels(relaunch_brandcode, shell_mode)) { | 788 !SetRelaunchExperimentLabels(relaunch_brandcode, shell_mode)) { |
783 if (error_code) | 789 if (error_code) |
784 *error_code = RELAUNCH_ERROR_RELAUNCH_FAILED; | 790 *error_code = RELAUNCH_ERROR_RELAUNCH_FAILED; |
785 return FALSE; | 791 return FALSE; |
786 } | 792 } |
787 | 793 |
788 return TRUE; | 794 return TRUE; |
789 } | 795 } |
OLD | NEW |