blob: 755b408d427773b68cc1fed25796a08d8a51f029 [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#pragma once
8
9#include "base/string16.h"
10
11#if defined(__OBJC__)
12
13#import <Foundation/Foundation.h>
14
[email protected]ef12d1e62012-03-21 20:55:0515#include "base/mac/scoped_authorizationref.h"
[email protected]3b63f8f42011-03-28 01:54:1516#import "base/memory/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
91
92 // The most recent kAutoupdateStatusNotification notification posted.
93 scoped_nsobject<NSNotification> recentNotification_;
94
95 // The authorization object, when it needs to persist because it's being
96 // carried across threads.
[email protected]ef12d1e62012-03-21 20:55:0597 base::mac::ScopedAuthorizationRef authorization_;
[email protected]7d791652010-12-01 16:34:4998
99 // YES if a synchronous promotion operation is in progress (promotion during
100 // installation).
101 BOOL synchronousPromotion_;
102
103 // YES if an update was ever successfully installed by -installUpdate.
104 BOOL updateSuccessfullyInstalled_;
105}
106
107// Return the default Keystone Glue object.
108+ (id)defaultKeystoneGlue;
109
110// Load KeystoneRegistration.framework if present, call into it to register
111// with Keystone, and set up periodic activity pings.
112- (void)registerWithKeystone;
113
114// -checkForUpdate launches a check for updates, and -installUpdate begins
115// installing an available update. For each, status will be communicated via
116// a kAutoupdateStatusNotification notification, and will also be available
117// through -recentNotification.
118- (void)checkForUpdate;
119- (void)installUpdate;
120
121// Accessor for recentNotification_. Returns an autoreleased NSNotification.
122- (NSNotification*)recentNotification;
123
124// Accessor for the kAutoupdateStatusStatus field of recentNotification_'s
125// userInfo dictionary.
126- (AutoupdateStatus)recentStatus;
127
128// Returns YES if an asynchronous operation is pending: if an update check or
129// installation attempt is currently in progress.
130- (BOOL)asyncOperationPending;
131
132// Returns YES if the application is running from a read-only filesystem,
133// such as a disk image.
134- (BOOL)isOnReadOnlyFilesystem;
135
136// -needsPromotion is YES if the application needs its ticket promoted to
137// a system ticket. This will be YES when the application is on a user
138// ticket and determines that the current user does not have sufficient
139// permission to perform the update.
140//
141// -wantsPromotion is YES if the application wants its ticket promoted to
142// a system ticket, even if it doesn't need it as determined by
143// -needsPromotion. -wantsPromotion will always be YES if -needsPromotion is,
144// and it will additionally be YES when the application is on a user ticket
145// and appears to be installed in a system-wide location such as
146// /Applications.
147//
148// Use -needsPromotion to decide whether to show any update UI at all. If
149// it's YES, there's no sense in asking the user to "update now" because it
150// will fail given the rights and permissions involved. On the other hand,
151// when -needsPromotion is YES, the application can encourage the user to
152// promote the ticket so that updates will work properly.
153//
154// Use -wantsPromotion to decide whether to allow the user to promote. The
155// user shouldn't be nagged about promotion on the basis of -wantsPromotion,
156// but if it's YES, the user should be allowed to promote the ticket.
157- (BOOL)needsPromotion;
158- (BOOL)wantsPromotion;
159
160// Promotes the Keystone ticket into the system store. System Keystone will
161// be installed if necessary. If synchronous is NO, the promotion may occur
162// in the background. synchronous should be YES for promotion during
163// installation. The KeystoneGlue object assumes ownership of
164// authorization_arg.
165- (void)promoteTicketWithAuthorization:(AuthorizationRef)authorization_arg
166 synchronous:(BOOL)synchronous;
167
168// Requests authorization and calls -promoteTicketWithAuthorization: in
169// asynchronous mode.
170- (void)promoteTicket;
171
172// Sets a new value for appPath. Used during installation to point a ticket
173// at the installed copy.
174- (void)setAppPath:(NSString*)appPath;
175
176@end // @interface KeystoneGlue
177
178@interface KeystoneGlue(ExposedForTesting)
179
180// Load any params we need for configuring Keystone.
181- (void)loadParameters;
182
183// Load the Keystone registration object.
184// Return NO on failure.
185- (BOOL)loadKeystoneRegistration;
186
187- (void)stopTimer;
188
189// Called when a checkForUpdate: notification completes.
190- (void)checkForUpdateComplete:(NSNotification*)notification;
191
192// Called when an installUpdate: notification completes.
193- (void)installUpdateComplete:(NSNotification*)notification;
194
195@end // @interface KeystoneGlue(ExposedForTesting)
196
197#endif // __OBJC__
198
199// Functions that may be accessed from non-Objective-C C/C++ code.
200namespace keystone_glue {
201
[email protected]c9c15122011-08-30 14:24:01202// Returns the brand code of the installation. Note that beta, dev, and canary
203// channels, as well as some stable builds, may have an empty string as a brand
204// code.
205std::string BrandCode();
206
[email protected]7d791652010-12-01 16:34:49207// True if Keystone is enabled.
208bool KeystoneEnabled();
209
210// The version of the application currently installed on disk.
211string16 CurrentlyInstalledVersion();
212
213} // namespace keystone_glue
214
[email protected]5950f5712011-06-20 22:15:52215#endif // CHROME_BROWSER_MAC_KEYSTONE_GLUE_H_