Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / chrome / browser / mac / keystone_glue.h
blob1547975ea43a5f5267dd3c8a3b42ffc87a558e43
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
90 BOOL registrationActive_;
91 Class ksUnsignedReportingAttributeClass_;
93 // The most recent kAutoupdateStatusNotification notification posted.
94 base::scoped_nsobject<NSNotification> recentNotification_;
96 // The authorization object, when it needs to persist because it's being
97 // carried across threads.
98 base::mac::ScopedAuthorizationRef authorization_;
100 // YES if a synchronous promotion operation is in progress (promotion during
101 // installation).
102 BOOL synchronousPromotion_;
104 // YES if an update was ever successfully installed by -installUpdate.
105 BOOL updateSuccessfullyInstalled_;
107 // Profile count information.
108 uint32_t numProfiles_;
109 uint32_t numSignedInProfiles_;
112 // Return the default Keystone Glue object.
113 + (id)defaultKeystoneGlue;
115 // Load KeystoneRegistration.framework if present, call into it to register
116 // with Keystone, and set up periodic activity pings.
117 - (void)registerWithKeystone;
118 - (BOOL)isRegisteredAndActive;
120 // -checkForUpdate launches a check for updates, and -installUpdate begins
121 // installing an available update. For each, status will be communicated via
122 // a kAutoupdateStatusNotification notification, and will also be available
123 // through -recentNotification.
124 - (void)checkForUpdate;
125 - (void)installUpdate;
127 // Accessor for recentNotification_. Returns an autoreleased NSNotification.
128 - (NSNotification*)recentNotification;
130 // Accessor for the kAutoupdateStatusStatus field of recentNotification_'s
131 // userInfo dictionary.
132 - (AutoupdateStatus)recentStatus;
134 // Returns YES if an asynchronous operation is pending: if an update check or
135 // installation attempt is currently in progress.
136 - (BOOL)asyncOperationPending;
138 // Returns YES if the application is running from a read-only filesystem,
139 // such as a disk image.
140 - (BOOL)isOnReadOnlyFilesystem;
142 // -needsPromotion is YES if the application needs its ticket promoted to
143 // a system ticket. This will be YES when the application is on a user
144 // ticket and determines that the current user does not have sufficient
145 // permission to perform the update.
147 // -wantsPromotion is YES if the application wants its ticket promoted to
148 // a system ticket, even if it doesn't need it as determined by
149 // -needsPromotion. -wantsPromotion will always be YES if -needsPromotion is,
150 // and it will additionally be YES when the application is on a user ticket
151 // and appears to be installed in a system-wide location such as
152 // /Applications.
154 // Use -needsPromotion to decide whether to show any update UI at all. If
155 // it's YES, there's no sense in asking the user to "update now" because it
156 // will fail given the rights and permissions involved. On the other hand,
157 // when -needsPromotion is YES, the application can encourage the user to
158 // promote the ticket so that updates will work properly.
160 // Use -wantsPromotion to decide whether to allow the user to promote. The
161 // user shouldn't be nagged about promotion on the basis of -wantsPromotion,
162 // but if it's YES, the user should be allowed to promote the ticket.
163 - (BOOL)needsPromotion;
164 - (BOOL)wantsPromotion;
166 // Promotes the Keystone ticket into the system store. System Keystone will
167 // be installed if necessary. If synchronous is NO, the promotion may occur
168 // in the background. synchronous should be YES for promotion during
169 // installation. The KeystoneGlue object assumes ownership of
170 // authorization_arg.
171 - (void)promoteTicketWithAuthorization:(AuthorizationRef)authorization_arg
172 synchronous:(BOOL)synchronous;
174 // Requests authorization and calls -promoteTicketWithAuthorization: in
175 // asynchronous mode.
176 - (void)promoteTicket;
178 // Sets a new value for appPath. Used during installation to point a ticket
179 // at the installed copy.
180 - (void)setAppPath:(NSString*)appPath;
182 // Sets the total number of profiles and the number of signed in profiles.
183 - (void)updateProfileCountsWithNumProfiles:(uint32_t)profiles
184 numSignedInProfiles:(uint32_t)signedInProfiles;
186 @end // @interface KeystoneGlue
188 @interface KeystoneGlue(ExposedForTesting)
190 // Load any params we need for configuring Keystone.
191 - (void)loadParameters;
193 // Load the Keystone registration object.
194 // Return NO on failure.
195 - (BOOL)loadKeystoneRegistration;
197 - (void)stopTimer;
199 // Called when a checkForUpdate: notification completes.
200 - (void)checkForUpdateComplete:(NSNotification*)notification;
202 // Called when an installUpdate: notification completes.
203 - (void)installUpdateComplete:(NSNotification*)notification;
205 @end // @interface KeystoneGlue(ExposedForTesting)
207 #endif // __OBJC__
209 // Functions that may be accessed from non-Objective-C C/C++ code.
210 namespace keystone_glue {
212 // Returns the brand code of the installation. Note that beta, dev, and canary
213 // channels, as well as some stable builds, may have an empty string as a brand
214 // code.
215 std::string BrandCode();
217 // True if Keystone is enabled.
218 bool KeystoneEnabled();
220 // The version of the application currently installed on disk.
221 base::string16 CurrentlyInstalledVersion();
223 } // namespace keystone_glue
225 #endif // CHROME_BROWSER_MAC_KEYSTONE_GLUE_H_