blob: dba4bd124d9312f6a03c9bf9cffa683ebc8cffa6 [file] [log] [blame]
[email protected]ef12d1e62012-03-21 20:55:051// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]7d791652010-12-01 16:34:492// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]5950f5712011-06-20 22:15:525#ifndef CHROME_BROWSER_MAC_KEYSTONE_GLUE_H_
6#define CHROME_BROWSER_MAC_KEYSTONE_GLUE_H_
[email protected]7d791652010-12-01 16:34:497
[email protected]f9b294362013-06-10 20:22:318#include "base/strings/string16.h"
[email protected]7d791652010-12-01 16:34:499
10#if defined(__OBJC__)
11
12#import <Foundation/Foundation.h>
avi6846aef2015-12-26 01:09:3813#include <stdint.h>
[email protected]7d791652010-12-01 16:34:4914
[email protected]ef12d1e62012-03-21 20:55:0515#include "base/mac/scoped_authorizationref.h"
[email protected]a8522032013-06-24 22:51:4616#import "base/mac/scoped_nsobject.h"
Avi Drissmance903ee2019-04-12 15:09:3017#include "chrome/common/mac/staging_watcher.h"
[email protected]7d791652010-12-01 16:34:4918
19// Possible outcomes of various operations. A version may accompany some of
20// these, but beware: a version is never required. For statuses that can be
21// accompanied by a version, the comment indicates what version is referenced.
22// A notification posted containing an asynchronous status will always be
23// followed by a notification with a terminal status.
24enum AutoupdateStatus {
25 kAutoupdateNone = 0, // no version (initial state only)
26 kAutoupdateRegistering, // no version (asynchronous operation in progress)
27 kAutoupdateRegistered, // no version
28 kAutoupdateChecking, // no version (asynchronous operation in progress)
29 kAutoupdateCurrent, // version of the running application
30 kAutoupdateAvailable, // version of the update that is available
31 kAutoupdateInstalling, // no version (asynchronous operation in progress)
32 kAutoupdateInstalled, // version of the update that was installed
33 kAutoupdatePromoting, // no version (asynchronous operation in progress)
34 kAutoupdatePromoted, // no version
35 kAutoupdateRegisterFailed, // no version
36 kAutoupdateCheckFailed, // no version
37 kAutoupdateInstallFailed, // no version
38 kAutoupdatePromoteFailed, // no version
[email protected]a2d67742011-10-18 15:44:1039 kAutoupdateNeedsPromotion, // no version
[email protected]7d791652010-12-01 16:34:4940};
41
42// kAutoupdateStatusNotification is the name of the notification posted when
43// -checkForUpdate and -installUpdate complete. This notification will be
44// sent with with its sender object set to the KeystoneGlue instance sending
45// the notification. Its userInfo dictionary will contain an AutoupdateStatus
46// value as an intValue at key kAutoupdateStatusStatus. If a version is
47// available (see AutoupdateStatus), it will be present at key
ryanmyersfffe8c7402016-03-25 01:21:1648// kAutoupdateStatusVersion. If any error messages were supplied by Keystone,
49// they will be present at key kAutoupdateStatusErrorMessages.
[email protected]7d791652010-12-01 16:34:4950extern NSString* const kAutoupdateStatusNotification;
51extern NSString* const kAutoupdateStatusStatus;
52extern NSString* const kAutoupdateStatusVersion;
ryanmyersfffe8c7402016-03-25 01:21:1653extern NSString* const kAutoupdateStatusErrorMessages;
[email protected]7d791652010-12-01 16:34:4954
[email protected]7d791652010-12-01 16:34:4955// KeystoneGlue is an adapter around the KSRegistration class, allowing it to
56// be used without linking directly against its containing KeystoneRegistration
57// framework. This is used in an environment where most builds (such as
58// developer builds) don't want or need Keystone support and might not even
59// have the framework available. Enabling Keystone support in an application
60// that uses KeystoneGlue is as simple as dropping
61// KeystoneRegistration.framework in the application's Frameworks directory
62// and providing the relevant information in its Info.plist. KeystoneGlue
63// requires that the KSUpdateURL key be set in the application's Info.plist,
64// and that it contain a string identifying the update URL to be used by
65// Keystone.
66
67@class KSRegistration;
68
69@interface KeystoneGlue : NSObject {
70 @protected
71
72 // Data for Keystone registration
Robert Liao44d3ef12019-12-12 21:04:3373 base::scoped_nsobject<NSString> _productID;
74 base::scoped_nsobject<NSString> _appPath;
75 base::scoped_nsobject<NSString> _url;
76 base::scoped_nsobject<NSString> _version;
77 std::string _channel; // Logically: dev, beta, or stable.
Robert Sesek621c3bed2018-05-31 18:25:5378 // Cached location of the brand file.
Robert Liao44d3ef12019-12-12 21:04:3379 base::scoped_nsobject<NSString> _brandFile;
[email protected]7d791652010-12-01 16:34:4980
81 // And the Keystone registration itself, with the active timer
Robert Liao44d3ef12019-12-12 21:04:3382 base::scoped_nsobject<KSRegistration> _registration;
83 NSTimer* _timer; // strong
84 BOOL _registrationActive;
85 Class _ksUnsignedReportingAttributeClass;
[email protected]7d791652010-12-01 16:34:4986
87 // The most recent kAutoupdateStatusNotification notification posted.
Robert Liao44d3ef12019-12-12 21:04:3388 base::scoped_nsobject<NSNotification> _recentNotification;
[email protected]7d791652010-12-01 16:34:4989
90 // The authorization object, when it needs to persist because it's being
91 // carried across threads.
Robert Liao44d3ef12019-12-12 21:04:3392 base::mac::ScopedAuthorizationRef _authorization;
[email protected]7d791652010-12-01 16:34:4993
94 // YES if a synchronous promotion operation is in progress (promotion during
95 // installation).
Robert Liao44d3ef12019-12-12 21:04:3396 BOOL _synchronousPromotion;
[email protected]7d791652010-12-01 16:34:4997
98 // YES if an update was ever successfully installed by -installUpdate.
Robert Liao44d3ef12019-12-12 21:04:3399 BOOL _updateSuccessfullyInstalled;
Avi Drissmance903ee2019-04-12 15:09:30100
101 // The object to use to watch for the staging key.
Robert Liao44d3ef12019-12-12 21:04:33102 base::scoped_nsobject<CrStagingKeyWatcher> _stagingKeyWatcher;
[email protected]7d791652010-12-01 16:34:49103}
104
105// Return the default Keystone Glue object.
106+ (id)defaultKeystoneGlue;
107
108// Load KeystoneRegistration.framework if present, call into it to register
109// with Keystone, and set up periodic activity pings.
110- (void)registerWithKeystone;
bcwhitee9301292015-06-22 15:31:58111- (BOOL)isRegisteredAndActive;
[email protected]7d791652010-12-01 16:34:49112
113// -checkForUpdate launches a check for updates, and -installUpdate begins
114// installing an available update. For each, status will be communicated via
115// a kAutoupdateStatusNotification notification, and will also be available
116// through -recentNotification.
117- (void)checkForUpdate;
118- (void)installUpdate;
119
120// Accessor for recentNotification_. Returns an autoreleased NSNotification.
121- (NSNotification*)recentNotification;
122
123// Accessor for the kAutoupdateStatusStatus field of recentNotification_'s
124// userInfo dictionary.
125- (AutoupdateStatus)recentStatus;
126
127// Returns YES if an asynchronous operation is pending: if an update check or
128// installation attempt is currently in progress.
129- (BOOL)asyncOperationPending;
130
131// Returns YES if the application is running from a read-only filesystem,
132// such as a disk image.
133- (BOOL)isOnReadOnlyFilesystem;
134
135// -needsPromotion is YES if the application needs its ticket promoted to
136// a system ticket. This will be YES when the application is on a user
137// ticket and determines that the current user does not have sufficient
138// permission to perform the update.
139//
140// -wantsPromotion is YES if the application wants its ticket promoted to
141// a system ticket, even if it doesn't need it as determined by
142// -needsPromotion. -wantsPromotion will always be YES if -needsPromotion is,
143// and it will additionally be YES when the application is on a user ticket
144// and appears to be installed in a system-wide location such as
145// /Applications.
146//
147// Use -needsPromotion to decide whether to show any update UI at all. If
148// it's YES, there's no sense in asking the user to "update now" because it
149// will fail given the rights and permissions involved. On the other hand,
150// when -needsPromotion is YES, the application can encourage the user to
151// promote the ticket so that updates will work properly.
152//
153// Use -wantsPromotion to decide whether to allow the user to promote. The
154// user shouldn't be nagged about promotion on the basis of -wantsPromotion,
155// but if it's YES, the user should be allowed to promote the ticket.
156- (BOOL)needsPromotion;
157- (BOOL)wantsPromotion;
158
dbeam3109d3ea2016-12-18 07:23:43159// -isAutoupdateEnabledForAllUsers indicates whether or not autoupdate is
160// turned on for all users.
161- (BOOL)isAutoupdateEnabledForAllUsers;
162
[email protected]7d791652010-12-01 16:34:49163// Promotes the Keystone ticket into the system store. System Keystone will
164// be installed if necessary. If synchronous is NO, the promotion may occur
165// in the background. synchronous should be YES for promotion during
166// installation. The KeystoneGlue object assumes ownership of
Robert Sesek4322a53d2018-06-12 01:40:06167// |anAuthorization|.
168- (void)promoteTicketWithAuthorization:(AuthorizationRef)anAuthorization
[email protected]7d791652010-12-01 16:34:49169 synchronous:(BOOL)synchronous;
170
171// Requests authorization and calls -promoteTicketWithAuthorization: in
172// asynchronous mode.
173- (void)promoteTicket;
174
Joshua Pawlicki9fbc8412019-03-20 16:05:12175// Set the registration active.
176- (void)setRegistrationActive;
177
[email protected]7d791652010-12-01 16:34:49178// Sets a new value for appPath. Used during installation to point a ticket
179// at the installed copy.
180- (void)setAppPath:(NSString*)appPath;
181
182@end // @interface KeystoneGlue
183
184@interface KeystoneGlue(ExposedForTesting)
185
186// Load any params we need for configuring Keystone.
187- (void)loadParameters;
188
189// Load the Keystone registration object.
190// Return NO on failure.
191- (BOOL)loadKeystoneRegistration;
192
193- (void)stopTimer;
194
195// Called when a checkForUpdate: notification completes.
196- (void)checkForUpdateComplete:(NSNotification*)notification;
197
198// Called when an installUpdate: notification completes.
199- (void)installUpdateComplete:(NSNotification*)notification;
200
201@end // @interface KeystoneGlue(ExposedForTesting)
202
203#endif // __OBJC__
204
205// Functions that may be accessed from non-Objective-C C/C++ code.
206namespace keystone_glue {
207
[email protected]c9c15122011-08-30 14:24:01208// Returns the brand code of the installation. Note that beta, dev, and canary
209// channels, as well as some stable builds, may have an empty string as a brand
210// code.
211std::string BrandCode();
212
[email protected]7d791652010-12-01 16:34:49213// True if Keystone is enabled.
214bool KeystoneEnabled();
215
216// The version of the application currently installed on disk.
[email protected]6a72a632013-12-12 22:22:00217base::string16 CurrentlyInstalledVersion();
[email protected]7d791652010-12-01 16:34:49218
219} // namespace keystone_glue
220
[email protected]5950f5712011-06-20 22:15:52221#endif // CHROME_BROWSER_MAC_KEYSTONE_GLUE_H_