Chromium Code Reviews| 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 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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, | 559 int previous_brand_codes_length, |
| 560 const wchar_t** previous_brand_codes, | 560 const wchar_t** previous_brand_codes, |
| 561 int shell_mode, | 561 int shell_mode, |
| 562 DWORD* error_code) { | 562 DWORD* error_code) { |
| 563 DCHECK(error_code); | 563 DCHECK(error_code); |
| 564 | 564 |
| 565 // If this function is invoked in elevated mode, always return TRUE. | |
| 566 // We only really care what this function returns when it is invoked | |
| 567 // in non-elevated mode. We return TRUE in elevated mode because we | |
| 568 // want this function to return TRUE when ReactivateChrome is invoked | |
| 569 // in elevated mode. | |
| 570 if (shell_mode == GCAPI_INVOKED_UAC_ELEVATION) | |
|
robertshield
2012/03/15 03:52:32
If a partner mistakenly invokes this method while
mgraboski
2012/03/22 00:33:25
Rather than always returning true, I've modified t
robertshield
2012/03/23 17:52:16
Looks good!
| |
| 571 return TRUE; | |
| 572 | |
| 565 if (!brand_code || | 573 if (!brand_code || |
| 566 (previous_brand_codes_length > 0 && previous_brand_codes == NULL)) { | 574 (previous_brand_codes_length > 0 && previous_brand_codes == NULL)) { |
| 567 if (error_code) | 575 if (error_code) |
| 568 *error_code = REACTIVATE_ERROR_INVALID_INPUT; | 576 *error_code = REACTIVATE_ERROR_INVALID_INPUT; |
| 569 return FALSE; | 577 return FALSE; |
| 570 } | 578 } |
| 571 | 579 |
| 572 bool has_system_install = IsChromeInstalled(HKEY_LOCAL_MACHINE); | 580 bool has_system_install = IsChromeInstalled(HKEY_LOCAL_MACHINE); |
| 573 bool has_user_install = IsChromeInstalled(HKEY_CURRENT_USER); | 581 bool has_user_install = IsChromeInstalled(HKEY_CURRENT_USER); |
| 574 | 582 |
| 575 if (!has_system_install && !has_user_install) { | 583 if (!has_system_install && !has_user_install) { |
| 576 if (error_code) | 584 if (error_code) |
| 577 *error_code = REACTIVATE_ERROR_NOTINSTALLED; | 585 *error_code = REACTIVATE_ERROR_NOTINSTALLED; |
| 578 return FALSE; | 586 return FALSE; |
| 579 } | 587 } |
| 580 | 588 |
| 581 int days_since_last_run = GoogleChromeDaysSinceLastRun(); | 589 int days_since_last_run = GoogleChromeDaysSinceLastRun(); |
| 582 if (days_since_last_run >= 0 && | 590 if (days_since_last_run >= 0 && |
| 583 days_since_last_run < kReactivationMinDaysDormant) { | 591 days_since_last_run < kReactivationMinDaysDormant) { |
| 584 if (error_code) | 592 if (error_code) |
| 585 *error_code = REACTIVATE_ERROR_NOTDORMANT; | 593 *error_code = REACTIVATE_ERROR_NOTDORMANT; |
| 586 return FALSE; | 594 return FALSE; |
| 587 } | 595 } |
| 588 | 596 |
| 589 // Make sure we haven't previously been reactivated by this brand code | 597 std::vector<std::wstring> reactivation_brands; |
| 590 // or any of the previous brand codes from this partner. | 598 reactivation_brands.push_back(brand_code); |
| 591 // Since this function is invoked by ReactivateChrome, and since | 599 if (previous_brand_codes_length > 0 && previous_brand_codes != NULL) { |
| 592 // ReactivateChrome is called first in non-elevated shell and | 600 std::copy(previous_brand_codes, |
| 593 // second in UAC-elevated shell, we only want to execute this block | 601 previous_brand_codes + previous_brand_codes_length, |
| 594 // of code the first time, in non-elevated mode. | 602 std::back_inserter(reactivation_brands)); |
| 595 if (shell_mode == GCAPI_INVOKED_STANDARD_SHELL) { | 603 } |
| 596 std::vector<std::wstring> reactivation_brands; | 604 if (HasBeenReactivatedByBrandCodes(reactivation_brands)) { |
| 597 reactivation_brands.push_back(brand_code); | 605 if (error_code) |
| 598 if (previous_brand_codes_length > 0 && previous_brand_codes != NULL) { | 606 *error_code = REACTIVATE_ERROR_ALREADY_REACTIVATED; |
| 599 std::copy(previous_brand_codes, | 607 return FALSE; |
| 600 previous_brand_codes + previous_brand_codes_length, | |
| 601 std::back_inserter(reactivation_brands)); | |
| 602 } | |
| 603 if (HasBeenReactivatedByBrandCodes(reactivation_brands)) { | |
| 604 if (error_code) | |
| 605 *error_code = REACTIVATE_ERROR_ALREADY_REACTIVATED; | |
| 606 return FALSE; | |
| 607 } | |
| 608 } | 608 } |
| 609 | 609 |
| 610 return TRUE; | 610 return TRUE; |
| 611 } | 611 } |
| 612 | 612 |
| 613 BOOL __stdcall ReactivateChrome(wchar_t* brand_code, | 613 BOOL __stdcall ReactivateChrome(wchar_t* brand_code, |
| 614 int previous_brand_codes_length, | 614 int previous_brand_codes_length, |
| 615 const wchar_t** previous_brand_codes, | 615 const wchar_t** previous_brand_codes, |
| 616 int shell_mode, | 616 int shell_mode, |
| 617 DWORD* error_code) { | 617 DWORD* error_code) { |
|
robertshield
2012/03/15 03:52:32
If we are short-circuiting CanOfferReactivation wh
mgraboski
2012/03/22 00:33:25
We need to run this function in non-elevated mode,
| |
| 618 BOOL result = FALSE; | 618 BOOL result = FALSE; |
| 619 if (CanOfferReactivation(brand_code, | 619 if (CanOfferReactivation(brand_code, |
| 620 previous_brand_codes_length, | 620 previous_brand_codes_length, |
| 621 previous_brand_codes, | 621 previous_brand_codes, |
| 622 shell_mode, | 622 shell_mode, |
| 623 error_code)) { | 623 error_code)) { |
| 624 if (SetReactivationBrandCode(brand_code, shell_mode)) { | 624 if (SetReactivationBrandCode(brand_code, shell_mode)) { |
| 625 // Currently set this as a best-effort thing. We return TRUE if | 625 // Currently set this as a best-effort thing. We return TRUE if |
| 626 // reactivation succeeded regardless of the experiment label result. | 626 // reactivation succeeded regardless of the experiment label result. |
| 627 SetOmahaExperimentLabel(brand_code, shell_mode); | 627 SetOmahaExperimentLabel(brand_code, shell_mode); |
| 628 | 628 |
| 629 result = TRUE; | 629 result = TRUE; |
| 630 } else { | 630 } else { |
| 631 if (error_code) | 631 if (error_code) |
| 632 *error_code = REACTIVATE_ERROR_REACTIVATION_FAILED; | 632 *error_code = REACTIVATE_ERROR_REACTIVATION_FAILED; |
| 633 } | 633 } |
| 634 } | 634 } |
| 635 | 635 |
| 636 return result; | 636 return result; |
| 637 } | 637 } |
| 638 | 638 |
| OLD | NEW |