[email protected] | ef12d1e6 | 2012-03-21 20:55:05 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 5950f571 | 2011-06-20 22:15:52 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_MAC_KEYSTONE_GLUE_H_ |
| 6 | #define CHROME_BROWSER_MAC_KEYSTONE_GLUE_H_ |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 7 | |
[email protected] | f9b29436 | 2013-06-10 20:22:31 | [diff] [blame] | 8 | #include "base/strings/string16.h" |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 9 | |
| 10 | #if defined(__OBJC__) |
| 11 | |
| 12 | #import <Foundation/Foundation.h> |
avi | 6846aef | 2015-12-26 01:09:38 | [diff] [blame] | 13 | #include <stdint.h> |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 14 | |
[email protected] | ef12d1e6 | 2012-03-21 20:55:05 | [diff] [blame] | 15 | #include "base/mac/scoped_authorizationref.h" |
[email protected] | a852203 | 2013-06-24 22:51:46 | [diff] [blame] | 16 | #import "base/mac/scoped_nsobject.h" |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 17 | |
| 18 | // Possible outcomes of various operations. A version may accompany some of |
| 19 | // these, but beware: a version is never required. For statuses that can be |
| 20 | // accompanied by a version, the comment indicates what version is referenced. |
| 21 | // A notification posted containing an asynchronous status will always be |
| 22 | // followed by a notification with a terminal status. |
| 23 | enum AutoupdateStatus { |
| 24 | kAutoupdateNone = 0, // no version (initial state only) |
| 25 | kAutoupdateRegistering, // no version (asynchronous operation in progress) |
| 26 | kAutoupdateRegistered, // no version |
| 27 | kAutoupdateChecking, // no version (asynchronous operation in progress) |
| 28 | kAutoupdateCurrent, // version of the running application |
| 29 | kAutoupdateAvailable, // version of the update that is available |
| 30 | kAutoupdateInstalling, // no version (asynchronous operation in progress) |
| 31 | kAutoupdateInstalled, // version of the update that was installed |
| 32 | kAutoupdatePromoting, // no version (asynchronous operation in progress) |
| 33 | kAutoupdatePromoted, // no version |
| 34 | kAutoupdateRegisterFailed, // no version |
| 35 | kAutoupdateCheckFailed, // no version |
| 36 | kAutoupdateInstallFailed, // no version |
| 37 | kAutoupdatePromoteFailed, // no version |
[email protected] | a2d6774 | 2011-10-18 15:44:10 | [diff] [blame] | 38 | kAutoupdateNeedsPromotion, // no version |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | // kAutoupdateStatusNotification is the name of the notification posted when |
| 42 | // -checkForUpdate and -installUpdate complete. This notification will be |
| 43 | // sent with with its sender object set to the KeystoneGlue instance sending |
| 44 | // the notification. Its userInfo dictionary will contain an AutoupdateStatus |
| 45 | // value as an intValue at key kAutoupdateStatusStatus. If a version is |
| 46 | // available (see AutoupdateStatus), it will be present at key |
ryanmyers | fffe8c740 | 2016-03-25 01:21:16 | [diff] [blame] | 47 | // kAutoupdateStatusVersion. If any error messages were supplied by Keystone, |
| 48 | // they will be present at key kAutoupdateStatusErrorMessages. |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 49 | extern NSString* const kAutoupdateStatusNotification; |
| 50 | extern NSString* const kAutoupdateStatusStatus; |
| 51 | extern NSString* const kAutoupdateStatusVersion; |
ryanmyers | fffe8c740 | 2016-03-25 01:21:16 | [diff] [blame] | 52 | extern NSString* const kAutoupdateStatusErrorMessages; |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 53 | |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 54 | // KeystoneGlue is an adapter around the KSRegistration class, allowing it to |
| 55 | // be used without linking directly against its containing KeystoneRegistration |
| 56 | // framework. This is used in an environment where most builds (such as |
| 57 | // developer builds) don't want or need Keystone support and might not even |
| 58 | // have the framework available. Enabling Keystone support in an application |
| 59 | // that uses KeystoneGlue is as simple as dropping |
| 60 | // KeystoneRegistration.framework in the application's Frameworks directory |
| 61 | // and providing the relevant information in its Info.plist. KeystoneGlue |
| 62 | // requires that the KSUpdateURL key be set in the application's Info.plist, |
| 63 | // and that it contain a string identifying the update URL to be used by |
| 64 | // Keystone. |
| 65 | |
| 66 | @class KSRegistration; |
| 67 | |
| 68 | @interface KeystoneGlue : NSObject { |
| 69 | @protected |
| 70 | |
| 71 | // Data for Keystone registration |
Robert Liao | 44d3ef1 | 2019-12-12 21:04:33 | [diff] [blame] | 72 | base::scoped_nsobject<NSString> _productID; |
| 73 | base::scoped_nsobject<NSString> _appPath; |
| 74 | base::scoped_nsobject<NSString> _url; |
| 75 | base::scoped_nsobject<NSString> _version; |
| 76 | std::string _channel; // Logically: dev, beta, or stable. |
Robert Sesek | 621c3bed | 2018-05-31 18:25:53 | [diff] [blame] | 77 | // Cached location of the brand file. |
Robert Liao | 44d3ef1 | 2019-12-12 21:04:33 | [diff] [blame] | 78 | base::scoped_nsobject<NSString> _brandFile; |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 79 | |
| 80 | // And the Keystone registration itself, with the active timer |
Robert Liao | 44d3ef1 | 2019-12-12 21:04:33 | [diff] [blame] | 81 | base::scoped_nsobject<KSRegistration> _registration; |
| 82 | NSTimer* _timer; // strong |
| 83 | BOOL _registrationActive; |
| 84 | Class _ksUnsignedReportingAttributeClass; |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 85 | |
| 86 | // The most recent kAutoupdateStatusNotification notification posted. |
Robert Liao | 44d3ef1 | 2019-12-12 21:04:33 | [diff] [blame] | 87 | base::scoped_nsobject<NSNotification> _recentNotification; |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 88 | |
| 89 | // The authorization object, when it needs to persist because it's being |
| 90 | // carried across threads. |
Robert Liao | 44d3ef1 | 2019-12-12 21:04:33 | [diff] [blame] | 91 | base::mac::ScopedAuthorizationRef _authorization; |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 92 | |
| 93 | // YES if a synchronous promotion operation is in progress (promotion during |
| 94 | // installation). |
Robert Liao | 44d3ef1 | 2019-12-12 21:04:33 | [diff] [blame] | 95 | BOOL _synchronousPromotion; |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 96 | |
| 97 | // YES if an update was ever successfully installed by -installUpdate. |
Robert Liao | 44d3ef1 | 2019-12-12 21:04:33 | [diff] [blame] | 98 | BOOL _updateSuccessfullyInstalled; |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | // Return the default Keystone Glue object. |
Leonard Grey | 7dd78aa | 2020-02-12 16:01:54 | [diff] [blame] | 102 | + (KeystoneGlue*)defaultKeystoneGlue; |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 103 | |
| 104 | // Load KeystoneRegistration.framework if present, call into it to register |
| 105 | // with Keystone, and set up periodic activity pings. |
| 106 | - (void)registerWithKeystone; |
bcwhite | e930129 | 2015-06-22 15:31:58 | [diff] [blame] | 107 | - (BOOL)isRegisteredAndActive; |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 108 | |
| 109 | // -checkForUpdate launches a check for updates, and -installUpdate begins |
| 110 | // installing an available update. For each, status will be communicated via |
| 111 | // a kAutoupdateStatusNotification notification, and will also be available |
| 112 | // through -recentNotification. |
| 113 | - (void)checkForUpdate; |
| 114 | - (void)installUpdate; |
| 115 | |
| 116 | // Accessor for recentNotification_. Returns an autoreleased NSNotification. |
| 117 | - (NSNotification*)recentNotification; |
| 118 | |
| 119 | // Accessor for the kAutoupdateStatusStatus field of recentNotification_'s |
| 120 | // userInfo dictionary. |
| 121 | - (AutoupdateStatus)recentStatus; |
| 122 | |
| 123 | // Returns YES if an asynchronous operation is pending: if an update check or |
| 124 | // installation attempt is currently in progress. |
| 125 | - (BOOL)asyncOperationPending; |
| 126 | |
| 127 | // Returns YES if the application is running from a read-only filesystem, |
| 128 | // such as a disk image. |
| 129 | - (BOOL)isOnReadOnlyFilesystem; |
| 130 | |
| 131 | // -needsPromotion is YES if the application needs its ticket promoted to |
| 132 | // a system ticket. This will be YES when the application is on a user |
| 133 | // ticket and determines that the current user does not have sufficient |
| 134 | // permission to perform the update. |
| 135 | // |
| 136 | // -wantsPromotion is YES if the application wants its ticket promoted to |
| 137 | // a system ticket, even if it doesn't need it as determined by |
| 138 | // -needsPromotion. -wantsPromotion will always be YES if -needsPromotion is, |
| 139 | // and it will additionally be YES when the application is on a user ticket |
| 140 | // and appears to be installed in a system-wide location such as |
| 141 | // /Applications. |
| 142 | // |
| 143 | // Use -needsPromotion to decide whether to show any update UI at all. If |
| 144 | // it's YES, there's no sense in asking the user to "update now" because it |
| 145 | // will fail given the rights and permissions involved. On the other hand, |
| 146 | // when -needsPromotion is YES, the application can encourage the user to |
| 147 | // promote the ticket so that updates will work properly. |
| 148 | // |
| 149 | // Use -wantsPromotion to decide whether to allow the user to promote. The |
| 150 | // user shouldn't be nagged about promotion on the basis of -wantsPromotion, |
| 151 | // but if it's YES, the user should be allowed to promote the ticket. |
| 152 | - (BOOL)needsPromotion; |
| 153 | - (BOOL)wantsPromotion; |
| 154 | |
dbeam | 3109d3ea | 2016-12-18 07:23:43 | [diff] [blame] | 155 | // -isAutoupdateEnabledForAllUsers indicates whether or not autoupdate is |
| 156 | // turned on for all users. |
| 157 | - (BOOL)isAutoupdateEnabledForAllUsers; |
| 158 | |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 159 | // Promotes the Keystone ticket into the system store. System Keystone will |
| 160 | // be installed if necessary. If synchronous is NO, the promotion may occur |
| 161 | // in the background. synchronous should be YES for promotion during |
| 162 | // installation. The KeystoneGlue object assumes ownership of |
Robert Sesek | 4322a53d | 2018-06-12 01:40:06 | [diff] [blame] | 163 | // |anAuthorization|. |
| 164 | - (void)promoteTicketWithAuthorization:(AuthorizationRef)anAuthorization |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 165 | synchronous:(BOOL)synchronous; |
| 166 | |
| 167 | // Requests authorization and calls -promoteTicketWithAuthorization: in |
| 168 | // asynchronous mode. |
| 169 | - (void)promoteTicket; |
| 170 | |
Joshua Pawlicki | 9fbc841 | 2019-03-20 16:05:12 | [diff] [blame] | 171 | // Set the registration active. |
| 172 | - (void)setRegistrationActive; |
| 173 | |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 174 | // Sets a new value for appPath. Used during installation to point a ticket |
| 175 | // at the installed copy. |
| 176 | - (void)setAppPath:(NSString*)appPath; |
| 177 | |
| 178 | @end // @interface KeystoneGlue |
| 179 | |
| 180 | @interface KeystoneGlue(ExposedForTesting) |
| 181 | |
| 182 | // Load any params we need for configuring Keystone. |
| 183 | - (void)loadParameters; |
| 184 | |
| 185 | // Load the Keystone registration object. |
| 186 | // Return NO on failure. |
| 187 | - (BOOL)loadKeystoneRegistration; |
| 188 | |
| 189 | - (void)stopTimer; |
| 190 | |
| 191 | // Called when a checkForUpdate: notification completes. |
| 192 | - (void)checkForUpdateComplete:(NSNotification*)notification; |
| 193 | |
| 194 | // Called when an installUpdate: notification completes. |
| 195 | - (void)installUpdateComplete:(NSNotification*)notification; |
| 196 | |
| 197 | @end // @interface KeystoneGlue(ExposedForTesting) |
| 198 | |
| 199 | #endif // __OBJC__ |
| 200 | |
| 201 | // Functions that may be accessed from non-Objective-C C/C++ code. |
| 202 | namespace keystone_glue { |
| 203 | |
[email protected] | c9c1512 | 2011-08-30 14:24:01 | [diff] [blame] | 204 | // Returns the brand code of the installation. Note that beta, dev, and canary |
| 205 | // channels, as well as some stable builds, may have an empty string as a brand |
| 206 | // code. |
| 207 | std::string BrandCode(); |
| 208 | |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 209 | // True if Keystone is enabled. |
| 210 | bool KeystoneEnabled(); |
| 211 | |
| 212 | // The version of the application currently installed on disk. |
[email protected] | 6a72a63 | 2013-12-12 22:22:00 | [diff] [blame] | 213 | base::string16 CurrentlyInstalledVersion(); |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 214 | |
| 215 | } // namespace keystone_glue |
| 216 | |
[email protected] | 5950f571 | 2011-06-20 22:15:52 | [diff] [blame] | 217 | #endif // CHROME_BROWSER_MAC_KEYSTONE_GLUE_H_ |