blob: 5c21c369e80294ede452810b37885491d48c7f79 [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>
13
[email protected]ef12d1e62012-03-21 20:55:0514#include "base/mac/scoped_authorizationref.h"
[email protected]a8522032013-06-24 22:51:4615#import "base/mac/scoped_nsobject.h"
[email protected]7d791652010-12-01 16:34:4916
17// Possible outcomes of various operations. A version may accompany some of
18// these, but beware: a version is never required. For statuses that can be
19// accompanied by a version, the comment indicates what version is referenced.
20// A notification posted containing an asynchronous status will always be
21// followed by a notification with a terminal status.
22enum AutoupdateStatus {
23 kAutoupdateNone = 0, // no version (initial state only)
24 kAutoupdateRegistering, // no version (asynchronous operation in progress)
25 kAutoupdateRegistered, // no version
26 kAutoupdateChecking, // no version (asynchronous operation in progress)
27 kAutoupdateCurrent, // version of the running application
28 kAutoupdateAvailable, // version of the update that is available
29 kAutoupdateInstalling, // no version (asynchronous operation in progress)
30 kAutoupdateInstalled, // version of the update that was installed
31 kAutoupdatePromoting, // no version (asynchronous operation in progress)
32 kAutoupdatePromoted, // no version
33 kAutoupdateRegisterFailed, // no version
34 kAutoupdateCheckFailed, // no version
35 kAutoupdateInstallFailed, // no version
36 kAutoupdatePromoteFailed, // no version
[email protected]a2d67742011-10-18 15:44:1037 kAutoupdateNeedsPromotion, // no version
[email protected]7d791652010-12-01 16:34:4938};
39
40// kAutoupdateStatusNotification is the name of the notification posted when
41// -checkForUpdate and -installUpdate complete. This notification will be
42// sent with with its sender object set to the KeystoneGlue instance sending
43// the notification. Its userInfo dictionary will contain an AutoupdateStatus
44// value as an intValue at key kAutoupdateStatusStatus. If a version is
45// available (see AutoupdateStatus), it will be present at key
46// kAutoupdateStatusVersion.
47extern NSString* const kAutoupdateStatusNotification;
48extern NSString* const kAutoupdateStatusStatus;
49extern NSString* const kAutoupdateStatusVersion;
50
51namespace {
52
53enum BrandFileType {
54 kBrandFileTypeNotDetermined = 0,
55 kBrandFileTypeNone,
56 kBrandFileTypeUser,
57 kBrandFileTypeSystem,
58};
59
60} // namespace
61
62// KeystoneGlue is an adapter around the KSRegistration class, allowing it to
63// be used without linking directly against its containing KeystoneRegistration
64// framework. This is used in an environment where most builds (such as
65// developer builds) don't want or need Keystone support and might not even
66// have the framework available. Enabling Keystone support in an application
67// that uses KeystoneGlue is as simple as dropping
68// KeystoneRegistration.framework in the application's Frameworks directory
69// and providing the relevant information in its Info.plist. KeystoneGlue
70// requires that the KSUpdateURL key be set in the application's Info.plist,
71// and that it contain a string identifying the update URL to be used by
72// Keystone.
73
74@class KSRegistration;
75
76@interface KeystoneGlue : NSObject {
77 @protected
78
79 // Data for Keystone registration
80 NSString* productID_;
81 NSString* appPath_;
82 NSString* url_;
83 NSString* version_;
84 NSString* channel_; // Logically: Dev, Beta, or Stable.
85 BrandFileType brandFileType_;
86
87 // And the Keystone registration itself, with the active timer
88 KSRegistration* registration_; // strong
89 NSTimer* timer_; // strong
90
91 // The most recent kAutoupdateStatusNotification notification posted.
[email protected]a8522032013-06-24 22:51:4692 base::scoped_nsobject<NSNotification> recentNotification_;
[email protected]7d791652010-12-01 16:34:4993
94 // The authorization object, when it needs to persist because it's being
95 // carried across threads.
[email protected]ef12d1e62012-03-21 20:55:0596 base::mac::ScopedAuthorizationRef authorization_;
[email protected]7d791652010-12-01 16:34:4997
98 // YES if a synchronous promotion operation is in progress (promotion during
99 // installation).
100 BOOL synchronousPromotion_;
101
102 // YES if an update was ever successfully installed by -installUpdate.
103 BOOL updateSuccessfullyInstalled_;
104}
105
106// Return the default Keystone Glue object.
107+ (id)defaultKeystoneGlue;
108
109// Load KeystoneRegistration.framework if present, call into it to register
110// with Keystone, and set up periodic activity pings.
111- (void)registerWithKeystone;
112
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
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
163// authorization_arg.
164- (void)promoteTicketWithAuthorization:(AuthorizationRef)authorization_arg
165 synchronous:(BOOL)synchronous;
166
167// Requests authorization and calls -promoteTicketWithAuthorization: in
168// asynchronous mode.
169- (void)promoteTicket;
170
171// Sets a new value for appPath. Used during installation to point a ticket
172// at the installed copy.
173- (void)setAppPath:(NSString*)appPath;
174
175@end // @interface KeystoneGlue
176
177@interface KeystoneGlue(ExposedForTesting)
178
179// Load any params we need for configuring Keystone.
180- (void)loadParameters;
181
182// Load the Keystone registration object.
183// Return NO on failure.
184- (BOOL)loadKeystoneRegistration;
185
186- (void)stopTimer;
187
188// Called when a checkForUpdate: notification completes.
189- (void)checkForUpdateComplete:(NSNotification*)notification;
190
191// Called when an installUpdate: notification completes.
192- (void)installUpdateComplete:(NSNotification*)notification;
193
194@end // @interface KeystoneGlue(ExposedForTesting)
195
196#endif // __OBJC__
197
198// Functions that may be accessed from non-Objective-C C/C++ code.
199namespace keystone_glue {
200
[email protected]c9c15122011-08-30 14:24:01201// Returns the brand code of the installation. Note that beta, dev, and canary
202// channels, as well as some stable builds, may have an empty string as a brand
203// code.
204std::string BrandCode();
205
[email protected]7d791652010-12-01 16:34:49206// True if Keystone is enabled.
207bool KeystoneEnabled();
208
209// The version of the application currently installed on disk.
[email protected]6a72a632013-12-12 22:22:00210base::string16 CurrentlyInstalledVersion();
[email protected]7d791652010-12-01 16:34:49211
212} // namespace keystone_glue
213
[email protected]5950f5712011-06-20 22:15:52214#endif // CHROME_BROWSER_MAC_KEYSTONE_GLUE_H_