summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-13 18:46:45 +0000
committermark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-13 18:46:45 +0000
commit4fb641318f7c98dae624fdfdcd94ac5531de787a (patch)
treecb992fc32f34e9f5a603284e3ddcfcf7fa976241
parent311c9ba4feead2a8e67d137c8963ab37b82790ab (diff)
downloadchromium_src-4fb641318f7c98dae624fdfdcd94ac5531de787a.zip
chromium_src-4fb641318f7c98dae624fdfdcd94ac5531de787a.tar.gz
chromium_src-4fb641318f7c98dae624fdfdcd94ac5531de787a.tar.bz2
Make FakeKeystoneRegistration a (fake) KSRegistration subclass. This appeases
clang, which is now able to check the type of +alloc and -init through its "related result types" feature. http://clang.llvm.org/docs/LanguageExtensions.html#objc_instancetype BUG=85885 TEST=clang compilation, Keystone still functions (check the About window in a Keystone-enabled build) Review URL: http://codereview.chromium.org/7003152 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@88864 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/cocoa/keystone_glue.mm133
-rw-r--r--chrome/browser/cocoa/keystone_glue_unittest.mm50
-rw-r--r--chrome/browser/cocoa/keystone_registration.h72
-rw-r--r--chrome/browser/cocoa/keystone_registration.mm42
-rw-r--r--chrome/chrome_browser.gypi2
5 files changed, 198 insertions, 101 deletions
diff --git a/chrome/browser/cocoa/keystone_glue.mm b/chrome/browser/cocoa/keystone_glue.mm
index 2edca3e..ba2e25a 100644
--- a/chrome/browser/cocoa/keystone_glue.mm
+++ b/chrome/browser/cocoa/keystone_glue.mm
@@ -17,6 +17,7 @@
#include "base/task.h"
#include "base/threading/worker_pool.h"
#include "chrome/browser/cocoa/authorization_util.h"
+#import "chrome/browser/cocoa/keystone_registration.h"
#include "chrome/browser/platform_util.h"
#include "chrome/common/chrome_constants.h"
#include "grit/chromium_strings.h"
@@ -26,50 +27,7 @@
namespace {
-// Provide declarations of the Keystone registration bits needed here. From
-// KSRegistration.h.
-typedef enum {
- kKSPathExistenceChecker,
-} KSExistenceCheckerType;
-
-typedef enum {
- kKSRegistrationUserTicket,
- kKSRegistrationSystemTicket,
- kKSRegistrationDontKnowWhatKindOfTicket,
-} KSRegistrationTicketType;
-
-NSString* const KSRegistrationVersionKey = @"Version";
-NSString* const KSRegistrationExistenceCheckerTypeKey = @"ExistenceCheckerType";
-NSString* const KSRegistrationExistenceCheckerStringKey =
- @"ExistenceCheckerString";
-NSString* const KSRegistrationServerURLStringKey = @"URLString";
-NSString* const KSRegistrationPreserveTrustedTesterTokenKey = @"PreserveTTT";
-NSString* const KSRegistrationTagKey = @"Tag";
-NSString* const KSRegistrationTagPathKey = @"TagPath";
-NSString* const KSRegistrationTagKeyKey = @"TagKey";
-NSString* const KSRegistrationBrandPathKey = @"BrandPath";
-NSString* const KSRegistrationBrandKeyKey = @"BrandKey";
-NSString* const KSRegistrationVersionPathKey = @"VersionPath";
-NSString* const KSRegistrationVersionKeyKey = @"VersionKey";
-
-NSString* const KSRegistrationDidCompleteNotification =
- @"KSRegistrationDidCompleteNotification";
-NSString* const KSRegistrationPromotionDidCompleteNotification =
- @"KSRegistrationPromotionDidCompleteNotification";
-
-NSString* const KSRegistrationCheckForUpdateNotification =
- @"KSRegistrationCheckForUpdateNotification";
-NSString* KSRegistrationStatusKey = @"Status";
-NSString* KSRegistrationUpdateCheckErrorKey = @"Error";
-
-NSString* const KSRegistrationStartUpdateNotification =
- @"KSRegistrationStartUpdateNotification";
-NSString* const KSUpdateCheckSuccessfulKey = @"CheckSuccessful";
-NSString* const KSUpdateCheckSuccessfullyInstalledKey =
- @"SuccessfullyInstalled";
-
-NSString* const KSRegistrationRemoveExistingTag = @"";
-#define KSRegistrationPreserveExistingTag nil
+namespace ksr = keystone_registration;
// Constants for the brand file (uses an external file so it can survive
// updates to Chrome.)
@@ -141,22 +99,6 @@ class PerformBridge : public base::RefCountedThreadSafe<PerformBridge> {
} // namespace
-@interface KSRegistration : NSObject
-
-+ (id)registrationWithProductID:(NSString*)productID;
-
-- (BOOL)registerWithParameters:(NSDictionary*)args;
-
-- (BOOL)promoteWithParameters:(NSDictionary*)args
- authorization:(AuthorizationRef)authorization;
-
-- (void)setActive;
-- (void)checkForUpdate;
-- (void)startUpdate;
-- (KSRegistrationTicketType)ticketType;
-
-@end // @interface KSRegistration
-
@interface KeystoneGlue (Private)
// Returns the path to the application's Info.plist file. This returns the
@@ -270,22 +212,22 @@ NSString* const kVersionKey = @"KSVersion";
[center addObserver:self
selector:@selector(registrationComplete:)
- name:KSRegistrationDidCompleteNotification
+ name:ksr::KSRegistrationDidCompleteNotification
object:nil];
[center addObserver:self
selector:@selector(promotionComplete:)
- name:KSRegistrationPromotionDidCompleteNotification
+ name:ksr::KSRegistrationPromotionDidCompleteNotification
object:nil];
[center addObserver:self
selector:@selector(checkForUpdateComplete:)
- name:KSRegistrationCheckForUpdateNotification
+ name:ksr::KSRegistrationCheckForUpdateNotification
object:nil];
[center addObserver:self
selector:@selector(installUpdateComplete:)
- name:KSRegistrationStartUpdateNotification
+ name:ksr::KSRegistrationStartUpdateNotification
object:nil];
}
@@ -334,7 +276,7 @@ NSString* const kVersionKey = @"KSVersion";
// The stable channel has no tag. If updating to stable, remove the
// dev and beta tags since we've been "promoted".
if (channel == nil)
- channel = KSRegistrationRemoveExistingTag;
+ channel = ksr::KSRegistrationRemoveExistingTag;
productID_ = [productID retain];
appPath_ = [appPath retain];
@@ -483,7 +425,7 @@ NSString* const kVersionKey = @"KSVersion";
}
- (NSDictionary*)keystoneParameters {
- NSNumber* xcType = [NSNumber numberWithInt:kKSPathExistenceChecker];
+ NSNumber* xcType = [NSNumber numberWithInt:ksr::kKSPathExistenceChecker];
NSNumber* preserveTTToken = [NSNumber numberWithBool:YES];
NSString* appInfoPlistPath = [self appInfoPlistPath];
NSString* brandKey = kBrandKey;
@@ -496,18 +438,18 @@ NSString* const kVersionKey = @"KSVersion";
}
return [NSDictionary dictionaryWithObjectsAndKeys:
- version_, KSRegistrationVersionKey,
- appInfoPlistPath, KSRegistrationVersionPathKey,
- kVersionKey, KSRegistrationVersionKeyKey,
- xcType, KSRegistrationExistenceCheckerTypeKey,
- appPath_, KSRegistrationExistenceCheckerStringKey,
- url_, KSRegistrationServerURLStringKey,
- preserveTTToken, KSRegistrationPreserveTrustedTesterTokenKey,
- channel_, KSRegistrationTagKey,
- appInfoPlistPath, KSRegistrationTagPathKey,
- kChannelKey, KSRegistrationTagKeyKey,
- brandPath, KSRegistrationBrandPathKey,
- brandKey, KSRegistrationBrandKeyKey,
+ version_, ksr::KSRegistrationVersionKey,
+ appInfoPlistPath, ksr::KSRegistrationVersionPathKey,
+ kVersionKey, ksr::KSRegistrationVersionKeyKey,
+ xcType, ksr::KSRegistrationExistenceCheckerTypeKey,
+ appPath_, ksr::KSRegistrationExistenceCheckerStringKey,
+ url_, ksr::KSRegistrationServerURLStringKey,
+ preserveTTToken, ksr::KSRegistrationPreserveTrustedTesterTokenKey,
+ channel_, ksr::KSRegistrationTagKey,
+ appInfoPlistPath, ksr::KSRegistrationTagPathKey,
+ kChannelKey, ksr::KSRegistrationTagKeyKey,
+ brandPath, ksr::KSRegistrationBrandPathKey,
+ brandKey, ksr::KSRegistrationBrandKeyKey,
nil];
}
@@ -520,8 +462,8 @@ NSString* const kVersionKey = @"KSVersion";
return;
}
- // Upon completion, KSRegistrationDidCompleteNotification will be posted,
- // and -registrationComplete: will be called.
+ // Upon completion, ksr::KSRegistrationDidCompleteNotification will be
+ // posted, and -registrationComplete: will be called.
// Mark an active RIGHT NOW; don't wait an hour for the first one.
[registration_ setActive];
@@ -536,7 +478,7 @@ NSString* const kVersionKey = @"KSVersion";
- (void)registrationComplete:(NSNotification*)notification {
NSDictionary* userInfo = [notification userInfo];
- if ([[userInfo objectForKey:KSRegistrationStatusKey] boolValue]) {
+ if ([[userInfo objectForKey:ksr::KSRegistrationStatusKey] boolValue]) {
[self updateStatus:kAutoupdateRegistered version:nil];
} else {
// Dump registration_?
@@ -565,19 +507,20 @@ NSString* const kVersionKey = @"KSVersion";
[registration_ checkForUpdate];
- // Upon completion, KSRegistrationCheckForUpdateNotification will be posted,
- // and -checkForUpdateComplete: will be called.
+ // Upon completion, ksr::KSRegistrationCheckForUpdateNotification will be
+ // posted, and -checkForUpdateComplete: will be called.
}
- (void)checkForUpdateComplete:(NSNotification*)notification {
NSDictionary* userInfo = [notification userInfo];
- if ([[userInfo objectForKey:KSRegistrationUpdateCheckErrorKey] boolValue]) {
+ if ([[userInfo objectForKey:ksr::KSRegistrationUpdateCheckErrorKey]
+ boolValue]) {
[self updateStatus:kAutoupdateCheckFailed version:nil];
- } else if ([[userInfo objectForKey:KSRegistrationStatusKey] boolValue]) {
+ } else if ([[userInfo objectForKey:ksr::KSRegistrationStatusKey] boolValue]) {
// If an update is known to be available, go straight to
// -updateStatus:version:. It doesn't matter what's currently on disk.
- NSString* version = [userInfo objectForKey:KSRegistrationVersionKey];
+ NSString* version = [userInfo objectForKey:ksr::KSRegistrationVersionKey];
[self updateStatus:kAutoupdateAvailable version:version];
} else {
// If no updates are available, check what's on disk, because an update
@@ -599,15 +542,15 @@ NSString* const kVersionKey = @"KSVersion";
[registration_ startUpdate];
- // Upon completion, KSRegistrationStartUpdateNotification will be posted,
- // and -installUpdateComplete: will be called.
+ // Upon completion, ksr::KSRegistrationStartUpdateNotification will be
+ // posted, and -installUpdateComplete: will be called.
}
- (void)installUpdateComplete:(NSNotification*)notification {
NSDictionary* userInfo = [notification userInfo];
- if (![[userInfo objectForKey:KSUpdateCheckSuccessfulKey] boolValue] ||
- ![[userInfo objectForKey:KSUpdateCheckSuccessfullyInstalledKey]
+ if (![[userInfo objectForKey:ksr::KSUpdateCheckSuccessfulKey] boolValue] ||
+ ![[userInfo objectForKey:ksr::KSUpdateCheckSuccessfullyInstalledKey]
intValue]) {
[self updateStatus:kAutoupdateInstallFailed version:nil];
} else {
@@ -712,7 +655,7 @@ NSString* const kVersionKey = @"KSVersion";
}
- (BOOL)isUserTicket {
- return [registration_ ticketType] == kKSRegistrationUserTicket;
+ return [registration_ ticketType] == ksr::kKSRegistrationUserTicket;
}
- (BOOL)isOnReadOnlyFilesystem {
@@ -875,7 +818,7 @@ NSString* const kVersionKey = @"KSVersion";
NSMutableDictionary* temp_parameters =
[[parameters mutableCopy] autorelease];
[temp_parameters setObject:SystemBrandFilePath()
- forKey:KSRegistrationBrandPathKey];
+ forKey:ksr::KSRegistrationBrandPathKey];
parameters = temp_parameters;
}
@@ -886,13 +829,13 @@ NSString* const kVersionKey = @"KSVersion";
return;
}
- // Upon completion, KSRegistrationPromotionDidCompleteNotification will be
- // posted, and -promotionComplete: will be called.
+ // Upon completion, ksr::KSRegistrationPromotionDidCompleteNotification will
+ // be posted, and -promotionComplete: will be called.
}
- (void)promotionComplete:(NSNotification*)notification {
NSDictionary* userInfo = [notification userInfo];
- if ([[userInfo objectForKey:KSRegistrationStatusKey] boolValue]) {
+ if ([[userInfo objectForKey:ksr::KSRegistrationStatusKey] boolValue]) {
if (synchronousPromotion_) {
// Short-circuit: if performing a synchronous promotion, the promotion
// came from the installer, which already set the permissions properly.
diff --git a/chrome/browser/cocoa/keystone_glue_unittest.mm b/chrome/browser/cocoa/keystone_glue_unittest.mm
index 9d49a09..134fac2 100644
--- a/chrome/browser/cocoa/keystone_glue_unittest.mm
+++ b/chrome/browser/cocoa/keystone_glue_unittest.mm
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,14 +6,52 @@
#import <objc/objc-class.h>
#import "chrome/browser/cocoa/keystone_glue.h"
+#import "chrome/browser/cocoa/keystone_registration.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
-@interface FakeGlueRegistration : NSObject
+namespace ksr = keystone_registration;
+
+
+@interface FakeKeystoneRegistration : KSRegistration
+@end
+
+
+// This unit test implements FakeKeystoneRegistration as a KSRegistration
+// subclass. It won't be linked against KSRegistration, so provide a stub
+// KSRegistration class on which to base FakeKeystoneRegistration.
+@implementation KSRegistration
+
++ (id)registrationWithProductID:(NSString*)productID {
+ return nil;
+}
+
+- (BOOL)registerWithParameters:(NSDictionary*)args {
+ return NO;
+}
+
+- (BOOL)promoteWithParameters:(NSDictionary*)args
+ authorization:(AuthorizationRef)authorization {
+ return NO;
+}
+
+- (void)setActive {
+}
+
+- (void)checkForUpdate {
+}
+
+- (void)startUpdate {
+}
+
+- (ksr::KSRegistrationTicketType)ticketType {
+ return ksr::kKSRegistrationDontKnowWhatKindOfTicket;
+}
+
@end
-@implementation FakeGlueRegistration
+@implementation FakeKeystoneRegistration
// Send the notifications that a real KeystoneGlue object would send.
@@ -23,14 +61,14 @@
NSDictionary* dictionary = [NSDictionary dictionaryWithObject:yesNumber
forKey:statusKey];
NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
- [center postNotificationName:@"KSRegistrationCheckForUpdateNotification"
+ [center postNotificationName:ksr::KSRegistrationCheckForUpdateNotification
object:nil
userInfo:dictionary];
}
- (void)startUpdate {
NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
- [center postNotificationName:@"KSRegistrationStartUpdateNotification"
+ [center postNotificationName:ksr::KSRegistrationStartUpdateNotification
object:nil];
}
@@ -103,7 +141,7 @@
}
- (void)addFakeRegistration {
- registration_ = [[FakeGlueRegistration alloc] init];
+ registration_ = [[FakeKeystoneRegistration alloc] init];
}
- (void)fakeAboutWindowCallback:(NSNotification*)notification {
diff --git a/chrome/browser/cocoa/keystone_registration.h b/chrome/browser/cocoa/keystone_registration.h
new file mode 100644
index 0000000..9f56c64
--- /dev/null
+++ b/chrome/browser/cocoa/keystone_registration.h
@@ -0,0 +1,72 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_COCOA_KEYSTONE_REGISTRATION_H_
+#define CHROME_BROWSER_COCOA_KEYSTONE_REGISTRATION_H_
+#pragma once
+
+#import <Foundation/Foundation.h>
+#include <Security/Authorization.h>
+
+// Declarations of the Keystone registration bits needed here. From
+// KSRegistration.h.
+
+namespace keystone_registration {
+
+typedef enum {
+ kKSPathExistenceChecker,
+} KSExistenceCheckerType;
+
+typedef enum {
+ kKSRegistrationUserTicket,
+ kKSRegistrationSystemTicket,
+ kKSRegistrationDontKnowWhatKindOfTicket,
+} KSRegistrationTicketType;
+
+extern NSString* KSRegistrationVersionKey;
+extern NSString* KSRegistrationExistenceCheckerTypeKey;
+extern NSString* KSRegistrationExistenceCheckerStringKey;
+extern NSString* KSRegistrationServerURLStringKey;
+extern NSString* KSRegistrationPreserveTrustedTesterTokenKey;
+extern NSString* KSRegistrationTagKey;
+extern NSString* KSRegistrationTagPathKey;
+extern NSString* KSRegistrationTagKeyKey;
+extern NSString* KSRegistrationBrandPathKey;
+extern NSString* KSRegistrationBrandKeyKey;
+extern NSString* KSRegistrationVersionPathKey;
+extern NSString* KSRegistrationVersionKeyKey;
+
+extern NSString* KSRegistrationDidCompleteNotification;
+extern NSString* KSRegistrationPromotionDidCompleteNotification;
+
+extern NSString* KSRegistrationCheckForUpdateNotification;
+extern NSString* KSRegistrationStatusKey;
+extern NSString* KSRegistrationUpdateCheckErrorKey;
+
+extern NSString* KSRegistrationStartUpdateNotification;
+extern NSString* KSUpdateCheckSuccessfulKey;
+extern NSString* KSUpdateCheckSuccessfullyInstalledKey;
+
+extern NSString* KSRegistrationRemoveExistingTag;
+#define KSRegistrationPreserveExistingTag nil
+
+} // namespace keystone_registration
+
+@interface KSRegistration : NSObject
+
++ (id)registrationWithProductID:(NSString*)productID;
+
+- (BOOL)registerWithParameters:(NSDictionary*)args;
+
+- (BOOL)promoteWithParameters:(NSDictionary*)args
+ authorization:(AuthorizationRef)authorization;
+
+- (void)setActive;
+- (void)checkForUpdate;
+- (void)startUpdate;
+- (keystone_registration::KSRegistrationTicketType)ticketType;
+
+@end // @interface KSRegistration
+
+#endif // CHROME_BROWSER_COCOA_KEYSTONE_REGISTRATION_H_
diff --git a/chrome/browser/cocoa/keystone_registration.mm b/chrome/browser/cocoa/keystone_registration.mm
new file mode 100644
index 0000000..306001b
--- /dev/null
+++ b/chrome/browser/cocoa/keystone_registration.mm
@@ -0,0 +1,42 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "chrome/browser/cocoa/keystone_registration.h"
+
+namespace keystone_registration {
+
+// Definitions of the Keystone registration constants needed here. From
+// KSRegistration.m.
+
+NSString* KSRegistrationVersionKey = @"Version";
+NSString* KSRegistrationExistenceCheckerTypeKey = @"ExistenceCheckerType";
+NSString* KSRegistrationExistenceCheckerStringKey = @"ExistenceCheckerString";
+NSString* KSRegistrationServerURLStringKey = @"URLString";
+NSString* KSRegistrationPreserveTrustedTesterTokenKey = @"PreserveTTT";
+NSString* KSRegistrationTagKey = @"Tag";
+NSString* KSRegistrationTagPathKey = @"TagPath";
+NSString* KSRegistrationTagKeyKey = @"TagKey";
+NSString* KSRegistrationBrandPathKey = @"BrandPath";
+NSString* KSRegistrationBrandKeyKey = @"BrandKey";
+NSString* KSRegistrationVersionPathKey = @"VersionPath";
+NSString* KSRegistrationVersionKeyKey = @"VersionKey";
+
+NSString* KSRegistrationDidCompleteNotification =
+ @"KSRegistrationDidCompleteNotification";
+NSString* KSRegistrationPromotionDidCompleteNotification =
+ @"KSRegistrationPromotionDidCompleteNotification";
+
+NSString* KSRegistrationCheckForUpdateNotification =
+ @"KSRegistrationCheckForUpdateNotification";
+NSString* KSRegistrationStatusKey = @"Status";
+NSString* KSRegistrationUpdateCheckErrorKey = @"Error";
+
+NSString* KSRegistrationStartUpdateNotification =
+ @"KSRegistrationStartUpdateNotification";
+NSString* KSUpdateCheckSuccessfulKey = @"CheckSuccessful";
+NSString* KSUpdateCheckSuccessfullyInstalledKey = @"SuccessfullyInstalled";
+
+NSString* KSRegistrationRemoveExistingTag = @"";
+
+} // namespace keystone_registration
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 6bbba88..15262c2 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -752,6 +752,8 @@
'browser/cocoa/install_from_dmg.mm',
'browser/cocoa/keystone_glue.h',
'browser/cocoa/keystone_glue.mm',
+ 'browser/cocoa/keystone_registration.h',
+ 'browser/cocoa/keystone_registration.mm',
'browser/cocoa/scoped_authorizationref.h',
'browser/command_updater.cc',
'browser/command_updater.h',