| 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 #ifndef CHROME_APP_KEYSTONE_GLUE_H_ | 5 #ifndef CHROME_APP_KEYSTONE_GLUE_H_ |
| 6 #define CHROME_APP_KEYSTONE_GLUE_H_ | 6 #define CHROME_APP_KEYSTONE_GLUE_H_ |
| 7 | 7 |
| 8 #import <Foundation/Foundation.h> | 8 #import <Foundation/Foundation.h> |
| 9 #import <base/scoped_nsobject.h> |
| 9 | 10 |
| 10 // Objects which request callbacks from KeystoneGlue (e.g. information | 11 // Possible outcomes of -checkForUpdate and -installUpdate. A version may |
| 11 // on update availability) should implement this protocol. All callbacks | 12 // accompany some of these, but beware: a version is never required. For |
| 12 // require the caller to be spinning in the runloop to happen. | 13 // statuses that can be accompanied by a version, the comment indicates what |
| 13 @protocol KeystoneGlueCallbacks | 14 // version is referenced. |
| 15 enum AutoupdateStatus { |
| 16 kAutoupdateCurrent = 0, // version of the running application |
| 17 kAutoupdateAvailable, // version of the update that is available |
| 18 kAutoupdateInstalled, // version of the update that was installed |
| 19 kAutoupdateCheckFailed, // no version |
| 20 kAutoupdateInstallFailed // no version |
| 21 }; |
| 14 | 22 |
| 15 // Callback when a checkForUpdate completes. | 23 // kAutoupdateStatusNotification is the name of the notification posted when |
| 16 // |latestVersion| may be nil if not returned from the server. | 24 // -checkForUpdate and -installUpdate complete. This notification will be |
| 17 // |latestVersion| is not a localizable string. | 25 // sent with with its sender object set to the KeystoneGlue instance sending |
| 18 - (void)upToDateCheckCompleted:(BOOL)upToDate | 26 // the notification. Its userInfo dictionary will contain an AutoupdateStatus |
| 19 latestVersion:(NSString*)latestVersion; | 27 // value as an intValue at key kAutoupdateStatusStatus. If a version is |
| 20 | 28 // available (see AutoupdateStatus), it will be present at key |
| 21 // Callback when a startUpdate completes. | 29 // kAutoupdateStatusVersion. |
| 22 // |successful| tells if the *check* was successful. This does not | 30 extern const NSString* const kAutoupdateStatusNotification; |
| 23 // necessarily mean updates installed successfully. | 31 extern const NSString* const kAutoupdateStatusStatus; |
| 24 // |installs| tells the number of updates that installed successfully | 32 extern const NSString* const kAutoupdateStatusVersion; |
| 25 // (typically 0 or 1). | |
| 26 - (void)updateCompleted:(BOOL)successful installs:(int)installs; | |
| 27 | |
| 28 @end // protocol KeystoneGlueCallbacks | |
| 29 | |
| 30 | 33 |
| 31 // KeystoneGlue is an adapter around the KSRegistration class, allowing it to | 34 // KeystoneGlue is an adapter around the KSRegistration class, allowing it to |
| 32 // be used without linking directly against its containing KeystoneRegistration | 35 // be used without linking directly against its containing KeystoneRegistration |
| 33 // framework. This is used in an environment where most builds (such as | 36 // framework. This is used in an environment where most builds (such as |
| 34 // developer builds) don't want or need Keystone support and might not even | 37 // developer builds) don't want or need Keystone support and might not even |
| 35 // have the framework available. Enabling Keystone support in an application | 38 // have the framework available. Enabling Keystone support in an application |
| 36 // that uses KeystoneGlue is as simple as dropping | 39 // that uses KeystoneGlue is as simple as dropping |
| 37 // KeystoneRegistration.framework in the application's Frameworks directory | 40 // KeystoneRegistration.framework in the application's Frameworks directory |
| 38 // and providing the relevant information in its Info.plist. KeystoneGlue | 41 // and providing the relevant information in its Info.plist. KeystoneGlue |
| 39 // requires that the KSUpdateURL key be set in the application's Info.plist, | 42 // requires that the KSUpdateURL key be set in the application's Info.plist, |
| 40 // and that it contain a string identifying the update URL to be used by | 43 // and that it contain a string identifying the update URL to be used by |
| 41 // Keystone. | 44 // Keystone. |
| 42 | 45 |
| 43 @class KSRegistration; | 46 @class KSRegistration; |
| 44 | 47 |
| 45 @interface KeystoneGlue : NSObject { | 48 @interface KeystoneGlue : NSObject { |
| 46 @protected | 49 @protected |
| 47 | 50 |
| 48 // Data for Keystone registration | 51 // Data for Keystone registration |
| 49 NSString* url_; | 52 NSString* url_; |
| 50 NSString* productID_; | 53 NSString* productID_; |
| 51 NSString* version_; | 54 NSString* version_; |
| 52 NSString* channel_; // Logically: Dev, Beta, or Stable. | 55 NSString* channel_; // Logically: Dev, Beta, or Stable. |
| 53 | 56 |
| 54 // And the Keystone registration itself, with the active timer | 57 // And the Keystone registration itself, with the active timer |
| 55 KSRegistration* registration_; // strong | 58 KSRegistration* registration_; // strong |
| 56 NSTimer* timer_; // strong | 59 NSTimer* timer_; // strong |
| 57 | 60 |
| 58 // Data for callbacks, all strong. Deallocated (if needed) in a | 61 // The most recent kAutoupdateStatusNotification notification posted. |
| 59 // NSNotificationCenter callback. | 62 scoped_nsobject<NSNotification> recentNotification_; |
| 60 NSObject<KeystoneGlueCallbacks>* startTarget_; | 63 |
| 61 NSObject<KeystoneGlueCallbacks>* checkTarget_; | 64 // YES if an update was ever successfully installed by -installUpdate. |
| 65 BOOL updateSuccessfullyInstalled_; |
| 62 } | 66 } |
| 63 | 67 |
| 64 // Return the default Keystone Glue object. | 68 // Return the default Keystone Glue object. |
| 65 + (id)defaultKeystoneGlue; | 69 + (id)defaultKeystoneGlue; |
| 66 | 70 |
| 67 // Load KeystoneRegistration.framework if present, call into it to register | 71 // Load KeystoneRegistration.framework if present, call into it to register |
| 68 // with Keystone, and set up periodic activity pings. | 72 // with Keystone, and set up periodic activity pings. |
| 69 - (void)registerWithKeystone; | 73 - (void)registerWithKeystone; |
| 70 | 74 |
| 71 // Check if updates are available. | 75 // -checkForUpdate launches a check for updates, and -installUpdate begins |
| 72 // upToDateCheckCompleted:: called on target when done. | 76 // installing an available update. For each, status will be communicated via |
| 73 // Return NO if we could not start the check. | 77 // a kAutoupdateStatusNotification notification, and will also be available |
| 74 - (BOOL)checkForUpdate:(NSObject<KeystoneGlueCallbacks>*)target; | 78 // through -recentUpdateStatus. |
| 79 - (void)checkForUpdate; |
| 80 - (void)installUpdate; |
| 75 | 81 |
| 76 // Start an update. | 82 // Accessor for recentNotification_. Returns an autoreleased NSNotification. |
| 77 // updateCompleted:: called on target when done. | 83 - (NSNotification*)recentNotification; |
| 78 // This cannot be cancelled. | |
| 79 // Return NO if we could not start the check. | |
| 80 - (BOOL)startUpdate:(NSObject<KeystoneGlueCallbacks>*)target; | |
| 81 | 84 |
| 82 @end // KeystoneGlue | 85 // Clears the saved recentNotification_. |
| 86 - (void)clearRecentNotification; |
| 83 | 87 |
| 88 @end // @interface KeystoneGlue |
| 84 | 89 |
| 85 @interface KeystoneGlue (ExposedForTesting) | 90 @interface KeystoneGlue(ExposedForTesting) |
| 91 |
| 92 // Release the shared instance. Use this in tests to reset the shared |
| 93 // instance in case strange things are done to it for testing purposes. Never |
| 94 // call this from non-test code. |
| 95 + (void)releaseDefaultKeystoneGlue; |
| 86 | 96 |
| 87 // Load any params we need for configuring Keystone. | 97 // Load any params we need for configuring Keystone. |
| 88 - (void)loadParameters; | 98 - (void)loadParameters; |
| 89 | 99 |
| 90 // Load the Keystone registration object. | 100 // Load the Keystone registration object. |
| 91 // Return NO on failure. | 101 // Return NO on failure. |
| 92 - (BOOL)loadKeystoneRegistration; | 102 - (BOOL)loadKeystoneRegistration; |
| 93 | 103 |
| 94 - (void)stopTimer; | 104 - (void)stopTimer; |
| 95 | 105 |
| 96 // Called when a checkForUpdate: notification completes. | 106 // Called when a checkForUpdate: notification completes. |
| 97 - (void)checkComplete:(NSNotification *)notification; | 107 - (void)checkForUpdateComplete:(NSNotification*)notification; |
| 98 | 108 |
| 99 // Called when a startUpdate: notification completes. | 109 // Called when an installUpdate: notification completes. |
| 100 - (void)startUpdateComplete:(NSNotification *)notification; | 110 - (void)installUpdateComplete:(NSNotification*)notification; |
| 101 | 111 |
| 102 @end // KeystoneGlue (ExposedForTesting) | 112 @end // @interface KeystoneGlue(ExposedForTesting) |
| 103 | 113 |
| 104 #endif // CHROME_APP_KEYSTONE_GLUE_H_ | 114 #endif // CHROME_APP_KEYSTONE_GLUE_H_ |
| OLD | NEW |