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 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 // outer application bundle's Info.plist, not the framework's Info.plist. | 112 // outer application bundle's Info.plist, not the framework's Info.plist. |
113 - (NSString*)appInfoPlistPath; | 113 - (NSString*)appInfoPlistPath; |
114 | 114 |
115 // Returns a dictionary containing parameters to be used for a KSRegistration | 115 // Returns a dictionary containing parameters to be used for a KSRegistration |
116 // -registerWithParameters: or -promoteWithParameters:authorization: call. | 116 // -registerWithParameters: or -promoteWithParameters:authorization: call. |
117 - (NSDictionary*)keystoneParameters; | 117 - (NSDictionary*)keystoneParameters; |
118 | 118 |
119 // Called when Keystone registration completes. | 119 // Called when Keystone registration completes. |
120 - (void)registrationComplete:(NSNotification*)notification; | 120 - (void)registrationComplete:(NSNotification*)notification; |
121 | 121 |
122 // Set the registration active and pass profile count parameters. | |
123 - (void)setRegistrationActive; | |
124 | |
122 // Called periodically to announce activity by pinging the Keystone server. | 125 // Called periodically to announce activity by pinging the Keystone server. |
123 - (void)markActive:(NSTimer*)timer; | 126 - (void)markActive:(NSTimer*)timer; |
124 | 127 |
125 // Called when an update check or update installation is complete. Posts the | 128 // Called when an update check or update installation is complete. Posts the |
126 // kAutoupdateStatusNotification notification to the default notification | 129 // kAutoupdateStatusNotification notification to the default notification |
127 // center. | 130 // center. |
128 - (void)updateStatus:(AutoupdateStatus)status version:(NSString*)version; | 131 - (void)updateStatus:(AutoupdateStatus)status version:(NSString*)version; |
129 | 132 |
130 // Returns the version of the currently-installed application on disk. | 133 // Returns the version of the currently-installed application on disk. |
131 - (NSString*)currentlyInstalledVersion; | 134 - (NSString*)currentlyInstalledVersion; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
208 NSString* const kAutoupdateStatusNotification = @"AutoupdateStatusNotification"; | 211 NSString* const kAutoupdateStatusNotification = @"AutoupdateStatusNotification"; |
209 NSString* const kAutoupdateStatusStatus = @"status"; | 212 NSString* const kAutoupdateStatusStatus = @"status"; |
210 NSString* const kAutoupdateStatusVersion = @"version"; | 213 NSString* const kAutoupdateStatusVersion = @"version"; |
211 | 214 |
212 namespace { | 215 namespace { |
213 | 216 |
214 NSString* const kChannelKey = @"KSChannelID"; | 217 NSString* const kChannelKey = @"KSChannelID"; |
215 NSString* const kBrandKey = @"KSBrandID"; | 218 NSString* const kBrandKey = @"KSBrandID"; |
216 NSString* const kVersionKey = @"KSVersion"; | 219 NSString* const kVersionKey = @"KSVersion"; |
217 | 220 |
221 // Keep the Keystone Registration bundle once it's been loaded. | |
222 NSBundle* ksrBundle; | |
Mark Mentovai
2015/02/20 21:54:18
Don’t store this in a global. Use an instance vari
Mike Lerman
2015/02/23 16:12:11
Done.
| |
223 | |
218 } // namespace | 224 } // namespace |
219 | 225 |
220 @implementation KeystoneGlue | 226 @implementation KeystoneGlue |
221 | 227 |
222 + (id)defaultKeystoneGlue { | 228 + (id)defaultKeystoneGlue { |
223 static bool sTriedCreatingDefaultKeystoneGlue = false; | 229 static bool sTriedCreatingDefaultKeystoneGlue = false; |
224 // TODO(jrg): use base::SingletonObjC<KeystoneGlue> | 230 // TODO(jrg): use base::SingletonObjC<KeystoneGlue> |
225 static KeystoneGlue* sDefaultKeystoneGlue = nil; // leaked | 231 static KeystoneGlue* sDefaultKeystoneGlue = nil; // leaked |
226 | 232 |
227 if (!sTriedCreatingDefaultKeystoneGlue) { | 233 if (!sTriedCreatingDefaultKeystoneGlue) { |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
428 | 434 |
429 - (BOOL)loadKeystoneRegistration { | 435 - (BOOL)loadKeystoneRegistration { |
430 if (!productID_ || !appPath_ || !url_ || !version_) | 436 if (!productID_ || !appPath_ || !url_ || !version_) |
431 return NO; | 437 return NO; |
432 | 438 |
433 // Load the KeystoneRegistration framework bundle if present. It lives | 439 // Load the KeystoneRegistration framework bundle if present. It lives |
434 // inside the framework, so use base::mac::FrameworkBundle(); | 440 // inside the framework, so use base::mac::FrameworkBundle(); |
435 NSString* ksrPath = | 441 NSString* ksrPath = |
436 [[base::mac::FrameworkBundle() privateFrameworksPath] | 442 [[base::mac::FrameworkBundle() privateFrameworksPath] |
437 stringByAppendingPathComponent:@"KeystoneRegistration.framework"]; | 443 stringByAppendingPathComponent:@"KeystoneRegistration.framework"]; |
438 NSBundle* ksrBundle = [NSBundle bundleWithPath:ksrPath]; | 444 ksrBundle = [NSBundle bundleWithPath:ksrPath]; |
439 [ksrBundle load]; | 445 [ksrBundle load]; |
440 | 446 |
441 // Harness the KSRegistration class. | 447 // Harness the KSRegistration class. |
442 Class ksrClass = [ksrBundle classNamed:@"KSRegistration"]; | 448 Class ksrClass = [ksrBundle classNamed:@"KSRegistration"]; |
443 KSRegistration* ksr = [ksrClass registrationWithProductID:productID_]; | 449 KSRegistration* ksr = [ksrClass registrationWithProductID:productID_]; |
444 if (!ksr) | 450 if (!ksr) |
445 return NO; | 451 return NO; |
446 | 452 |
447 registration_ = [ksr retain]; | 453 registration_ = [ksr retain]; |
448 return YES; | 454 return YES; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
484 url_, ksr::KSRegistrationServerURLStringKey, | 490 url_, ksr::KSRegistrationServerURLStringKey, |
485 preserveTTToken, ksr::KSRegistrationPreserveTrustedTesterTokenKey, | 491 preserveTTToken, ksr::KSRegistrationPreserveTrustedTesterTokenKey, |
486 tagValue, ksr::KSRegistrationTagKey, | 492 tagValue, ksr::KSRegistrationTagKey, |
487 appInfoPlistPath, ksr::KSRegistrationTagPathKey, | 493 appInfoPlistPath, ksr::KSRegistrationTagPathKey, |
488 tagKey, ksr::KSRegistrationTagKeyKey, | 494 tagKey, ksr::KSRegistrationTagKeyKey, |
489 brandPath, ksr::KSRegistrationBrandPathKey, | 495 brandPath, ksr::KSRegistrationBrandPathKey, |
490 brandKey, ksr::KSRegistrationBrandKeyKey, | 496 brandKey, ksr::KSRegistrationBrandKeyKey, |
491 nil]; | 497 nil]; |
492 } | 498 } |
493 | 499 |
500 - (void)setRegistrationActive { | |
501 if (!registration_) | |
502 return; | |
503 | |
504 // Should never have zero profiles. Do not report this value. | |
505 if (!numProfiles_) { | |
506 [registration_ setActive]; | |
507 return; | |
508 } | |
509 | |
510 NSError* reportingError = nil; | |
511 | |
512 Class ksUnsignedReportingAttributeClass = | |
513 [ksrBundle classNamed:@"KSUnsignedReportingAttribute"]; | |
514 | |
515 KSReportingAttribute* numAccountsAttr = | |
516 [ksUnsignedReportingAttributeClass | |
517 reportingAttributeWithValue:numProfiles_ | |
518 name:@"_NumAccounts" | |
519 aggregationType:kKSReportingAggregationSum | |
520 error:&reportingError]; | |
521 if (reportingError != nil) | |
522 VLOG(1) << [reportingError localizedDescription]; | |
523 reportingError = nil; | |
524 | |
525 KSReportingAttribute* numSignedInAccountsAttr = | |
526 [ksUnsignedReportingAttributeClass | |
527 reportingAttributeWithValue:numSignedInProfiles_ | |
528 name:@"_NumSignedIn" | |
529 aggregationType:kKSReportingAggregationSum | |
530 error:&reportingError]; | |
531 if (reportingError != nil) | |
532 VLOG(1) << [reportingError localizedDescription]; | |
533 reportingError = nil; | |
534 | |
535 NSArray* profileCountsInformation = | |
536 [NSArray arrayWithObjects:numAccountsAttr, numSignedInAccountsAttr, nil]; | |
537 | |
538 if (![registration_ setActiveWithReportingAttributes:profileCountsInformation | |
539 error:&reportingError]) | |
540 VLOG(1) << [reportingError localizedDescription]; | |
Mark Mentovai
2015/02/20 21:54:18
{brace} this because its controlling condition tak
Mike Lerman
2015/02/23 16:12:11
Indeed - thanks. Done.
| |
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]; |
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:nil |
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]; |
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 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1042 NSString* tagSuffix = @""; | 1090 NSString* tagSuffix = @""; |
1043 if (ObsoleteSystemMac::Has32BitOnlyCPU()) { | 1091 if (ObsoleteSystemMac::Has32BitOnlyCPU()) { |
1044 tagSuffix = [tagSuffix stringByAppendingString:@"-32bit"]; | 1092 tagSuffix = [tagSuffix stringByAppendingString:@"-32bit"]; |
1045 } | 1093 } |
1046 if ([self wantsFullInstaller]) { | 1094 if ([self wantsFullInstaller]) { |
1047 tagSuffix = [tagSuffix stringByAppendingString:@"-full"]; | 1095 tagSuffix = [tagSuffix stringByAppendingString:@"-full"]; |
1048 } | 1096 } |
1049 return tagSuffix; | 1097 return tagSuffix; |
1050 } | 1098 } |
1051 | 1099 |
1100 | |
1101 - (void)updateProfileCountsWithNumProfiles:(uint32_t)numProfiles | |
1102 numSignedInProfiles:(uint32_t)numSignedInProfiles { | |
1103 numProfiles_ = numProfiles; | |
1104 numSignedInProfiles_ = numSignedInProfiles; | |
1105 } | |
1106 | |
1052 @end // @implementation KeystoneGlue | 1107 @end // @implementation KeystoneGlue |
1053 | 1108 |
1054 namespace { | 1109 namespace { |
1055 | 1110 |
1056 std::string BrandCodeInternal() { | 1111 std::string BrandCodeInternal() { |
1057 KeystoneGlue* keystone_glue = [KeystoneGlue defaultKeystoneGlue]; | 1112 KeystoneGlue* keystone_glue = [KeystoneGlue defaultKeystoneGlue]; |
1058 NSString* brand_path = [keystone_glue brandFilePath]; | 1113 NSString* brand_path = [keystone_glue brandFilePath]; |
1059 | 1114 |
1060 if (![brand_path length]) | 1115 if (![brand_path length]) |
1061 return std::string(); | 1116 return std::string(); |
(...skipping 22 matching lines...) Expand all Loading... | |
1084 return [KeystoneGlue defaultKeystoneGlue] != nil; | 1139 return [KeystoneGlue defaultKeystoneGlue] != nil; |
1085 } | 1140 } |
1086 | 1141 |
1087 base::string16 CurrentlyInstalledVersion() { | 1142 base::string16 CurrentlyInstalledVersion() { |
1088 KeystoneGlue* keystoneGlue = [KeystoneGlue defaultKeystoneGlue]; | 1143 KeystoneGlue* keystoneGlue = [KeystoneGlue defaultKeystoneGlue]; |
1089 NSString* version = [keystoneGlue currentlyInstalledVersion]; | 1144 NSString* version = [keystoneGlue currentlyInstalledVersion]; |
1090 return base::SysNSStringToUTF16(version); | 1145 return base::SysNSStringToUTF16(version); |
1091 } | 1146 } |
1092 | 1147 |
1093 } // namespace keystone_glue | 1148 } // namespace keystone_glue |
OLD | NEW |