Disabling NativeViewAcccessibilityWinTest.RetrieveAllAlerts.
[chromium-blink-merge.git] / chrome / browser / mac / keystone_glue.h
blob5c21c369e80294ede452810b37885491d48c7f79
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"
10 #if defined(__OBJC__)
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;
51 namespace {
53 enum BrandFileType {
54 kBrandFileTypeNotDetermined = 0,
55 kBrandFileTypeNone,
56 kBrandFileTypeUser,
57 kBrandFileTypeSystem,
60 } // namespace
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.
74 @class KSRegistration;
76 @interface KeystoneGlue : NSObject {
77 @protected
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_;
87 // And the Keystone registration itself, with the active timer
88 KSRegistration* registration_; // strong
89 NSTimer* timer_; // strong
91 // The most recent kAutoupdateStatusNotification notification posted.
92 base::scoped_nsobject<NSNotification> recentNotification_;
94 // The authorization object, when it needs to persist because it's being
95 // carried across threads.
96 base::mac::ScopedAuthorizationRef authorization_;
98 // YES if a synchronous promotion operation is in progress (promotion during
99 // installation).
100 BOOL synchronousPromotion_;
102 // YES if an update was ever successfully installed by -installUpdate.
103 BOOL updateSuccessfullyInstalled_;
106 // Return the default Keystone Glue object.
107 + (id)defaultKeystoneGlue;
109 // Load KeystoneRegistration.framework if present, call into it to register
110 // with Keystone, and set up periodic activity pings.
111 - (void)registerWithKeystone;
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;
120 // Accessor for recentNotification_. Returns an autoreleased NSNotification.
121 - (NSNotification*)recentNotification;
123 // Accessor for the kAutoupdateStatusStatus field of recentNotification_'s
124 // userInfo dictionary.
125 - (AutoupdateStatus)recentStatus;
127 // Returns YES if an asynchronous operation is pending: if an update check or
128 // installation attempt is currently in progress.
129 - (BOOL)asyncOperationPending;
131 // Returns YES if the application is running from a read-only filesystem,
132 // such as a disk image.
133 - (BOOL)isOnReadOnlyFilesystem;
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.
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.
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.
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;
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;
167 // Requests authorization and calls -promoteTicketWithAuthorization: in
168 // asynchronous mode.
169 - (void)promoteTicket;
171 // Sets a new value for appPath. Used during installation to point a ticket
172 // at the installed copy.
173 - (void)setAppPath:(NSString*)appPath;
175 @end // @interface KeystoneGlue
177 @interface KeystoneGlue(ExposedForTesting)
179 // Load any params we need for configuring Keystone.
180 - (void)loadParameters;
182 // Load the Keystone registration object.
183 // Return NO on failure.
184 - (BOOL)loadKeystoneRegistration;
186 - (void)stopTimer;
188 // Called when a checkForUpdate: notification completes.
189 - (void)checkForUpdateComplete:(NSNotification*)notification;
191 // Called when an installUpdate: notification completes.
192 - (void)installUpdateComplete:(NSNotification*)notification;
194 @end // @interface KeystoneGlue(ExposedForTesting)
196 #endif // __OBJC__
198 // Functions that may be accessed from non-Objective-C C/C++ code.
199 namespace keystone_glue {
201 // 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.
204 std::string BrandCode();
206 // True if Keystone is enabled.
207 bool KeystoneEnabled();
209 // The version of the application currently installed on disk.
210 base::string16 CurrentlyInstalledVersion();
212 } // namespace keystone_glue
214 #endif // CHROME_BROWSER_MAC_KEYSTONE_GLUE_H_