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 | |
125 // Called periodically to announce activity by pinging the Keystone server. | 122 // Called periodically to announce activity by pinging the Keystone server. |
126 - (void)markActive:(NSTimer*)timer; | 123 - (void)markActive:(NSTimer*)timer; |
127 | 124 |
128 // Called when an update check or update installation is complete. Posts the | 125 // Called when an update check or update installation is complete. Posts the |
129 // kAutoupdateStatusNotification notification to the default notification | 126 // kAutoupdateStatusNotification notification to the default notification |
130 // center. | 127 // center. |
131 - (void)updateStatus:(AutoupdateStatus)status version:(NSString*)version; | 128 - (void)updateStatus:(AutoupdateStatus)status version:(NSString*)version; |
132 | 129 |
133 // Returns the version of the currently-installed application on disk. | 130 // Returns the version of the currently-installed application on disk. |
134 - (NSString*)currentlyInstalledVersion; | 131 - (NSString*)currentlyInstalledVersion; |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 NSBundle* ksrBundle = [NSBundle bundleWithPath:ksrPath]; | 438 NSBundle* ksrBundle = [NSBundle bundleWithPath:ksrPath]; |
442 [ksrBundle load]; | 439 [ksrBundle load]; |
443 | 440 |
444 // Harness the KSRegistration class. | 441 // Harness the KSRegistration class. |
445 Class ksrClass = [ksrBundle classNamed:@"KSRegistration"]; | 442 Class ksrClass = [ksrBundle classNamed:@"KSRegistration"]; |
446 KSRegistration* ksr = [ksrClass registrationWithProductID:productID_]; | 443 KSRegistration* ksr = [ksrClass registrationWithProductID:productID_]; |
447 if (!ksr) | 444 if (!ksr) |
448 return NO; | 445 return NO; |
449 | 446 |
450 registration_ = [ksr retain]; | 447 registration_ = [ksr retain]; |
451 ksUnsignedReportingAttributeClass_ = | |
452 [ksrBundle classNamed:@"KSUnsignedReportingAttribute"]; | |
453 return YES; | 448 return YES; |
454 } | 449 } |
455 | 450 |
456 - (NSString*)appInfoPlistPath { | 451 - (NSString*)appInfoPlistPath { |
457 // NSBundle ought to have a way to access this path directly, but it | 452 // NSBundle ought to have a way to access this path directly, but it |
458 // doesn't. | 453 // doesn't. |
459 return [[appPath_ stringByAppendingPathComponent:@"Contents"] | 454 return [[appPath_ stringByAppendingPathComponent:@"Contents"] |
460 stringByAppendingPathComponent:@"Info.plist"]; | 455 stringByAppendingPathComponent:@"Info.plist"]; |
461 } | 456 } |
462 | 457 |
(...skipping 26 matching lines...) Expand all Loading... |
489 url_, ksr::KSRegistrationServerURLStringKey, | 484 url_, ksr::KSRegistrationServerURLStringKey, |
490 preserveTTToken, ksr::KSRegistrationPreserveTrustedTesterTokenKey, | 485 preserveTTToken, ksr::KSRegistrationPreserveTrustedTesterTokenKey, |
491 tagValue, ksr::KSRegistrationTagKey, | 486 tagValue, ksr::KSRegistrationTagKey, |
492 appInfoPlistPath, ksr::KSRegistrationTagPathKey, | 487 appInfoPlistPath, ksr::KSRegistrationTagPathKey, |
493 tagKey, ksr::KSRegistrationTagKeyKey, | 488 tagKey, ksr::KSRegistrationTagKeyKey, |
494 brandPath, ksr::KSRegistrationBrandPathKey, | 489 brandPath, ksr::KSRegistrationBrandPathKey, |
495 brandKey, ksr::KSRegistrationBrandKeyKey, | 490 brandKey, ksr::KSRegistrationBrandKeyKey, |
496 nil]; | 491 nil]; |
497 } | 492 } |
498 | 493 |
499 - (void)setRegistrationActive { | |
500 if (!registration_) | |
501 return; | |
502 | |
503 // Should never have zero profiles. Do not report this value. | |
504 if (!numProfiles_) { | |
505 [registration_ setActive]; | |
506 return; | |
507 } | |
508 | |
509 NSError* reportingError = nil; | |
510 | |
511 KSReportingAttribute* numAccountsAttr = | |
512 [ksUnsignedReportingAttributeClass_ | |
513 reportingAttributeWithValue:numProfiles_ | |
514 name:@"_NumAccounts" | |
515 aggregationType:kKSReportingAggregationSum | |
516 error:&reportingError]; | |
517 if (reportingError != nil) | |
518 VLOG(1) << [reportingError localizedDescription]; | |
519 reportingError = nil; | |
520 | |
521 KSReportingAttribute* numSignedInAccountsAttr = | |
522 [ksUnsignedReportingAttributeClass_ | |
523 reportingAttributeWithValue:numSignedInProfiles_ | |
524 name:@"_NumSignedIn" | |
525 aggregationType:kKSReportingAggregationSum | |
526 error:&reportingError]; | |
527 if (reportingError != nil) | |
528 VLOG(1) << [reportingError localizedDescription]; | |
529 reportingError = nil; | |
530 | |
531 NSArray* profileCountsInformation = | |
532 [NSArray arrayWithObjects:numAccountsAttr, numSignedInAccountsAttr, nil]; | |
533 | |
534 if (![registration_ setActiveWithReportingAttributes:profileCountsInformation | |
535 error:&reportingError]) { | |
536 VLOG(1) << [reportingError localizedDescription]; | |
537 } | |
538 } | |
539 | |
540 - (void)registerWithKeystone { | 494 - (void)registerWithKeystone { |
541 [self updateStatus:kAutoupdateRegistering version:nil]; | 495 [self updateStatus:kAutoupdateRegistering version:nil]; |
542 | 496 |
543 NSDictionary* parameters = [self keystoneParameters]; | 497 NSDictionary* parameters = [self keystoneParameters]; |
544 BOOL result; | 498 BOOL result; |
545 { | 499 { |
546 // TODO(shess): Allows Keystone to throw an exception when | 500 // TODO(shess): Allows Keystone to throw an exception when |
547 // /usr/bin/python does not exist (really!). | 501 // /usr/bin/python does not exist (really!). |
548 // http://crbug.com/86221 and http://crbug.com/87931 | 502 // http://crbug.com/86221 and http://crbug.com/87931 |
549 base::mac::ScopedNSExceptionEnabler enabler; | 503 base::mac::ScopedNSExceptionEnabler enabler; |
550 result = [registration_ registerWithParameters:parameters]; | 504 result = [registration_ registerWithParameters:parameters]; |
551 } | 505 } |
552 if (!result) { | 506 if (!result) { |
553 [self updateStatus:kAutoupdateRegisterFailed version:nil]; | 507 [self updateStatus:kAutoupdateRegisterFailed version:nil]; |
554 return; | 508 return; |
555 } | 509 } |
556 | 510 |
557 // Upon completion, ksr::KSRegistrationDidCompleteNotification will be | 511 // Upon completion, ksr::KSRegistrationDidCompleteNotification will be |
558 // posted, and -registrationComplete: will be called. | 512 // posted, and -registrationComplete: will be called. |
559 | 513 |
560 // Mark an active RIGHT NOW; don't wait an hour for the first one. | 514 // Mark an active RIGHT NOW; don't wait an hour for the first one. |
561 [self setRegistrationActive]; | 515 [registration_ setActive]; |
562 | 516 |
563 // Set up hourly activity pings. | 517 // Set up hourly activity pings. |
564 timer_ = [NSTimer scheduledTimerWithTimeInterval:60 * 60 // One hour | 518 timer_ = [NSTimer scheduledTimerWithTimeInterval:60 * 60 // One hour |
565 target:self | 519 target:self |
566 selector:@selector(markActive:) | 520 selector:@selector(markActive:) |
567 userInfo:nil | 521 userInfo:registration_ |
568 repeats:YES]; | 522 repeats:YES]; |
569 } | 523 } |
570 | 524 |
571 - (void)registrationComplete:(NSNotification*)notification { | 525 - (void)registrationComplete:(NSNotification*)notification { |
572 NSDictionary* userInfo = [notification userInfo]; | 526 NSDictionary* userInfo = [notification userInfo]; |
573 if ([[userInfo objectForKey:ksr::KSRegistrationStatusKey] boolValue]) { | 527 if ([[userInfo objectForKey:ksr::KSRegistrationStatusKey] boolValue]) { |
574 if ([self isSystemTicketDoomed]) { | 528 if ([self isSystemTicketDoomed]) { |
575 [self updateStatus:kAutoupdateNeedsPromotion version:nil]; | 529 [self updateStatus:kAutoupdateNeedsPromotion version:nil]; |
576 } else { | 530 } else { |
577 [self updateStatus:kAutoupdateRegistered version:nil]; | 531 [self updateStatus:kAutoupdateRegistered version:nil]; |
578 } | 532 } |
579 } else { | 533 } else { |
580 // Dump registration_? | 534 // Dump registration_? |
581 [self updateStatus:kAutoupdateRegisterFailed version:nil]; | 535 [self updateStatus:kAutoupdateRegisterFailed version:nil]; |
582 } | 536 } |
583 } | 537 } |
584 | 538 |
585 - (void)stopTimer { | 539 - (void)stopTimer { |
586 [timer_ invalidate]; | 540 [timer_ invalidate]; |
587 } | 541 } |
588 | 542 |
589 - (void)markActive:(NSTimer*)timer { | 543 - (void)markActive:(NSTimer*)timer { |
590 [self setRegistrationActive]; | 544 KSRegistration* ksr = [timer userInfo]; |
| 545 [ksr setActive]; |
591 } | 546 } |
592 | 547 |
593 - (void)checkForUpdate { | 548 - (void)checkForUpdate { |
594 DCHECK(![self asyncOperationPending]); | 549 DCHECK(![self asyncOperationPending]); |
595 | 550 |
596 if (!registration_) { | 551 if (!registration_) { |
597 [self updateStatus:kAutoupdateCheckFailed version:nil]; | 552 [self updateStatus:kAutoupdateCheckFailed version:nil]; |
598 return; | 553 return; |
599 } | 554 } |
600 | 555 |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1087 NSString* tagSuffix = @""; | 1042 NSString* tagSuffix = @""; |
1088 if (ObsoleteSystemMac::Has32BitOnlyCPU()) { | 1043 if (ObsoleteSystemMac::Has32BitOnlyCPU()) { |
1089 tagSuffix = [tagSuffix stringByAppendingString:@"-32bit"]; | 1044 tagSuffix = [tagSuffix stringByAppendingString:@"-32bit"]; |
1090 } | 1045 } |
1091 if ([self wantsFullInstaller]) { | 1046 if ([self wantsFullInstaller]) { |
1092 tagSuffix = [tagSuffix stringByAppendingString:@"-full"]; | 1047 tagSuffix = [tagSuffix stringByAppendingString:@"-full"]; |
1093 } | 1048 } |
1094 return tagSuffix; | 1049 return tagSuffix; |
1095 } | 1050 } |
1096 | 1051 |
1097 | |
1098 - (void)updateProfileCountsWithNumProfiles:(uint32_t)profiles | |
1099 numSignedInProfiles:(uint32_t)signedInProfiles { | |
1100 numProfiles_ = profiles; | |
1101 numSignedInProfiles_ = signedInProfiles; | |
1102 } | |
1103 | |
1104 @end // @implementation KeystoneGlue | 1052 @end // @implementation KeystoneGlue |
1105 | 1053 |
1106 namespace { | 1054 namespace { |
1107 | 1055 |
1108 std::string BrandCodeInternal() { | 1056 std::string BrandCodeInternal() { |
1109 KeystoneGlue* keystone_glue = [KeystoneGlue defaultKeystoneGlue]; | 1057 KeystoneGlue* keystone_glue = [KeystoneGlue defaultKeystoneGlue]; |
1110 NSString* brand_path = [keystone_glue brandFilePath]; | 1058 NSString* brand_path = [keystone_glue brandFilePath]; |
1111 | 1059 |
1112 if (![brand_path length]) | 1060 if (![brand_path length]) |
1113 return std::string(); | 1061 return std::string(); |
(...skipping 22 matching lines...) Expand all Loading... |
1136 return [KeystoneGlue defaultKeystoneGlue] != nil; | 1084 return [KeystoneGlue defaultKeystoneGlue] != nil; |
1137 } | 1085 } |
1138 | 1086 |
1139 base::string16 CurrentlyInstalledVersion() { | 1087 base::string16 CurrentlyInstalledVersion() { |
1140 KeystoneGlue* keystoneGlue = [KeystoneGlue defaultKeystoneGlue]; | 1088 KeystoneGlue* keystoneGlue = [KeystoneGlue defaultKeystoneGlue]; |
1141 NSString* version = [keystoneGlue currentlyInstalledVersion]; | 1089 NSString* version = [keystoneGlue currentlyInstalledVersion]; |
1142 return base::SysNSStringToUTF16(version); | 1090 return base::SysNSStringToUTF16(version); |
1143 } | 1091 } |
1144 | 1092 |
1145 } // namespace keystone_glue | 1093 } // namespace keystone_glue |
OLD | NEW |