1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_MAC_KEYSTONE_GLUE_H_
6 #define CHROME_BROWSER_MAC_KEYSTONE_GLUE_H_
8 #include "base/strings/string16.h"
12 #import <Foundation/Foundation.h>
14 #include "base/mac/scoped_authorizationref.h"
15 #import "base/mac/scoped_nsobject.h"
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.
22 enum 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
37 kAutoupdateNeedsPromotion
, // no version
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.
47 extern NSString
* const kAutoupdateStatusNotification
;
48 extern NSString
* const kAutoupdateStatusStatus
;
49 extern NSString
* const kAutoupdateStatusVersion
;
54 kBrandFileTypeNotDetermined
= 0,
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
74 @
class KSRegistration
;
76 @interface KeystoneGlue
: NSObject
{
79 // Data for Keystone registration
84 NSString
* channel_
; // Logically: Dev, Beta, or Stable.
85 BrandFileType brandFileType_
;
87 // And the Keystone registration itself, with the active timer
88 KSRegistration
* registration_
; // strong
89 NSTimer
* timer_
; // strong
90 Class ksUnsignedReportingAttributeClass_
;
92 // The most recent kAutoupdateStatusNotification notification posted.
93 base::scoped_nsobject
<NSNotification
> recentNotification_
;
95 // The authorization object, when it needs to persist because it's being
96 // carried across threads.
97 base::mac::ScopedAuthorizationRef authorization_
;
99 // YES if a synchronous promotion operation is in progress (promotion during
101 BOOL synchronousPromotion_
;
103 // YES if an update was ever successfully installed by -installUpdate.
104 BOOL updateSuccessfullyInstalled_
;
106 // Profile count information.
107 uint32_t numProfiles_
;
108 uint32_t numSignedInProfiles_
;
111 // Return the default Keystone Glue object.
112 + (id
)defaultKeystoneGlue
;
114 // Load KeystoneRegistration.framework if present, call into it to register
115 // with Keystone, and set up periodic activity pings.
116 - (void)registerWithKeystone
;
118 // -checkForUpdate launches a check for updates, and -installUpdate begins
119 // installing an available update. For each, status will be communicated via
120 // a kAutoupdateStatusNotification notification, and will also be available
121 // through -recentNotification.
122 - (void)checkForUpdate
;
123 - (void)installUpdate
;
125 // Accessor for recentNotification_. Returns an autoreleased NSNotification.
126 - (NSNotification
*)recentNotification
;
128 // Accessor for the kAutoupdateStatusStatus field of recentNotification_'s
129 // userInfo dictionary.
130 - (AutoupdateStatus
)recentStatus
;
132 // Returns YES if an asynchronous operation is pending: if an update check or
133 // installation attempt is currently in progress.
134 - (BOOL
)asyncOperationPending
;
136 // Returns YES if the application is running from a read-only filesystem,
137 // such as a disk image.
138 - (BOOL
)isOnReadOnlyFilesystem
;
140 // -needsPromotion is YES if the application needs its ticket promoted to
141 // a system ticket. This will be YES when the application is on a user
142 // ticket and determines that the current user does not have sufficient
143 // permission to perform the update.
145 // -wantsPromotion is YES if the application wants its ticket promoted to
146 // a system ticket, even if it doesn't need it as determined by
147 // -needsPromotion. -wantsPromotion will always be YES if -needsPromotion is,
148 // and it will additionally be YES when the application is on a user ticket
149 // and appears to be installed in a system-wide location such as
152 // Use -needsPromotion to decide whether to show any update UI at all. If
153 // it's YES, there's no sense in asking the user to "update now" because it
154 // will fail given the rights and permissions involved. On the other hand,
155 // when -needsPromotion is YES, the application can encourage the user to
156 // promote the ticket so that updates will work properly.
158 // Use -wantsPromotion to decide whether to allow the user to promote. The
159 // user shouldn't be nagged about promotion on the basis of -wantsPromotion,
160 // but if it's YES, the user should be allowed to promote the ticket.
161 - (BOOL
)needsPromotion
;
162 - (BOOL
)wantsPromotion
;
164 // Promotes the Keystone ticket into the system store. System Keystone will
165 // be installed if necessary. If synchronous is NO, the promotion may occur
166 // in the background. synchronous should be YES for promotion during
167 // installation. The KeystoneGlue object assumes ownership of
168 // authorization_arg.
169 - (void)promoteTicketWithAuthorization
:(AuthorizationRef
)authorization_arg
170 synchronous
:(BOOL
)synchronous
;
172 // Requests authorization and calls -promoteTicketWithAuthorization: in
173 // asynchronous mode.
174 - (void)promoteTicket
;
176 // Sets a new value for appPath. Used during installation to point a ticket
177 // at the installed copy.
178 - (void)setAppPath
:(NSString
*)appPath
;
180 // Sets the total number of profiles and the number of signed in profiles.
181 - (void)updateProfileCountsWithNumProfiles
:(uint32_t)profiles
182 numSignedInProfiles
:(uint32_t)signedInProfiles
;
184 @end
// @interface KeystoneGlue
186 @interface
KeystoneGlue(ExposedForTesting
)
188 // Load any params we need for configuring Keystone.
189 - (void)loadParameters
;
191 // Load the Keystone registration object.
192 // Return NO on failure.
193 - (BOOL
)loadKeystoneRegistration
;
197 // Called when a checkForUpdate: notification completes.
198 - (void)checkForUpdateComplete
:(NSNotification
*)notification
;
200 // Called when an installUpdate: notification completes.
201 - (void)installUpdateComplete
:(NSNotification
*)notification
;
203 @end
// @interface KeystoneGlue(ExposedForTesting)
207 // Functions that may be accessed from non-Objective-C C/C++ code.
208 namespace keystone_glue
{
210 // Returns the brand code of the installation. Note that beta, dev, and canary
211 // channels, as well as some stable builds, may have an empty string as a brand
213 std::string
BrandCode();
215 // True if Keystone is enabled.
216 bool KeystoneEnabled();
218 // The version of the application currently installed on disk.
219 base::string16
CurrentlyInstalledVersion();
221 } // namespace keystone_glue
223 #endif // CHROME_BROWSER_MAC_KEYSTONE_GLUE_H_