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