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

Side by Side Diff: chrome/browser/mac/keystone_glue.mm

Issue 593243002: Profile_Metrics integration with Keystone (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 9 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
« no previous file with comments | « chrome/browser/mac/keystone_glue.h ('k') | chrome/browser/mac/keystone_glue_unittest.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #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
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 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 NSBundle* ksrBundle = [NSBundle bundleWithPath:ksrPath]; 441 NSBundle* ksrBundle = [NSBundle bundleWithPath:ksrPath];
439 [ksrBundle load]; 442 [ksrBundle load];
440 443
441 // Harness the KSRegistration class. 444 // Harness the KSRegistration class.
442 Class ksrClass = [ksrBundle classNamed:@"KSRegistration"]; 445 Class ksrClass = [ksrBundle classNamed:@"KSRegistration"];
443 KSRegistration* ksr = [ksrClass registrationWithProductID:productID_]; 446 KSRegistration* ksr = [ksrClass registrationWithProductID:productID_];
444 if (!ksr) 447 if (!ksr)
445 return NO; 448 return NO;
446 449
447 registration_ = [ksr retain]; 450 registration_ = [ksr retain];
451 ksUnsignedReportingAttributeClass_ =
452 [ksrBundle classNamed:@"KSUnsignedReportingAttribute"];
448 return YES; 453 return YES;
449 } 454 }
450 455
451 - (NSString*)appInfoPlistPath { 456 - (NSString*)appInfoPlistPath {
452 // NSBundle ought to have a way to access this path directly, but it 457 // NSBundle ought to have a way to access this path directly, but it
453 // doesn't. 458 // doesn't.
454 return [[appPath_ stringByAppendingPathComponent:@"Contents"] 459 return [[appPath_ stringByAppendingPathComponent:@"Contents"]
455 stringByAppendingPathComponent:@"Info.plist"]; 460 stringByAppendingPathComponent:@"Info.plist"];
456 } 461 }
457 462
(...skipping 26 matching lines...) Expand all
484 url_, ksr::KSRegistrationServerURLStringKey, 489 url_, ksr::KSRegistrationServerURLStringKey,
485 preserveTTToken, ksr::KSRegistrationPreserveTrustedTesterTokenKey, 490 preserveTTToken, ksr::KSRegistrationPreserveTrustedTesterTokenKey,
486 tagValue, ksr::KSRegistrationTagKey, 491 tagValue, ksr::KSRegistrationTagKey,
487 appInfoPlistPath, ksr::KSRegistrationTagPathKey, 492 appInfoPlistPath, ksr::KSRegistrationTagPathKey,
488 tagKey, ksr::KSRegistrationTagKeyKey, 493 tagKey, ksr::KSRegistrationTagKeyKey,
489 brandPath, ksr::KSRegistrationBrandPathKey, 494 brandPath, ksr::KSRegistrationBrandPathKey,
490 brandKey, ksr::KSRegistrationBrandKeyKey, 495 brandKey, ksr::KSRegistrationBrandKeyKey,
491 nil]; 496 nil];
492 } 497 }
493 498
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
494 - (void)registerWithKeystone { 540 - (void)registerWithKeystone {
495 [self updateStatus:kAutoupdateRegistering version:nil]; 541 [self updateStatus:kAutoupdateRegistering version:nil];
496 542
497 NSDictionary* parameters = [self keystoneParameters]; 543 NSDictionary* parameters = [self keystoneParameters];
498 BOOL result; 544 BOOL result;
499 { 545 {
500 // TODO(shess): Allows Keystone to throw an exception when 546 // TODO(shess): Allows Keystone to throw an exception when
501 // /usr/bin/python does not exist (really!). 547 // /usr/bin/python does not exist (really!).
502 // http://crbug.com/86221 and http://crbug.com/87931 548 // http://crbug.com/86221 and http://crbug.com/87931
503 base::mac::ScopedNSExceptionEnabler enabler; 549 base::mac::ScopedNSExceptionEnabler enabler;
504 result = [registration_ registerWithParameters:parameters]; 550 result = [registration_ registerWithParameters:parameters];
505 } 551 }
506 if (!result) { 552 if (!result) {
507 [self updateStatus:kAutoupdateRegisterFailed version:nil]; 553 [self updateStatus:kAutoupdateRegisterFailed version:nil];
508 return; 554 return;
509 } 555 }
510 556
511 // Upon completion, ksr::KSRegistrationDidCompleteNotification will be 557 // Upon completion, ksr::KSRegistrationDidCompleteNotification will be
512 // posted, and -registrationComplete: will be called. 558 // posted, and -registrationComplete: will be called.
513 559
514 // Mark an active RIGHT NOW; don't wait an hour for the first one. 560 // Mark an active RIGHT NOW; don't wait an hour for the first one.
515 [registration_ setActive]; 561 [self setRegistrationActive];
516 562
517 // Set up hourly activity pings. 563 // Set up hourly activity pings.
518 timer_ = [NSTimer scheduledTimerWithTimeInterval:60 * 60 // One hour 564 timer_ = [NSTimer scheduledTimerWithTimeInterval:60 * 60 // One hour
519 target:self 565 target:self
520 selector:@selector(markActive:) 566 selector:@selector(markActive:)
521 userInfo:registration_ 567 userInfo:nil
522 repeats:YES]; 568 repeats:YES];
523 } 569 }
524 570
525 - (void)registrationComplete:(NSNotification*)notification { 571 - (void)registrationComplete:(NSNotification*)notification {
526 NSDictionary* userInfo = [notification userInfo]; 572 NSDictionary* userInfo = [notification userInfo];
527 if ([[userInfo objectForKey:ksr::KSRegistrationStatusKey] boolValue]) { 573 if ([[userInfo objectForKey:ksr::KSRegistrationStatusKey] boolValue]) {
528 if ([self isSystemTicketDoomed]) { 574 if ([self isSystemTicketDoomed]) {
529 [self updateStatus:kAutoupdateNeedsPromotion version:nil]; 575 [self updateStatus:kAutoupdateNeedsPromotion version:nil];
530 } else { 576 } else {
531 [self updateStatus:kAutoupdateRegistered version:nil]; 577 [self updateStatus:kAutoupdateRegistered version:nil];
532 } 578 }
533 } else { 579 } else {
534 // Dump registration_? 580 // Dump registration_?
535 [self updateStatus:kAutoupdateRegisterFailed version:nil]; 581 [self updateStatus:kAutoupdateRegisterFailed version:nil];
536 } 582 }
537 } 583 }
538 584
539 - (void)stopTimer { 585 - (void)stopTimer {
540 [timer_ invalidate]; 586 [timer_ invalidate];
541 } 587 }
542 588
543 - (void)markActive:(NSTimer*)timer { 589 - (void)markActive:(NSTimer*)timer {
544 KSRegistration* ksr = [timer userInfo]; 590 [self setRegistrationActive];
545 [ksr setActive];
546 } 591 }
547 592
548 - (void)checkForUpdate { 593 - (void)checkForUpdate {
549 DCHECK(![self asyncOperationPending]); 594 DCHECK(![self asyncOperationPending]);
550 595
551 if (!registration_) { 596 if (!registration_) {
552 [self updateStatus:kAutoupdateCheckFailed version:nil]; 597 [self updateStatus:kAutoupdateCheckFailed version:nil];
553 return; 598 return;
554 } 599 }
555 600
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
1042 NSString* tagSuffix = @""; 1087 NSString* tagSuffix = @"";
1043 if (ObsoleteSystemMac::Has32BitOnlyCPU()) { 1088 if (ObsoleteSystemMac::Has32BitOnlyCPU()) {
1044 tagSuffix = [tagSuffix stringByAppendingString:@"-32bit"]; 1089 tagSuffix = [tagSuffix stringByAppendingString:@"-32bit"];
1045 } 1090 }
1046 if ([self wantsFullInstaller]) { 1091 if ([self wantsFullInstaller]) {
1047 tagSuffix = [tagSuffix stringByAppendingString:@"-full"]; 1092 tagSuffix = [tagSuffix stringByAppendingString:@"-full"];
1048 } 1093 }
1049 return tagSuffix; 1094 return tagSuffix;
1050 } 1095 }
1051 1096
1097
1098 - (void)updateProfileCountsWithNumProfiles:(uint32_t)profiles
1099 numSignedInProfiles:(uint32_t)signedInProfiles {
1100 numProfiles_ = profiles;
1101 numSignedInProfiles_ = signedInProfiles;
1102 }
1103
1052 @end // @implementation KeystoneGlue 1104 @end // @implementation KeystoneGlue
1053 1105
1054 namespace { 1106 namespace {
1055 1107
1056 std::string BrandCodeInternal() { 1108 std::string BrandCodeInternal() {
1057 KeystoneGlue* keystone_glue = [KeystoneGlue defaultKeystoneGlue]; 1109 KeystoneGlue* keystone_glue = [KeystoneGlue defaultKeystoneGlue];
1058 NSString* brand_path = [keystone_glue brandFilePath]; 1110 NSString* brand_path = [keystone_glue brandFilePath];
1059 1111
1060 if (![brand_path length]) 1112 if (![brand_path length])
1061 return std::string(); 1113 return std::string();
(...skipping 22 matching lines...) Expand all
1084 return [KeystoneGlue defaultKeystoneGlue] != nil; 1136 return [KeystoneGlue defaultKeystoneGlue] != nil;
1085 } 1137 }
1086 1138
1087 base::string16 CurrentlyInstalledVersion() { 1139 base::string16 CurrentlyInstalledVersion() {
1088 KeystoneGlue* keystoneGlue = [KeystoneGlue defaultKeystoneGlue]; 1140 KeystoneGlue* keystoneGlue = [KeystoneGlue defaultKeystoneGlue];
1089 NSString* version = [keystoneGlue currentlyInstalledVersion]; 1141 NSString* version = [keystoneGlue currentlyInstalledVersion];
1090 return base::SysNSStringToUTF16(version); 1142 return base::SysNSStringToUTF16(version);
1091 } 1143 }
1092 1144
1093 } // namespace keystone_glue 1145 } // namespace keystone_glue
OLDNEW
« no previous file with comments | « chrome/browser/mac/keystone_glue.h ('k') | chrome/browser/mac/keystone_glue_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698