Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(654)

Side by Side Diff: chrome/installer/gcapi/gcapi.cc

Issue 9465013: Mike's change. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removing unneeded line breaks. Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 15 matching lines...) Expand all
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_omaha_experiment.h" 32 #include "chrome/installer/gcapi/gcapi_omaha_experiment.h"
33 #include "chrome/installer/gcapi/gcapi_reactivation.h" 33 #include "chrome/installer/gcapi/gcapi_reactivation.h"
34 #include "chrome/installer/util/google_update_constants.h" 34 #include "chrome/installer/util/google_update_constants.h"
35 #include "chrome/installer/util/util_constants.h" 35 #include "chrome/installer/util/util_constants.h"
36 #include "google_update/google_update_idl.h" 36
Roger Tawa OOO till Jul 10th 2012/02/24 21:46:59 why extra space?
robertshield 2012/02/24 22:21:40 Done.
37 #include "google_update/google_update_idl.h" // NOLINT
37 38
38 using base::Time; 39 using base::Time;
39 using base::TimeDelta; 40 using base::TimeDelta;
40 using base::win::RegKey; 41 using base::win::RegKey;
41 using base::win::ScopedCOMInitializer; 42 using base::win::ScopedCOMInitializer;
42 using base::win::ScopedComPtr; 43 using base::win::ScopedComPtr;
43 using base::win::ScopedHandle; 44 using base::win::ScopedHandle;
44 45
45 namespace { 46 namespace {
46 47
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 } 313 }
313 delete[] token_user; 314 delete[] token_user;
314 } 315 }
315 ::CloseHandle(process_token); 316 ::CloseHandle(process_token);
316 } 317 }
317 ::CloseHandle(process_handle); 318 ::CloseHandle(process_handle);
318 return result; 319 return result;
319 } 320 }
320 } // namespace 321 } // namespace
321 322
322 BOOL __stdcall GoogleChromeCompatibilityCheck(BOOL set_flag, DWORD* reasons) { 323 BOOL __stdcall GoogleChromeCompatibilityCheck(BOOL set_flag,
324 int shell_mode,
325 DWORD* reasons) {
323 DWORD local_reasons = 0; 326 DWORD local_reasons = 0;
324 327
325 WindowsVersion windows_version = GetWindowsVersion(); 328 WindowsVersion windows_version = GetWindowsVersion();
326 // System requirements? 329 // System requirements?
327 if (windows_version == VERSION_BELOW_XP_SP2) 330 if (windows_version == VERSION_BELOW_XP_SP2)
328 local_reasons |= GCCC_ERROR_OSNOTSUPPORTED; 331 local_reasons |= GCCC_ERROR_OSNOTSUPPORTED;
329 332
330 if (IsChromeInstalled(HKEY_LOCAL_MACHINE)) 333 if (IsChromeInstalled(HKEY_LOCAL_MACHINE))
331 local_reasons |= GCCC_ERROR_SYSTEMLEVELALREADYPRESENT; 334 local_reasons |= GCCC_ERROR_SYSTEMLEVELALREADYPRESENT;
332 335
333 if (IsChromeInstalled(HKEY_CURRENT_USER)) 336 if (IsChromeInstalled(HKEY_CURRENT_USER))
334 local_reasons |= GCCC_ERROR_USERLEVELALREADYPRESENT; 337 local_reasons |= GCCC_ERROR_USERLEVELALREADYPRESENT;
335 338
336 if (!VerifyHKLMAccess()) { 339 if (shell_mode == GCAPI_INVOKED_UAC_ELEVATION) {
340 // Only check that we have HKLM write permissions if we specify that
341 // GCAPI is being invoked from an elevated shell, or in admin mode
342 if (!VerifyHKLMAccess()) {
337 local_reasons |= GCCC_ERROR_ACCESSDENIED; 343 local_reasons |= GCCC_ERROR_ACCESSDENIED;
338 } else if ((windows_version == VERSION_VISTA_OR_HIGHER) && 344 } else if ((windows_version == VERSION_VISTA_OR_HIGHER) &&
339 !VerifyAdminGroup()) { 345 !VerifyAdminGroup()) {
340 // For Vista or later check for elevation since even for admin user we could 346 // For Vista or later check for elevation since even for admin user we could
341 // be running in non-elevated mode. We require integrity level High. 347 // be running in non-elevated mode. We require integrity level High.
342 local_reasons |= GCCC_ERROR_INTEGRITYLEVEL; 348 local_reasons |= GCCC_ERROR_INTEGRITYLEVEL;
349 }
343 } 350 }
344 351
345 // Then only check whether we can re-offer, if everything else is OK. 352 // Then only check whether we can re-offer, if everything else is OK.
346 if (local_reasons == 0 && !CanReOfferChrome(set_flag)) 353 if (local_reasons == 0 && !CanReOfferChrome(set_flag))
347 local_reasons |= GCCC_ERROR_ALREADYOFFERED; 354 local_reasons |= GCCC_ERROR_ALREADYOFFERED;
348 355
349 // Done. Copy/return results. 356 // Done. Copy/return results.
350 if (reasons != NULL) 357 if (reasons != NULL)
351 *reasons = local_reasons; 358 *reasons = local_reasons;
352 359
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 if (days_since_last_run == std::numeric_limits<int>::max()) { 544 if (days_since_last_run == std::numeric_limits<int>::max()) {
538 days_since_last_run = -1; 545 days_since_last_run = -1;
539 } 546 }
540 547
541 return days_since_last_run; 548 return days_since_last_run;
542 } 549 }
543 550
544 BOOL __stdcall CanOfferReactivation(const wchar_t* brand_code, 551 BOOL __stdcall CanOfferReactivation(const wchar_t* brand_code,
545 int previous_brand_codes_length, 552 int previous_brand_codes_length,
546 const wchar_t** previous_brand_codes, 553 const wchar_t** previous_brand_codes,
554 int shell_mode,
547 DWORD* error_code) { 555 DWORD* error_code) {
548 DCHECK(error_code); 556 DCHECK(error_code);
549 557
550 if (!brand_code || 558 if (!brand_code ||
551 (previous_brand_codes_length > 0 && previous_brand_codes == NULL)) { 559 (previous_brand_codes_length > 0 && previous_brand_codes == NULL)) {
552 if (error_code) 560 if (error_code)
553 *error_code = REACTIVATE_ERROR_INVALID_INPUT; 561 *error_code = REACTIVATE_ERROR_INVALID_INPUT;
554 return FALSE; 562 return FALSE;
555 } 563 }
556 564
557 bool has_system_install = IsChromeInstalled(HKEY_LOCAL_MACHINE); 565 bool has_system_install = IsChromeInstalled(HKEY_LOCAL_MACHINE);
558 bool has_user_install = IsChromeInstalled(HKEY_CURRENT_USER); 566 bool has_user_install = IsChromeInstalled(HKEY_CURRENT_USER);
559 567
560 if (!has_system_install && !has_user_install) { 568 if (!has_system_install && !has_user_install) {
561 if (error_code) 569 if (error_code)
562 *error_code = REACTIVATE_ERROR_NOTINSTALLED; 570 *error_code = REACTIVATE_ERROR_NOTINSTALLED;
563 return FALSE; 571 return FALSE;
564 } 572 }
565 573
566 int days_since_last_run = GoogleChromeDaysSinceLastRun(); 574 int days_since_last_run = GoogleChromeDaysSinceLastRun();
567 if (days_since_last_run >= 0 && 575 if (days_since_last_run >= 0 &&
568 days_since_last_run < kReactivationMinDaysDormant) { 576 days_since_last_run < kReactivationMinDaysDormant) {
569 if (error_code) 577 if (error_code)
570 *error_code = REACTIVATE_ERROR_NOTDORMANT; 578 *error_code = REACTIVATE_ERROR_NOTDORMANT;
571 return FALSE; 579 return FALSE;
572 } 580 }
573 581
574 // Make sure we haven't previously been reactivated by this brand code 582 // Make sure we haven't previously been reactivated by this brand code
575 // or any of the previous brand codes from this partner. 583 // or any of the previous brand codes from this partner.
576 std::vector<std::wstring> reactivation_brands; 584 // Since this function is invoked by ReactivateChrome, and since
577 reactivation_brands.push_back(brand_code); 585 // ReactivateChrome is called first in non-elevated shell and
578 if (previous_brand_codes_length > 0 && previous_brand_codes != NULL) { 586 // second in UAC-elevated shell, we only want to execute this block
587 // of code the first time, in non-elevated mode.
588 if (shell_mode == GCAPI_INVOKED_STANDARD_SHELL) {
589 std::vector<std::wstring> reactivation_brands;
590 reactivation_brands.push_back(brand_code);
591 if (previous_brand_codes_length > 0 && previous_brand_codes != NULL) {
579 std::copy(previous_brand_codes, 592 std::copy(previous_brand_codes,
580 previous_brand_codes + previous_brand_codes_length, 593 previous_brand_codes + previous_brand_codes_length,
581 std::back_inserter(reactivation_brands)); 594 std::back_inserter(reactivation_brands));
Roger Tawa OOO till Jul 10th 2012/02/24 21:46:59 above: indent 4 more.
robertshield 2012/02/24 22:21:40 Done.
582 } 595 }
583 if (HasBeenReactivatedByBrandCodes(reactivation_brands)) { 596 if (HasBeenReactivatedByBrandCodes(reactivation_brands)) {
584 if (error_code) 597 if (error_code)
585 *error_code = REACTIVATE_ERROR_ALREADY_REACTIVATED; 598 *error_code = REACTIVATE_ERROR_ALREADY_REACTIVATED;
586 return FALSE; 599 return FALSE;
Roger Tawa OOO till Jul 10th 2012/02/24 21:46:59 indent if(error_code) block
robertshield 2012/02/24 22:21:40 Done.
600 }
587 } 601 }
588 602
589 return TRUE; 603 return TRUE;
590 } 604 }
591 605
592 BOOL __stdcall ReactivateChrome(wchar_t* brand_code, 606 BOOL __stdcall ReactivateChrome(wchar_t* brand_code,
593 int previous_brand_codes_length, 607 int previous_brand_codes_length,
594 const wchar_t** previous_brand_codes, 608 const wchar_t** previous_brand_codes,
609 int shell_mode,
595 DWORD* error_code) { 610 DWORD* error_code) {
596 BOOL result = FALSE; 611 BOOL result = FALSE;
597 if (CanOfferReactivation(brand_code, 612 if (CanOfferReactivation(brand_code,
598 previous_brand_codes_length, 613 previous_brand_codes_length,
599 previous_brand_codes, 614 previous_brand_codes,
615 shell_mode,
600 error_code)) { 616 error_code)) {
601 if (SetReactivationBrandCode(brand_code)) { 617 if (SetReactivationBrandCode(brand_code, shell_mode)) {
602 // Currently set this as a best-effort thing. We return TRUE if 618 // Currently set this as a best-effort thing. We return TRUE if
603 // reactivation succeeded regardless of the experiment label result. 619 // reactivation succeeded regardless of the experiment label result.
604 SetOmahaExperimentLabel(brand_code); 620 SetOmahaExperimentLabel(brand_code, shell_mode);
605 621
606 result = TRUE; 622 result = TRUE;
607 } else { 623 } else {
608 if (error_code) 624 if (error_code)
609 *error_code = REACTIVATE_ERROR_REACTIVATION_FAILED; 625 *error_code = REACTIVATE_ERROR_REACTIVATION_FAILED;
610 } 626 }
611 } 627 }
612 628
613 return result; 629 return result;
614 } 630 }
615 631
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698