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 #import "chrome/browser/mac/keystone_glue.h" | 5 #import "chrome/browser/mac/keystone_glue.h" |
| 6 | 6 |
| 7 #include <sys/mount.h> | 7 #include <sys/mount.h> |
| 8 #include <sys/param.h> | 8 #include <sys/param.h> |
| 9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
| 10 | 10 |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/location.h" | 14 #include "base/location.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/mac/authorization_util.h" | 16 #include "base/mac/authorization_util.h" |
| 17 #include "base/mac/bundle_locations.h" | 17 #include "base/mac/bundle_locations.h" |
| 18 #include "base/mac/mac_logging.h" | 18 #include "base/mac/mac_logging.h" |
| 19 #include "base/mac/mac_util.h" | 19 #include "base/mac/mac_util.h" |
| 20 #include "base/mac/scoped_nsautorelease_pool.h" | 20 #include "base/mac/scoped_nsautorelease_pool.h" |
| 21 #include "base/mac/scoped_nsexception_enabler.h" | 21 #include "base/mac/scoped_nsexception_enabler.h" |
| 22 #include "base/memory/ref_counted.h" | 22 #include "base/memory/ref_counted.h" |
| 23 #include "base/strings/sys_string_conversions.h" | 23 #include "base/strings/sys_string_conversions.h" |
| 24 #include "base/threading/worker_pool.h" | 24 #include "base/threading/worker_pool.h" |
| 25 #include "build/build_config.h" | 25 #include "build/build_config.h" |
| 26 #import "chrome/browser/mac/keystone_registration.h" | 26 #import "chrome/browser/mac/keystone_registration.h" |
| 27 #import "chrome/browser/mac/keystone_reporting_attribute.h" | |
| 27 #include "chrome/browser/mac/obsolete_system.h" | 28 #include "chrome/browser/mac/obsolete_system.h" |
| 28 #include "chrome/common/chrome_constants.h" | 29 #include "chrome/common/chrome_constants.h" |
| 29 #include "chrome/common/chrome_version_info.h" | 30 #include "chrome/common/chrome_version_info.h" |
| 30 #include "chrome/grit/chromium_strings.h" | 31 #include "chrome/grit/chromium_strings.h" |
| 31 #include "chrome/grit/generated_resources.h" | 32 #include "chrome/grit/generated_resources.h" |
| 32 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
| 33 #include "ui/base/l10n/l10n_util_mac.h" | 34 #include "ui/base/l10n/l10n_util_mac.h" |
| 34 | 35 |
| 35 namespace { | 36 namespace { |
| 36 | 37 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 // outer application bundle's Info.plist, not the framework's Info.plist. | 113 // outer application bundle's Info.plist, not the framework's Info.plist. |
| 113 - (NSString*)appInfoPlistPath; | 114 - (NSString*)appInfoPlistPath; |
| 114 | 115 |
| 115 // Returns a dictionary containing parameters to be used for a KSRegistration | 116 // Returns a dictionary containing parameters to be used for a KSRegistration |
| 116 // -registerWithParameters: or -promoteWithParameters:authorization: call. | 117 // -registerWithParameters: or -promoteWithParameters:authorization: call. |
| 117 - (NSDictionary*)keystoneParameters; | 118 - (NSDictionary*)keystoneParameters; |
| 118 | 119 |
| 119 // Called when Keystone registration completes. | 120 // Called when Keystone registration completes. |
| 120 - (void)registrationComplete:(NSNotification*)notification; | 121 - (void)registrationComplete:(NSNotification*)notification; |
| 121 | 122 |
| 123 // Set the registration active passing profile count parameters. | |
| 124 - (void)setRegistrationActive:(KSRegistration*)ksr; | |
| 125 | |
| 122 // Called periodically to announce activity by pinging the Keystone server. | 126 // Called periodically to announce activity by pinging the Keystone server. |
| 123 - (void)markActive:(NSTimer*)timer; | 127 - (void)markActive:(NSTimer*)timer; |
| 124 | 128 |
| 125 // Called when an update check or update installation is complete. Posts the | 129 // Called when an update check or update installation is complete. Posts the |
| 126 // kAutoupdateStatusNotification notification to the default notification | 130 // kAutoupdateStatusNotification notification to the default notification |
| 127 // center. | 131 // center. |
| 128 - (void)updateStatus:(AutoupdateStatus)status version:(NSString*)version; | 132 - (void)updateStatus:(AutoupdateStatus)status version:(NSString*)version; |
| 129 | 133 |
| 130 // Returns the version of the currently-installed application on disk. | 134 // Returns the version of the currently-installed application on disk. |
| 131 - (NSString*)currentlyInstalledVersion; | 135 - (NSString*)currentlyInstalledVersion; |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 484 url_, ksr::KSRegistrationServerURLStringKey, | 488 url_, ksr::KSRegistrationServerURLStringKey, |
| 485 preserveTTToken, ksr::KSRegistrationPreserveTrustedTesterTokenKey, | 489 preserveTTToken, ksr::KSRegistrationPreserveTrustedTesterTokenKey, |
| 486 tagValue, ksr::KSRegistrationTagKey, | 490 tagValue, ksr::KSRegistrationTagKey, |
| 487 appInfoPlistPath, ksr::KSRegistrationTagPathKey, | 491 appInfoPlistPath, ksr::KSRegistrationTagPathKey, |
| 488 tagKey, ksr::KSRegistrationTagKeyKey, | 492 tagKey, ksr::KSRegistrationTagKeyKey, |
| 489 brandPath, ksr::KSRegistrationBrandPathKey, | 493 brandPath, ksr::KSRegistrationBrandPathKey, |
| 490 brandKey, ksr::KSRegistrationBrandKeyKey, | 494 brandKey, ksr::KSRegistrationBrandKeyKey, |
| 491 nil]; | 495 nil]; |
| 492 } | 496 } |
| 493 | 497 |
| 498 - (void)setRegistrationActive:(KSRegistration*)ksr { | |
| 499 if (numSignedInProfiles_ > 0) { | |
|
bcwhite
2014/09/23 20:32:58
Should this be "numProfiles_"? You could have exi
Mike Lerman
2014/09/26 19:52:29
Done.
| |
| 500 NSError* reportingAttributeError = nil; | |
| 501 KSUnsignedReportingAttribute* numProfilesAttribute = | |
| 502 [KSUnsignedReportingAttribute | |
| 503 reportingAttributeWithValue:numProfiles_ | |
| 504 name:@"_numAccounts" | |
| 505 aggregationType:kKSReportingAggregationSum | |
| 506 error:&reportingAttributeError]; | |
| 507 if (reportingAttributeError != nil) { | |
| 508 LOG(ERROR) << [reportingAttributeError localizedDescription]; | |
| 509 [ksr setActive]; | |
| 510 return; | |
| 511 } | |
| 512 | |
| 513 KSUnsignedReportingAttribute* numSignedInProfilesAttribute = | |
| 514 [KSUnsignedReportingAttribute | |
| 515 reportingAttributeWithValue:numSignedInProfiles_ | |
| 516 name:@"_numSignedInAccounts" | |
| 517 aggregationType:kKSReportingAggregationSum | |
| 518 error:&reportingAttributeError]; | |
| 519 if (reportingAttributeError != nil) { | |
| 520 LOG(ERROR) << [reportingAttributeError localizedDescription]; | |
| 521 [ksr setActive]; | |
| 522 return; | |
| 523 } | |
| 524 | |
| 525 NSArray* profileCountsInformation = | |
| 526 [NSArray arrayWithObjects:numProfilesAttribute, | |
| 527 numSignedInProfilesAttribute, | |
| 528 nil]; | |
| 529 | |
| 530 NSError* setActiveError = nil; | |
| 531 [ksr setActiveWithReportingAttributes:profileCountsInformation | |
| 532 error:&setActiveError]; | |
| 533 if (setActiveError != nil) { | |
| 534 LOG(ERROR) << [setActiveError localizedDescription]; | |
| 535 [ksr setActive]; | |
|
bcwhite
2014/09/23 20:32:58
How about moving this out of the condition and eli
Mike Lerman
2014/09/26 19:52:30
I flipped the upper condition around.
bcwhite
2014/09/26 20:41:20
I like the idea where you optionally add things to
Mike Lerman
2014/10/06 16:49:08
We don't always call setActive, we call it only if
| |
| 536 return; | |
|
bcwhite
2014/09/23 20:32:58
Unneeded.
Mike Lerman
2014/09/26 19:52:29
Done.
| |
| 537 } | |
| 538 } else { | |
| 539 [ksr setActive]; | |
| 540 } | |
| 541 } | |
| 542 | |
| 494 - (void)registerWithKeystone { | 543 - (void)registerWithKeystone { |
| 495 [self updateStatus:kAutoupdateRegistering version:nil]; | 544 [self updateStatus:kAutoupdateRegistering version:nil]; |
| 496 | 545 |
| 497 NSDictionary* parameters = [self keystoneParameters]; | 546 NSDictionary* parameters = [self keystoneParameters]; |
| 498 BOOL result; | 547 BOOL result; |
| 499 { | 548 { |
| 500 // TODO(shess): Allows Keystone to throw an exception when | 549 // TODO(shess): Allows Keystone to throw an exception when |
| 501 // /usr/bin/python does not exist (really!). | 550 // /usr/bin/python does not exist (really!). |
| 502 // http://crbug.com/86221 and http://crbug.com/87931 | 551 // http://crbug.com/86221 and http://crbug.com/87931 |
| 503 base::mac::ScopedNSExceptionEnabler enabler; | 552 base::mac::ScopedNSExceptionEnabler enabler; |
| 504 result = [registration_ registerWithParameters:parameters]; | 553 result = [registration_ registerWithParameters:parameters]; |
| 505 } | 554 } |
| 506 if (!result) { | 555 if (!result) { |
| 507 [self updateStatus:kAutoupdateRegisterFailed version:nil]; | 556 [self updateStatus:kAutoupdateRegisterFailed version:nil]; |
| 508 return; | 557 return; |
| 509 } | 558 } |
| 510 | 559 |
| 511 // Upon completion, ksr::KSRegistrationDidCompleteNotification will be | 560 // Upon completion, ksr::KSRegistrationDidCompleteNotification will be |
| 512 // posted, and -registrationComplete: will be called. | 561 // posted, and -registrationComplete: will be called. |
| 513 | 562 |
| 514 // Mark an active RIGHT NOW; don't wait an hour for the first one. | 563 // Mark an active RIGHT NOW; don't wait an hour for the first one. |
| 515 [registration_ setActive]; | 564 [self setRegistrationActive:registration_]; |
| 516 | 565 |
| 517 // Set up hourly activity pings. | 566 // Set up hourly activity pings. |
| 518 timer_ = [NSTimer scheduledTimerWithTimeInterval:60 * 60 // One hour | 567 timer_ = [NSTimer scheduledTimerWithTimeInterval:60 * 60 // One hour |
| 519 target:self | 568 target:self |
| 520 selector:@selector(markActive:) | 569 selector:@selector(markActive:) |
| 521 userInfo:registration_ | 570 userInfo:registration_ |
| 522 repeats:YES]; | 571 repeats:YES]; |
| 523 } | 572 } |
| 524 | 573 |
| 525 - (void)registrationComplete:(NSNotification*)notification { | 574 - (void)registrationComplete:(NSNotification*)notification { |
| 526 NSDictionary* userInfo = [notification userInfo]; | 575 NSDictionary* userInfo = [notification userInfo]; |
| 527 if ([[userInfo objectForKey:ksr::KSRegistrationStatusKey] boolValue]) { | 576 if ([[userInfo objectForKey:ksr::KSRegistrationStatusKey] boolValue]) { |
| 528 if ([self isSystemTicketDoomed]) { | 577 if ([self isSystemTicketDoomed]) { |
| 529 [self updateStatus:kAutoupdateNeedsPromotion version:nil]; | 578 [self updateStatus:kAutoupdateNeedsPromotion version:nil]; |
| 530 } else { | 579 } else { |
| 531 [self updateStatus:kAutoupdateRegistered version:nil]; | 580 [self updateStatus:kAutoupdateRegistered version:nil]; |
| 532 } | 581 } |
| 533 } else { | 582 } else { |
| 534 // Dump registration_? | 583 // Dump registration_? |
| 535 [self updateStatus:kAutoupdateRegisterFailed version:nil]; | 584 [self updateStatus:kAutoupdateRegisterFailed version:nil]; |
| 536 } | 585 } |
| 537 } | 586 } |
| 538 | 587 |
| 539 - (void)stopTimer { | 588 - (void)stopTimer { |
| 540 [timer_ invalidate]; | 589 [timer_ invalidate]; |
| 541 } | 590 } |
| 542 | 591 |
| 543 - (void)markActive:(NSTimer*)timer { | 592 - (void)markActive:(NSTimer*)timer { |
| 544 KSRegistration* ksr = [timer userInfo]; | 593 [self setRegistrationActive:[timer userInfo]]; |
| 545 [ksr setActive]; | |
| 546 } | 594 } |
| 547 | 595 |
| 548 - (void)checkForUpdate { | 596 - (void)checkForUpdate { |
| 549 DCHECK(![self asyncOperationPending]); | 597 DCHECK(![self asyncOperationPending]); |
| 550 | 598 |
| 551 if (!registration_) { | 599 if (!registration_) { |
| 552 [self updateStatus:kAutoupdateCheckFailed version:nil]; | 600 [self updateStatus:kAutoupdateCheckFailed version:nil]; |
| 553 return; | 601 return; |
| 554 } | 602 } |
| 555 | 603 |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1038 NSString* tagSuffix = @""; | 1086 NSString* tagSuffix = @""; |
| 1039 if (ObsoleteSystemMac::Has32BitOnlyCPU()) { | 1087 if (ObsoleteSystemMac::Has32BitOnlyCPU()) { |
| 1040 tagSuffix = [tagSuffix stringByAppendingString:@"-32bit"]; | 1088 tagSuffix = [tagSuffix stringByAppendingString:@"-32bit"]; |
| 1041 } | 1089 } |
| 1042 if ([self wantsFullInstaller]) { | 1090 if ([self wantsFullInstaller]) { |
| 1043 tagSuffix = [tagSuffix stringByAppendingString:@"-full"]; | 1091 tagSuffix = [tagSuffix stringByAppendingString:@"-full"]; |
| 1044 } | 1092 } |
| 1045 return tagSuffix; | 1093 return tagSuffix; |
| 1046 } | 1094 } |
| 1047 | 1095 |
| 1096 | |
| 1097 - (void)updateProfileCountsWithNumProfiles:(size_t)numProfiles | |
| 1098 numSignedInProfiles:(size_t)numSignedInProfiles { | |
| 1099 numProfiles_ = numProfiles; | |
| 1100 numSignedInProfiles_ = numSignedInProfiles; | |
| 1101 } | |
| 1102 | |
| 1048 @end // @implementation KeystoneGlue | 1103 @end // @implementation KeystoneGlue |
| 1049 | 1104 |
| 1050 namespace { | 1105 namespace { |
| 1051 | 1106 |
| 1052 std::string BrandCodeInternal() { | 1107 std::string BrandCodeInternal() { |
| 1053 KeystoneGlue* keystone_glue = [KeystoneGlue defaultKeystoneGlue]; | 1108 KeystoneGlue* keystone_glue = [KeystoneGlue defaultKeystoneGlue]; |
| 1054 NSString* brand_path = [keystone_glue brandFilePath]; | 1109 NSString* brand_path = [keystone_glue brandFilePath]; |
| 1055 | 1110 |
| 1056 if (![brand_path length]) | 1111 if (![brand_path length]) |
| 1057 return std::string(); | 1112 return std::string(); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 1080 return [KeystoneGlue defaultKeystoneGlue] != nil; | 1135 return [KeystoneGlue defaultKeystoneGlue] != nil; |
| 1081 } | 1136 } |
| 1082 | 1137 |
| 1083 base::string16 CurrentlyInstalledVersion() { | 1138 base::string16 CurrentlyInstalledVersion() { |
| 1084 KeystoneGlue* keystoneGlue = [KeystoneGlue defaultKeystoneGlue]; | 1139 KeystoneGlue* keystoneGlue = [KeystoneGlue defaultKeystoneGlue]; |
| 1085 NSString* version = [keystoneGlue currentlyInstalledVersion]; | 1140 NSString* version = [keystoneGlue currentlyInstalledVersion]; |
| 1086 return base::SysNSStringToUTF16(version); | 1141 return base::SysNSStringToUTF16(version); |
| 1087 } | 1142 } |
| 1088 | 1143 |
| 1089 } // namespace keystone_glue | 1144 } // namespace keystone_glue |
| OLD | NEW |