Index: chrome/browser/autofill/autofill_keystone_observer_mac.mm |
diff --git a/chrome/browser/autofill/autofill_keystone_observer_mac.mm b/chrome/browser/autofill/autofill_keystone_observer_mac.mm |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a67fdd8e61d659dcb9907db00cc0339299439a4f |
--- /dev/null |
+++ b/chrome/browser/autofill/autofill_keystone_observer_mac.mm |
@@ -0,0 +1,75 @@ |
+// Copyright 2014 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/autofill/autofill_keystone_observer_mac.h" |
+ |
+#import <Cocoa/Cocoa.h> |
+ |
+#include "base/logging.h" |
+#import "chrome/browser/autofill/autofill_keystone_observer_mac_delegate.h" |
+#import "chrome/browser/mac/keystone_glue.h" |
+ |
+// Listens to Keystone notifications and passes them on to the delegate. |
+@interface AutofillKeystoneBridge : NSObject { |
+ @private |
+ AutofillKeystoneObserverMacDelegate* delegate_; |
Ilya Sherman
2014/06/14 01:18:50
Please document lifetime expectations here as well
erikchen
2014/06/16 20:30:45
Done.
|
+} |
+ |
+// Designated initializer. The delegate is expected to outlive this object. |
+- (instancetype)initWithDelegate:(AutofillKeystoneObserverMacDelegate*)delegate; |
+ |
+// Receieved a notification from Keystone. |
+- (void)handleStatusNotification:(NSNotification*)notification; |
+@end |
+ |
+@implementation AutofillKeystoneBridge |
+ |
+- (instancetype)init { |
+ NOTREACHED(); |
+ return nil; |
+} |
+ |
+- (instancetype)initWithDelegate: |
+ (AutofillKeystoneObserverMacDelegate*)delegate { |
+ DCHECK(delegate); |
+ self = [super init]; |
+ if (self) { |
+ delegate_ = delegate; |
+ NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; |
+ [center addObserver:self |
+ selector:@selector(handleStatusNotification:) |
+ name:kAutoupdateStatusNotification |
+ object:nil]; |
+ } |
+ return self; |
+} |
+ |
+- (void)dealloc { |
+ [[NSNotificationCenter defaultCenter] removeObserver:self]; |
+ [super dealloc]; |
+} |
+ |
+- (void)handleStatusNotification:(NSNotification*)notification { |
+ NSNumber* statusNumber = |
+ [[notification userInfo] objectForKey:kAutoupdateStatusStatus]; |
+ DCHECK(statusNumber); |
+ DCHECK([statusNumber isKindOfClass:[NSNumber class]]); |
+ keystone_glue::AutoupdateStatus status = |
+ static_cast<keystone_glue::AutoupdateStatus>([statusNumber intValue]); |
+ delegate_->OnKeystoneNotification(status); |
+} |
+ |
+@end |
+ |
+namespace autofill { |
+ |
+AutofillKeystoneObserverMac::AutofillKeystoneObserverMac( |
+ AutofillKeystoneObserverMacDelegate* delegate) { |
+ bridge_.reset([[AutofillKeystoneBridge alloc] initWithDelegate:delegate]); |
+} |
+ |
+AutofillKeystoneObserverMac::~AutofillKeystoneObserverMac() { |
+} |
+ |
+} // namespace autofill |