summaryrefslogtreecommitdiffstats
path: root/chrome/app
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/app')
-rw-r--r--chrome/app/keystone_glue.h33
-rw-r--r--chrome/app/keystone_glue.m81
2 files changed, 114 insertions, 0 deletions
diff --git a/chrome/app/keystone_glue.h b/chrome/app/keystone_glue.h
new file mode 100644
index 0000000..0ebc2f7
--- /dev/null
+++ b/chrome/app/keystone_glue.h
@@ -0,0 +1,33 @@
+// Copyright (c) 2009 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 WEBKIT_TOOLS_TEST_SHELL_MAC_KEYSTONE_GLUE_H_
+#define WEBKIT_TOOLS_TEST_SHELL_MAC_KEYSTONE_GLUE_H_
+
+#import <Foundation/Foundation.h>
+
+// KeystoneGlue is an adapter around the KSRegistration class, allowing it to
+// be used without linking directly against its containing KeystoneRegistration
+// framework. This is used in an environment where most builds (such as
+// developer builds) don't want or need Keystone support and might not even
+// have the framework available. Enabling Keystone support in an application
+// that uses KeystoneGlue is as simple as dropping
+// KeystoneRegistration.framework in the application's Frameworks directory
+// and providing the relevant information in its Info.plist. KeystoneGlue
+// requires that the KSUpdateURL key be set in the application's Info.plist,
+// and that it contain a string identifying the update URL to be used by
+// Keystone.
+
+@interface KeystoneGlue : NSObject
+
+// Load KeystoneRegistration.framework if present, call into it to register
+// with Keystone, and set up periodic activity pings.
++ (void)registerWithKeystone;
+
+// Called periodically to announce activity by pinging the Keystone server.
++ (void)markActive:(NSTimer*)timer;
+
+@end
+
+#endif // WEBKIT_TOOLS_TEST_SHELL_MAC_KEYSTONE_GLUE_H_
diff --git a/chrome/app/keystone_glue.m b/chrome/app/keystone_glue.m
new file mode 100644
index 0000000..45ae1c2
--- /dev/null
+++ b/chrome/app/keystone_glue.m
@@ -0,0 +1,81 @@
+// Copyright (c) 2009 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 "keystone_glue.h"
+
+// Provide declarations of the Keystone registration bits needed here. From
+// KSRegistration.h.
+typedef enum { kKSPathExistenceChecker } KSExistenceCheckerType;
+@interface KSRegistration : NSObject
++ (id)registrationWithProductID:(NSString*)productID;
+- (BOOL)registerWithVersion:(NSString*)version
+ existenceCheckerType:(KSExistenceCheckerType)xctype
+ existenceCheckerString:(NSString*)xc
+ serverURLString:(NSString*)serverURLString;
+- (void)setActive;
+@end
+
+@implementation KeystoneGlue
+
+// TODO(mmentovai): Determine if the app is writable, and don't register for
+// updates if not - but keep the periodic activity pings.
++ (void)registerWithKeystone {
+ // Figure out who we are.
+ NSBundle* mainBundle = [NSBundle mainBundle];
+ NSDictionary* infoDictionary = [mainBundle infoDictionary];
+ NSString* url = [infoDictionary objectForKey:@"KSUpdateURL"];
+ NSString* bundleIdentifier = [infoDictionary objectForKey:@"KSProductID"];
+ if (bundleIdentifier == nil) {
+ bundleIdentifier = [mainBundle bundleIdentifier];
+ }
+ // TODO(mmentovai): The svn version serves our purposes for now, but it will
+ // likely be replaced. The key problem is that it does not monotonically
+ // increase for releases when considering svn branches and tags. For the
+ // purposes of TestShell, though, which will likely only ever survive in
+ // auto-updatable form in builds straight from the trunk, this is fine.
+ NSString* version = [infoDictionary objectForKey:@"SVNRevision"];
+ if (!bundleIdentifier || !url || !version) {
+ // If parameters required for Keystone are missing, don't use it.
+ return;
+ }
+
+ // Load the KeystoneRegistration framework bundle.
+ NSString* ksrPath =
+ [[mainBundle privateFrameworksPath]
+ stringByAppendingPathComponent:@"KeystoneRegistration.framework"];
+ NSBundle* ksrBundle = [NSBundle bundleWithPath:ksrPath];
+ [ksrBundle load];
+
+ // Harness the KSRegistration class.
+ Class ksrClass = [ksrBundle classNamed:@"KSRegistration"];
+ KSRegistration* ksr = [ksrClass registrationWithProductID:bundleIdentifier];
+ if (!ksr) {
+ // Strictly speaking, this isn't necessary, because it's harmless to send
+ // messages to nil. However, if there really isn't a
+ // KeystoneRegistration.framework or KSRegistration class, bailing out here
+ // avoids setting up the timer that will only be able to perform no-ops.
+ return;
+ }
+
+ // Keystone will asynchronously handle installation and registration as
+ // needed.
+ [ksr registerWithVersion:version
+ existenceCheckerType:kKSPathExistenceChecker
+ existenceCheckerString:[mainBundle bundlePath]
+ serverURLString:url];
+
+ // Set up hourly activity pings.
+ [NSTimer scheduledTimerWithTimeInterval:60 * 60 // One hour
+ target:self
+ selector:@selector(markActive:)
+ userInfo:ksr
+ repeats:YES];
+}
+
++ (void)markActive:(NSTimer*)timer {
+ KSRegistration* ksr = [timer userInfo];
+ [ksr setActive];
+}
+
+@end