OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/cocoa/keystone_glue.h" | 5 #import "chrome/browser/cocoa/keystone_glue.h" |
6 | 6 |
7 #include <sys/param.h> | 7 #include <sys/param.h> |
8 #include <sys/mount.h> | 8 #include <sys/mount.h> |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #import "app/l10n_util_mac.h" | 12 #import "app/l10n_util_mac.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/mac_util.h" | 14 #include "base/mac_util.h" |
| 15 #include "base/sys_string_conversions.h" |
15 #import "base/worker_pool_mac.h" | 16 #import "base/worker_pool_mac.h" |
16 #include "chrome/browser/cocoa/authorization_util.h" | 17 #include "chrome/browser/cocoa/authorization_util.h" |
17 #include "chrome/common/chrome_constants.h" | 18 #include "chrome/common/chrome_constants.h" |
18 #include "grit/chromium_strings.h" | 19 #include "grit/chromium_strings.h" |
19 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 // Provide declarations of the Keystone registration bits needed here. From | 24 // Provide declarations of the Keystone registration bits needed here. From |
24 // KSRegistration.h. | 25 // KSRegistration.h. |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 - (void)registrationComplete:(NSNotification*)notification; | 120 - (void)registrationComplete:(NSNotification*)notification; |
120 | 121 |
121 // Called periodically to announce activity by pinging the Keystone server. | 122 // Called periodically to announce activity by pinging the Keystone server. |
122 - (void)markActive:(NSTimer*)timer; | 123 - (void)markActive:(NSTimer*)timer; |
123 | 124 |
124 // 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 |
125 // kAutoupdateStatusNotification notification to the default notification | 126 // kAutoupdateStatusNotification notification to the default notification |
126 // center. | 127 // center. |
127 - (void)updateStatus:(AutoupdateStatus)status version:(NSString*)version; | 128 - (void)updateStatus:(AutoupdateStatus)status version:(NSString*)version; |
128 | 129 |
| 130 // Returns the version of the currently-installed application on disk. |
| 131 - (NSString*)currentlyInstalledVersion; |
| 132 |
129 // These three methods are used to determine the version of the application | 133 // These three methods are used to determine the version of the application |
130 // currently installed on disk, compare that to the currently-running version, | 134 // currently installed on disk, compare that to the currently-running version, |
131 // decide whether any updates have been installed, and call | 135 // decide whether any updates have been installed, and call |
132 // -updateStatus:version:. | 136 // -updateStatus:version:. |
133 // | 137 // |
134 // In order to check the version on disk, the installed application's | 138 // In order to check the version on disk, the installed application's |
135 // Info.plist dictionary must be read; in order to see changes as updates are | 139 // Info.plist dictionary must be read; in order to see changes as updates are |
136 // applied, the dictionary must be read each time, bypassing any caches such | 140 // applied, the dictionary must be read each time, bypassing any caches such |
137 // as the one that NSBundle might be maintaining. Reading files can be a | 141 // as the one that NSBundle might be maintaining. Reading files can be a |
138 // blocking operation, and blocking operations are to be avoided on the main | 142 // blocking operation, and blocking operations are to be avoided on the main |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 [self updateStatus:kAutoupdateInstallFailed version:nil]; | 543 [self updateStatus:kAutoupdateInstallFailed version:nil]; |
540 } else { | 544 } else { |
541 updateSuccessfullyInstalled_ = YES; | 545 updateSuccessfullyInstalled_ = YES; |
542 | 546 |
543 // Nothing in the notification dictionary reports the version that was | 547 // Nothing in the notification dictionary reports the version that was |
544 // installed. Figure it out based on what's on disk. | 548 // installed. Figure it out based on what's on disk. |
545 [self determineUpdateStatusAsync]; | 549 [self determineUpdateStatusAsync]; |
546 } | 550 } |
547 } | 551 } |
548 | 552 |
| 553 - (NSString*)currentlyInstalledVersion { |
| 554 NSString* appInfoPlistPath = [self appInfoPlistPath]; |
| 555 NSDictionary* infoPlist = |
| 556 [NSDictionary dictionaryWithContentsOfFile:appInfoPlistPath]; |
| 557 return [infoPlist objectForKey:@"CFBundleShortVersionString"]; |
| 558 } |
| 559 |
549 // Runs on the main thread. | 560 // Runs on the main thread. |
550 - (void)determineUpdateStatusAsync { | 561 - (void)determineUpdateStatusAsync { |
551 DCHECK([NSThread isMainThread]); | 562 DCHECK([NSThread isMainThread]); |
552 | 563 |
553 SEL selector = @selector(determineUpdateStatus); | 564 SEL selector = @selector(determineUpdateStatus); |
554 NSInvocationOperation* operation = | 565 NSInvocationOperation* operation = |
555 [[[NSInvocationOperation alloc] initWithTarget:self | 566 [[[NSInvocationOperation alloc] initWithTarget:self |
556 selector:selector | 567 selector:selector |
557 object:nil] autorelease]; | 568 object:nil] autorelease]; |
558 | 569 |
559 NSOperationQueue* operationQueue = [WorkerPoolObjC sharedOperationQueue]; | 570 NSOperationQueue* operationQueue = [WorkerPoolObjC sharedOperationQueue]; |
560 [operationQueue addOperation:operation]; | 571 [operationQueue addOperation:operation]; |
561 } | 572 } |
562 | 573 |
563 // Runs on a thread managed by NSOperationQueue. | 574 // Runs on a thread managed by NSOperationQueue. |
564 - (void)determineUpdateStatus { | 575 - (void)determineUpdateStatus { |
565 DCHECK(![NSThread isMainThread]); | 576 DCHECK(![NSThread isMainThread]); |
566 | 577 |
567 NSString* appInfoPlistPath = [self appInfoPlistPath]; | 578 NSString* version = [self currentlyInstalledVersion]; |
568 NSDictionary* infoPlist = | |
569 [NSDictionary dictionaryWithContentsOfFile:appInfoPlistPath]; | |
570 NSString* version = [infoPlist objectForKey:@"CFBundleShortVersionString"]; | |
571 | 579 |
572 [self performSelectorOnMainThread:@selector(determineUpdateStatusForVersion:) | 580 [self performSelectorOnMainThread:@selector(determineUpdateStatusForVersion:) |
573 withObject:version | 581 withObject:version |
574 waitUntilDone:NO]; | 582 waitUntilDone:NO]; |
575 } | 583 } |
576 | 584 |
577 // Runs on the main thread. | 585 // Runs on the main thread. |
578 - (void)determineUpdateStatusForVersion:(NSString*)version { | 586 - (void)determineUpdateStatusForVersion:(NSString*)version { |
579 DCHECK([NSThread isMainThread]); | 587 DCHECK([NSThread isMainThread]); |
580 | 588 |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
891 } | 899 } |
892 | 900 |
893 - (void)setAppPath:(NSString*)appPath { | 901 - (void)setAppPath:(NSString*)appPath { |
894 if (appPath != appPath_) { | 902 if (appPath != appPath_) { |
895 [appPath_ release]; | 903 [appPath_ release]; |
896 appPath_ = [appPath copy]; | 904 appPath_ = [appPath copy]; |
897 } | 905 } |
898 } | 906 } |
899 | 907 |
900 @end // @implementation KeystoneGlue | 908 @end // @implementation KeystoneGlue |
| 909 |
| 910 namespace keystone_glue { |
| 911 |
| 912 bool KeystoneEnabled() { |
| 913 return [KeystoneGlue defaultKeystoneGlue] != nil; |
| 914 } |
| 915 |
| 916 string16 CurrentlyInstalledVersion() { |
| 917 KeystoneGlue* keystoneGlue = [KeystoneGlue defaultKeystoneGlue]; |
| 918 NSString* version = [keystoneGlue currentlyInstalledVersion]; |
| 919 return base::SysNSStringToUTF16(version); |
| 920 } |
| 921 |
| 922 } // namespace keystone_glue |
OLD | NEW |