| 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 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 } | 549 } |
| 550 | 550 |
| 551 if (days_since_last_run == std::numeric_limits<int>::max()) { | 551 if (days_since_last_run == std::numeric_limits<int>::max()) { |
| 552 days_since_last_run = -1; | 552 days_since_last_run = -1; |
| 553 } | 553 } |
| 554 | 554 |
| 555 return days_since_last_run; | 555 return days_since_last_run; |
| 556 } | 556 } |
| 557 | 557 |
| 558 BOOL __stdcall CanOfferReactivation(const wchar_t* brand_code, | 558 BOOL __stdcall CanOfferReactivation(const wchar_t* brand_code, |
| 559 int previous_brand_codes_length, | |
| 560 const wchar_t** previous_brand_codes, | |
| 561 int shell_mode, | 559 int shell_mode, |
| 562 DWORD* error_code) { | 560 DWORD* error_code) { |
| 563 DCHECK(error_code); | 561 DCHECK(error_code); |
| 564 | 562 |
| 565 if (!brand_code || | 563 if (!brand_code) { |
| 566 (previous_brand_codes_length > 0 && previous_brand_codes == NULL)) { | |
| 567 if (error_code) | 564 if (error_code) |
| 568 *error_code = REACTIVATE_ERROR_INVALID_INPUT; | 565 *error_code = REACTIVATE_ERROR_INVALID_INPUT; |
| 569 return FALSE; | 566 return FALSE; |
| 570 } | 567 } |
| 571 | 568 |
| 572 bool has_system_install = IsChromeInstalled(HKEY_LOCAL_MACHINE); | |
| 573 bool has_user_install = IsChromeInstalled(HKEY_CURRENT_USER); | |
| 574 | |
| 575 if (!has_system_install && !has_user_install) { | |
| 576 if (error_code) | |
| 577 *error_code = REACTIVATE_ERROR_NOTINSTALLED; | |
| 578 return FALSE; | |
| 579 } | |
| 580 | |
| 581 int days_since_last_run = GoogleChromeDaysSinceLastRun(); | 569 int days_since_last_run = GoogleChromeDaysSinceLastRun(); |
| 582 if (days_since_last_run >= 0 && | 570 if (days_since_last_run >= 0 && |
| 583 days_since_last_run < kReactivationMinDaysDormant) { | 571 days_since_last_run < kReactivationMinDaysDormant) { |
| 584 if (error_code) | 572 if (error_code) |
| 585 *error_code = REACTIVATE_ERROR_NOTDORMANT; | 573 *error_code = REACTIVATE_ERROR_NOTDORMANT; |
| 586 return FALSE; | 574 return FALSE; |
| 587 } | 575 } |
| 588 | 576 |
| 589 // Make sure we haven't previously been reactivated by this brand code | 577 // Only run the code below when this function is invoked from a standard, |
| 590 // or any of the previous brand codes from this partner. | 578 // non-elevated cmd shell. This is because this section of code looks at |
| 591 // Since this function is invoked by ReactivateChrome, and since | 579 // values in HKEY_CURRENT_USER, and we only want to look at the logged-in |
| 592 // ReactivateChrome is called first in non-elevated shell and | 580 // user's HKCU, not the admin user's HKCU. |
| 593 // second in UAC-elevated shell, we only want to execute this block | |
| 594 // of code the first time, in non-elevated mode. | |
| 595 if (shell_mode == GCAPI_INVOKED_STANDARD_SHELL) { | 581 if (shell_mode == GCAPI_INVOKED_STANDARD_SHELL) { |
| 596 std::vector<std::wstring> reactivation_brands; | 582 |
| 597 reactivation_brands.push_back(brand_code); | 583 if (!IsChromeInstalled(HKEY_LOCAL_MACHINE) && |
| 598 if (previous_brand_codes_length > 0 && previous_brand_codes != NULL) { | 584 !IsChromeInstalled(HKEY_CURRENT_USER)) { |
| 599 std::copy(previous_brand_codes, | 585 if (error_code) |
| 600 previous_brand_codes + previous_brand_codes_length, | 586 *error_code = REACTIVATE_ERROR_NOTINSTALLED; |
| 601 std::back_inserter(reactivation_brands)); | 587 return FALSE; |
| 602 } | 588 } |
| 603 if (HasBeenReactivatedByBrandCodes(reactivation_brands)) { | 589 |
| 590 if (HasBeenReactivated()) { |
| 604 if (error_code) | 591 if (error_code) |
| 605 *error_code = REACTIVATE_ERROR_ALREADY_REACTIVATED; | 592 *error_code = REACTIVATE_ERROR_ALREADY_REACTIVATED; |
| 606 return FALSE; | 593 return FALSE; |
| 607 } | 594 } |
| 608 } | 595 } |
| 609 | 596 |
| 610 return TRUE; | 597 return TRUE; |
| 611 } | 598 } |
| 612 | 599 |
| 613 BOOL __stdcall ReactivateChrome(wchar_t* brand_code, | 600 BOOL __stdcall ReactivateChrome(wchar_t* brand_code, |
| 614 int previous_brand_codes_length, | |
| 615 const wchar_t** previous_brand_codes, | |
| 616 int shell_mode, | 601 int shell_mode, |
| 617 DWORD* error_code) { | 602 DWORD* error_code) { |
| 618 BOOL result = FALSE; | 603 BOOL result = FALSE; |
| 619 if (CanOfferReactivation(brand_code, | 604 if (CanOfferReactivation(brand_code, |
| 620 previous_brand_codes_length, | |
| 621 previous_brand_codes, | |
| 622 shell_mode, | 605 shell_mode, |
| 623 error_code)) { | 606 error_code)) { |
| 624 if (SetReactivationBrandCode(brand_code, shell_mode)) { | 607 if (SetReactivationBrandCode(brand_code, shell_mode)) { |
| 625 // Currently set this as a best-effort thing. We return TRUE if | 608 // Currently set this as a best-effort thing. We return TRUE if |
| 626 // reactivation succeeded regardless of the experiment label result. | 609 // reactivation succeeded regardless of the experiment label result. |
| 627 SetOmahaExperimentLabel(brand_code, shell_mode); | 610 SetOmahaExperimentLabel(brand_code, shell_mode); |
| 628 | 611 |
| 629 result = TRUE; | 612 result = TRUE; |
| 630 } else { | 613 } else { |
| 631 if (error_code) | 614 if (error_code) |
| 632 *error_code = REACTIVATE_ERROR_REACTIVATION_FAILED; | 615 *error_code = REACTIVATE_ERROR_REACTIVATION_FAILED; |
| 633 } | 616 } |
| 634 } | 617 } |
| 635 | 618 |
| 636 return result; | 619 return result; |
| 637 } | 620 } |
| 638 | 621 |
| OLD | NEW |