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; | |
|
Mark Mentovai
2014/10/02 16:07:23
Why is this taking ksr as a parameter when registr
Mike Lerman
2014/10/06 16:49:08
when it's called from markActive (when the timer t
Mark Mentovai
2014/10/06 18:35:13
Mike Lerman wrote:
Mike Lerman
2014/10/09 20:41:01
Ok, removed it, now referencing the object's regis
| |
| 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 (numProfiles_ == 0) { | |
| 500 [ksr setActive]; | |
| 501 return; | |
|
Boris Vidolov
2014/09/26 20:57:00
This will break in the following case:
1. User A (
Mike Lerman
2014/10/06 16:49:08
In step 2 here, after signing out, numAccounts wil
| |
| 502 } | |
| 503 | |
| 504 NSError* reportingAttributeError = nil; | |
| 505 KSUnsignedReportingAttribute* numProfilesAttribute = | |
| 506 [KSUnsignedReportingAttribute | |
| 507 reportingAttributeWithValue:numProfiles_ | |
| 508 name:@"_NumAccounts" | |
| 509 aggregationType:kKSReportingAggregationSum | |
| 510 error:&reportingAttributeError]; | |
| 511 if (reportingAttributeError != nil) { | |
| 512 LOG(ERROR) << [reportingAttributeError localizedDescription]; | |
| 513 [ksr setActive]; | |
| 514 return; | |
| 515 } | |
| 516 | |
| 517 KSUnsignedReportingAttribute* numSignedInProfilesAttribute = | |
| 518 [KSUnsignedReportingAttribute | |
| 519 reportingAttributeWithValue:numSignedInProfiles_ | |
| 520 name:@"_NumSignedIn" | |
| 521 aggregationType:kKSReportingAggregationSum | |
| 522 error:&reportingAttributeError]; | |
| 523 if (reportingAttributeError != nil) { | |
| 524 LOG(ERROR) << [reportingAttributeError localizedDescription]; | |
| 525 [ksr setActive]; | |
| 526 return; | |
| 527 } | |
| 528 | |
| 529 NSArray* profileCountsInformation = | |
| 530 [NSArray arrayWithObjects:numProfilesAttribute, | |
| 531 numSignedInProfilesAttribute, | |
| 532 nil]; | |
| 533 | |
| 534 NSError* setActiveError = nil; | |
| 535 if (![ksr setActiveWithReportingAttributes:profileCountsInformation | |
| 536 error:&setActiveError]) | |
| 537 LOG(ERROR) << [setActiveError localizedDescription]; | |
| 538 [ksr setActive]; | |
| 539 } | |
| 540 } | |
| 541 | |
| 494 - (void)registerWithKeystone { | 542 - (void)registerWithKeystone { |
| 495 [self updateStatus:kAutoupdateRegistering version:nil]; | 543 [self updateStatus:kAutoupdateRegistering version:nil]; |
| 496 | 544 |
| 497 NSDictionary* parameters = [self keystoneParameters]; | 545 NSDictionary* parameters = [self keystoneParameters]; |
| 498 BOOL result; | 546 BOOL result; |
| 499 { | 547 { |
| 500 // TODO(shess): Allows Keystone to throw an exception when | 548 // TODO(shess): Allows Keystone to throw an exception when |
| 501 // /usr/bin/python does not exist (really!). | 549 // /usr/bin/python does not exist (really!). |
| 502 // http://crbug.com/86221 and http://crbug.com/87931 | 550 // http://crbug.com/86221 and http://crbug.com/87931 |
| 503 base::mac::ScopedNSExceptionEnabler enabler; | 551 base::mac::ScopedNSExceptionEnabler enabler; |
| 504 result = [registration_ registerWithParameters:parameters]; | 552 result = [registration_ registerWithParameters:parameters]; |
| 505 } | 553 } |
| 506 if (!result) { | 554 if (!result) { |
| 507 [self updateStatus:kAutoupdateRegisterFailed version:nil]; | 555 [self updateStatus:kAutoupdateRegisterFailed version:nil]; |
| 508 return; | 556 return; |
| 509 } | 557 } |
| 510 | 558 |
| 511 // Upon completion, ksr::KSRegistrationDidCompleteNotification will be | 559 // Upon completion, ksr::KSRegistrationDidCompleteNotification will be |
| 512 // posted, and -registrationComplete: will be called. | 560 // posted, and -registrationComplete: will be called. |
| 513 | 561 |
| 514 // Mark an active RIGHT NOW; don't wait an hour for the first one. | 562 // Mark an active RIGHT NOW; don't wait an hour for the first one. |
| 515 [registration_ setActive]; | 563 [self setRegistrationActive:registration_]; |
| 516 | 564 |
| 517 // Set up hourly activity pings. | 565 // Set up hourly activity pings. |
| 518 timer_ = [NSTimer scheduledTimerWithTimeInterval:60 * 60 // One hour | 566 timer_ = [NSTimer scheduledTimerWithTimeInterval:60 * 60 // One hour |
| 519 target:self | 567 target:self |
| 520 selector:@selector(markActive:) | 568 selector:@selector(markActive:) |
| 521 userInfo:registration_ | 569 userInfo:registration_ |
| 522 repeats:YES]; | 570 repeats:YES]; |
| 523 } | 571 } |
| 524 | 572 |
| 525 - (void)registrationComplete:(NSNotification*)notification { | 573 - (void)registrationComplete:(NSNotification*)notification { |
| 526 NSDictionary* userInfo = [notification userInfo]; | 574 NSDictionary* userInfo = [notification userInfo]; |
| 527 if ([[userInfo objectForKey:ksr::KSRegistrationStatusKey] boolValue]) { | 575 if ([[userInfo objectForKey:ksr::KSRegistrationStatusKey] boolValue]) { |
| 528 if ([self isSystemTicketDoomed]) { | 576 if ([self isSystemTicketDoomed]) { |
| 529 [self updateStatus:kAutoupdateNeedsPromotion version:nil]; | 577 [self updateStatus:kAutoupdateNeedsPromotion version:nil]; |
| 530 } else { | 578 } else { |
| 531 [self updateStatus:kAutoupdateRegistered version:nil]; | 579 [self updateStatus:kAutoupdateRegistered version:nil]; |
| 532 } | 580 } |
| 533 } else { | 581 } else { |
| 534 // Dump registration_? | 582 // Dump registration_? |
| 535 [self updateStatus:kAutoupdateRegisterFailed version:nil]; | 583 [self updateStatus:kAutoupdateRegisterFailed version:nil]; |
| 536 } | 584 } |
| 537 } | 585 } |
| 538 | 586 |
| 539 - (void)stopTimer { | 587 - (void)stopTimer { |
| 540 [timer_ invalidate]; | 588 [timer_ invalidate]; |
| 541 } | 589 } |
| 542 | 590 |
| 543 - (void)markActive:(NSTimer*)timer { | 591 - (void)markActive:(NSTimer*)timer { |
| 544 KSRegistration* ksr = [timer userInfo]; | 592 [self setRegistrationActive:[timer userInfo]]; |
| 545 [ksr setActive]; | |
| 546 } | 593 } |
| 547 | 594 |
| 548 - (void)checkForUpdate { | 595 - (void)checkForUpdate { |
| 549 DCHECK(![self asyncOperationPending]); | 596 DCHECK(![self asyncOperationPending]); |
| 550 | 597 |
| 551 if (!registration_) { | 598 if (!registration_) { |
| 552 [self updateStatus:kAutoupdateCheckFailed version:nil]; | 599 [self updateStatus:kAutoupdateCheckFailed version:nil]; |
| 553 return; | 600 return; |
| 554 } | 601 } |
| 555 | 602 |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1038 NSString* tagSuffix = @""; | 1085 NSString* tagSuffix = @""; |
| 1039 if (ObsoleteSystemMac::Has32BitOnlyCPU()) { | 1086 if (ObsoleteSystemMac::Has32BitOnlyCPU()) { |
| 1040 tagSuffix = [tagSuffix stringByAppendingString:@"-32bit"]; | 1087 tagSuffix = [tagSuffix stringByAppendingString:@"-32bit"]; |
| 1041 } | 1088 } |
| 1042 if ([self wantsFullInstaller]) { | 1089 if ([self wantsFullInstaller]) { |
| 1043 tagSuffix = [tagSuffix stringByAppendingString:@"-full"]; | 1090 tagSuffix = [tagSuffix stringByAppendingString:@"-full"]; |
| 1044 } | 1091 } |
| 1045 return tagSuffix; | 1092 return tagSuffix; |
| 1046 } | 1093 } |
| 1047 | 1094 |
| 1095 | |
| 1096 - (void)updateProfileCountsWithNumProfiles:(size_t)numProfiles | |
| 1097 numSignedInProfiles:(size_t)numSignedInProfiles { | |
| 1098 numProfiles_ = numProfiles; | |
| 1099 numSignedInProfiles_ = numSignedInProfiles; | |
| 1100 } | |
| 1101 | |
| 1048 @end // @implementation KeystoneGlue | 1102 @end // @implementation KeystoneGlue |
| 1049 | 1103 |
| 1050 namespace { | 1104 namespace { |
| 1051 | 1105 |
| 1052 std::string BrandCodeInternal() { | 1106 std::string BrandCodeInternal() { |
| 1053 KeystoneGlue* keystone_glue = [KeystoneGlue defaultKeystoneGlue]; | 1107 KeystoneGlue* keystone_glue = [KeystoneGlue defaultKeystoneGlue]; |
| 1054 NSString* brand_path = [keystone_glue brandFilePath]; | 1108 NSString* brand_path = [keystone_glue brandFilePath]; |
| 1055 | 1109 |
| 1056 if (![brand_path length]) | 1110 if (![brand_path length]) |
| 1057 return std::string(); | 1111 return std::string(); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 1080 return [KeystoneGlue defaultKeystoneGlue] != nil; | 1134 return [KeystoneGlue defaultKeystoneGlue] != nil; |
| 1081 } | 1135 } |
| 1082 | 1136 |
| 1083 base::string16 CurrentlyInstalledVersion() { | 1137 base::string16 CurrentlyInstalledVersion() { |
| 1084 KeystoneGlue* keystoneGlue = [KeystoneGlue defaultKeystoneGlue]; | 1138 KeystoneGlue* keystoneGlue = [KeystoneGlue defaultKeystoneGlue]; |
| 1085 NSString* version = [keystoneGlue currentlyInstalledVersion]; | 1139 NSString* version = [keystoneGlue currentlyInstalledVersion]; |
| 1086 return base::SysNSStringToUTF16(version); | 1140 return base::SysNSStringToUTF16(version); |
| 1087 } | 1141 } |
| 1088 | 1142 |
| 1089 } // namespace keystone_glue | 1143 } // namespace keystone_glue |
| OLD | NEW |