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 11 matching lines...) Expand all Loading... |
22 | 22 |
23 #include "base/basictypes.h" | 23 #include "base/basictypes.h" |
24 #include "base/file_path.h" | 24 #include "base/file_path.h" |
25 #include "base/file_util.h" | 25 #include "base/file_util.h" |
26 #include "base/string_number_conversions.h" | 26 #include "base/string_number_conversions.h" |
27 #include "base/time.h" | 27 #include "base/time.h" |
28 #include "base/win/registry.h" | 28 #include "base/win/registry.h" |
29 #include "base/win/scoped_com_initializer.h" | 29 #include "base/win/scoped_com_initializer.h" |
30 #include "base/win/scoped_comptr.h" | 30 #include "base/win/scoped_comptr.h" |
31 #include "base/win/scoped_handle.h" | 31 #include "base/win/scoped_handle.h" |
| 32 #include "chrome/installer/gcapi/gcapi_reactivation.h" |
32 #include "chrome/installer/util/google_update_constants.h" | 33 #include "chrome/installer/util/google_update_constants.h" |
33 #include "chrome/installer/util/util_constants.h" | 34 #include "chrome/installer/util/util_constants.h" |
34 | 35 |
35 #include "google_update_idl.h" // NOLINT | 36 #include "google_update_idl.h" // NOLINT |
36 | 37 |
37 using base::Time; | 38 using base::Time; |
38 using base::TimeDelta; | 39 using base::TimeDelta; |
39 using base::win::RegKey; | 40 using base::win::RegKey; |
40 using base::win::ScopedCOMInitializer; | 41 using base::win::ScopedCOMInitializer; |
41 using base::win::ScopedComPtr; | 42 using base::win::ScopedComPtr; |
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 } | 533 } |
533 } | 534 } |
534 } | 535 } |
535 | 536 |
536 if (days_since_last_run == std::numeric_limits<int>::max()) { | 537 if (days_since_last_run == std::numeric_limits<int>::max()) { |
537 days_since_last_run = -1; | 538 days_since_last_run = -1; |
538 } | 539 } |
539 | 540 |
540 return days_since_last_run; | 541 return days_since_last_run; |
541 } | 542 } |
| 543 |
| 544 BOOL __stdcall CanOfferReactivation(const wchar_t* brand_code, |
| 545 int previous_brand_codes_length, |
| 546 const wchar_t** previous_brand_codes, |
| 547 DWORD* error_code) { |
| 548 DCHECK(error_code); |
| 549 |
| 550 if (!brand_code || |
| 551 (previous_brand_codes_length > 0 && previous_brand_codes == NULL)) { |
| 552 if (error_code) |
| 553 *error_code = REACTIVATE_ERROR_INVALID_INPUT; |
| 554 return FALSE; |
| 555 } |
| 556 |
| 557 bool has_system_install = IsChromeInstalled(HKEY_LOCAL_MACHINE); |
| 558 bool has_user_install = IsChromeInstalled(HKEY_CURRENT_USER); |
| 559 |
| 560 if (!has_system_install && !has_user_install) { |
| 561 if (error_code) |
| 562 *error_code = REACTIVATE_ERROR_NOTINSTALLED; |
| 563 return FALSE; |
| 564 } |
| 565 |
| 566 int days_since_last_run = GoogleChromeDaysSinceLastRun(); |
| 567 if (days_since_last_run > 0 && |
| 568 days_since_last_run < kReactivationMinDaysDormant) { |
| 569 if (error_code) |
| 570 *error_code = REACTIVATE_ERROR_NOTDORMANT; |
| 571 return FALSE; |
| 572 } |
| 573 |
| 574 // Make sure we haven't previously been reactivated by this brand code |
| 575 // or any of the previous brand codes from this partner. |
| 576 std::vector<std::wstring> reactivation_brands; |
| 577 reactivation_brands.push_back(brand_code); |
| 578 if (previous_brand_codes_length > 0 && previous_brand_codes != NULL) { |
| 579 std::copy(previous_brand_codes, |
| 580 previous_brand_codes + previous_brand_codes_length, |
| 581 std::back_inserter(reactivation_brands)); |
| 582 } |
| 583 if (HasBeenReactivatedByBrandCodes(reactivation_brands)) { |
| 584 if (error_code) |
| 585 *error_code = REACTIVATE_ERROR_ALREADY_REACTIVATED; |
| 586 return FALSE; |
| 587 } |
| 588 |
| 589 return TRUE; |
| 590 } |
| 591 |
| 592 BOOL __stdcall ReactivateChrome(wchar_t* brand_code, |
| 593 int previous_brand_codes_length, |
| 594 const wchar_t** previous_brand_codes, |
| 595 DWORD* error_code) { |
| 596 BOOL result = FALSE; |
| 597 if (CanOfferReactivation(brand_code, |
| 598 previous_brand_codes_length, |
| 599 previous_brand_codes, |
| 600 error_code)) { |
| 601 if (SetReactivationBrandCode(brand_code)) { |
| 602 // TODO(robertshield): Set Omaha reg key to add experiment label for |
| 603 // tracking 7DA. |
| 604 result = TRUE; |
| 605 } else { |
| 606 if (error_code) |
| 607 *error_code = REACTIVATE_ERROR_REACTIVATION_FAILED; |
| 608 } |
| 609 } |
| 610 |
| 611 return result; |
| 612 } |
| 613 |
OLD | NEW |