blob: 912a1d9d116e8028c826e6cd353c7c96ed7e47ee [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"
[email protected]7d791652010-12-01 16:34:4917
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.
23enum 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]a2d67742011-10-18 15:44:1038 kAutoupdateNeedsPromotion, // no version
[email protected]7d791652010-12-01 16:34:4939};
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
47// kAutoupdateStatusVersion.
48extern NSString* const kAutoupdateStatusNotification;
49extern NSString* const kAutoupdateStatusStatus;
50extern NSString* const kAutoupdateStatusVersion;
51
52namespace {
53
54enum BrandFileType {
55 kBrandFileTypeNotDetermined = 0,
56 kBrandFileTypeNone,
57 kBrandFileTypeUser,
58 kBrandFileTypeSystem,
59};
60
61} // namespace
62
63// KeystoneGlue is an adapter around the KSRegistration class, allowing it to
64// be used without linking directly against its containing KeystoneRegistration
65// framework. This is used in an environment where most builds (such as
66// developer builds) don't want or need Keystone support and might not even
67// have the framework available. Enabling Keystone support in an application
68// that uses KeystoneGlue is as simple as dropping
69// KeystoneRegistration.framework in the application's Frameworks directory
70// and providing the relevant information in its Info.plist. KeystoneGlue
71// requires that the KSUpdateURL key be set in the application's Info.plist,
72// and that it contain a string identifying the update URL to be used by
73// Keystone.
74
75@class KSRegistration;
76
77@interface KeystoneGlue : NSObject {
78 @protected
79
80 // Data for Keystone registration
81 NSString* productID_;
82 NSString* appPath_;
83 NSString* url_;
84 NSString* version_;
85 NSString* channel_; // Logically: Dev, Beta, or Stable.
86 BrandFileType brandFileType_;
87
88 // And the Keystone registration itself, with the active timer
89 KSRegistration* registration_; // strong
90 NSTimer* timer_; // strong
bcwhitee9301292015-06-22 15:31:5891 BOOL registrationActive_;
mlerman1e9f61ce2015-03-23 18:14:0092 Class ksUnsignedReportingAttributeClass_;
[email protected]7d791652010-12-01 16:34:4993
94 // The most recent kAutoupdateStatusNotification notification posted.
[email protected]a8522032013-06-24 22:51:4695 base::scoped_nsobject<NSNotification> recentNotification_;
[email protected]7d791652010-12-01 16:34:4996
97 // The authorization object, when it needs to persist because it's being
98 // carried across threads.
[email protected]ef12d1e62012-03-21 20:55:0599 base::mac::ScopedAuthorizationRef authorization_;
[email protected]7d791652010-12-01 16:34:49100
101 // YES if a synchronous promotion operation is in progress (promotion during
102 // installation).
103 BOOL synchronousPromotion_;
104
105 // YES if an update was ever successfully installed by -installUpdate.
106 BOOL updateSuccessfullyInstalled_;
mlerman1e9f61ce2015-03-23 18:14:00107
108 // Profile count information.
109 uint32_t numProfiles_;
110 uint32_t numSignedInProfiles_;
[email protected]7d791652010-12-01 16:34:49111}
112
113// Return the default Keystone Glue object.
114+ (id)defaultKeystoneGlue;
115
116// Load KeystoneRegistration.framework if present, call into it to register
117// with Keystone, and set up periodic activity pings.
118- (void)registerWithKeystone;
bcwhitee9301292015-06-22 15:31:58119- (BOOL)isRegisteredAndActive;
[email protected]7d791652010-12-01 16:34:49120
121// -checkForUpdate launches a check for updates, and -installUpdate begins
122// installing an available update. For each, status will be communicated via
123// a kAutoupdateStatusNotification notification, and will also be available
124// through -recentNotification.
125- (void)checkForUpdate;
126- (void)installUpdate;
127
128// Accessor for recentNotification_. Returns an autoreleased NSNotification.
129- (NSNotification*)recentNotification;
130
131// Accessor for the kAutoupdateStatusStatus field of recentNotification_'s
132// userInfo dictionary.
133- (AutoupdateStatus)recentStatus;
134
135// Returns YES if an asynchronous operation is pending: if an update check or
136// installation attempt is currently in progress.
137- (BOOL)asyncOperationPending;
138
139// Returns YES if the application is running from a read-only filesystem,
140// such as a disk image.
141- (BOOL)isOnReadOnlyFilesystem;
142
143// -needsPromotion is YES if the application needs its ticket promoted to
144// a system ticket. This will be YES when the application is on a user
145// ticket and determines that the current user does not have sufficient
146// permission to perform the update.
147//
148// -wantsPromotion is YES if the application wants its ticket promoted to
149// a system ticket, even if it doesn't need it as determined by
150// -needsPromotion. -wantsPromotion will always be YES if -needsPromotion is,
151// and it will additionally be YES when the application is on a user ticket
152// and appears to be installed in a system-wide location such as
153// /Applications.
154//
155// Use -needsPromotion to decide whether to show any update UI at all. If
156// it's YES, there's no sense in asking the user to "update now" because it
157// will fail given the rights and permissions involved. On the other hand,
158// when -needsPromotion is YES, the application can encourage the user to
159// promote the ticket so that updates will work properly.
160//
161// Use -wantsPromotion to decide whether to allow the user to promote. The
162// user shouldn't be nagged about promotion on the basis of -wantsPromotion,
163// but if it's YES, the user should be allowed to promote the ticket.
164- (BOOL)needsPromotion;
165- (BOOL)wantsPromotion;
166
167// Promotes the Keystone ticket into the system store. System Keystone will
168// be installed if necessary. If synchronous is NO, the promotion may occur
169// in the background. synchronous should be YES for promotion during
170// installation. The KeystoneGlue object assumes ownership of
171// authorization_arg.
172- (void)promoteTicketWithAuthorization:(AuthorizationRef)authorization_arg
173 synchronous:(BOOL)synchronous;
174
175// Requests authorization and calls -promoteTicketWithAuthorization: in
176// asynchronous mode.
177- (void)promoteTicket;
178
179// Sets a new value for appPath. Used during installation to point a ticket
180// at the installed copy.
181- (void)setAppPath:(NSString*)appPath;
182
mlerman1e9f61ce2015-03-23 18:14:00183// Sets the total number of profiles and the number of signed in profiles.
184- (void)updateProfileCountsWithNumProfiles:(uint32_t)profiles
185 numSignedInProfiles:(uint32_t)signedInProfiles;
186
[email protected]7d791652010-12-01 16:34:49187@end // @interface KeystoneGlue
188
189@interface KeystoneGlue(ExposedForTesting)
190
191// Load any params we need for configuring Keystone.
192- (void)loadParameters;
193
194// Load the Keystone registration object.
195// Return NO on failure.
196- (BOOL)loadKeystoneRegistration;
197
198- (void)stopTimer;
199
200// Called when a checkForUpdate: notification completes.
201- (void)checkForUpdateComplete:(NSNotification*)notification;
202
203// Called when an installUpdate: notification completes.
204- (void)installUpdateComplete:(NSNotification*)notification;
205
206@end // @interface KeystoneGlue(ExposedForTesting)
207
208#endif // __OBJC__
209
210// Functions that may be accessed from non-Objective-C C/C++ code.
211namespace keystone_glue {
212
[email protected]c9c15122011-08-30 14:24:01213// Returns the brand code of the installation. Note that beta, dev, and canary
214// channels, as well as some stable builds, may have an empty string as a brand
215// code.
216std::string BrandCode();
217
[email protected]7d791652010-12-01 16:34:49218// True if Keystone is enabled.
219bool KeystoneEnabled();
220
221// The version of the application currently installed on disk.
[email protected]6a72a632013-12-12 22:22:00222base::string16 CurrentlyInstalledVersion();
[email protected]7d791652010-12-01 16:34:49223
224} // namespace keystone_glue
225
[email protected]5950f5712011-06-20 22:15:52226#endif // CHROME_BROWSER_MAC_KEYSTONE_GLUE_H_