Index: chrome/browser/ui/autofill/chrome_autofill_client_mac.mm |
diff --git a/chrome/browser/ui/autofill/chrome_autofill_client_mac.mm b/chrome/browser/ui/autofill/chrome_autofill_client_mac.mm |
new file mode 100644 |
index 0000000000000000000000000000000000000000..638197cf051cd435512e8e185dabdb1c5327692b |
--- /dev/null |
+++ b/chrome/browser/ui/autofill/chrome_autofill_client_mac.mm |
@@ -0,0 +1,104 @@ |
+// 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. |
+ |
+#include "chrome/browser/ui/autofill/chrome_autofill_client.h" |
+ |
+#import <Cocoa/Cocoa.h> |
+ |
+#include "base/logging.h" |
+#include "base/mac/scoped_nsobject.h" |
+#import "chrome/browser/mac/keystone_glue.h" |
+#include "components/autofill/core/browser/personal_data_manager.h" |
+ |
+// Listens to Keystone notifications and passes relevant ones on to the |
+// PersonalDataManager. |
+@interface AutofillKeystoneBridge : NSObject { |
+ @private |
+ // The personal data manager is expected to outlive this object. |
+ autofill::PersonalDataManager* personal_data_manager_; |
+} |
+ |
+// Designated initializer. The personal data manager is expected to outlive |
+// this object. |
+- (instancetype)initWithPersonalDataManager: |
+ (autofill::PersonalDataManager*)personal_data_manager; |
+ |
+// Receieved a notification from Keystone. |
+- (void)handleStatusNotification:(NSNotification*)notification; |
+@end |
+ |
+@implementation AutofillKeystoneBridge |
+ |
+- (instancetype)init { |
+ NOTREACHED(); |
+ return nil; |
+} |
+ |
+- (instancetype)initWithPersonalDataManager: |
+ (autofill::PersonalDataManager*)personal_data_manager { |
+ DCHECK(personal_data_manager); |
+ self = [super init]; |
+ if (self) { |
+ personal_data_manager_ = personal_data_manager; |
+ 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]); |
+ |
+ switch (status) { |
+ case keystone_glue::kAutoupdateInstalling: |
+ case keystone_glue::kAutoupdateInstalled: { |
+ personal_data_manager_->BinaryChanging(); |
+ return; |
+ } |
+ default: |
+ return; |
+ } |
+} |
+ |
+@end |
+ |
+namespace autofill { |
+ |
+class AutofillKeystoneBridgeWrapper { |
+ public: |
+ explicit AutofillKeystoneBridgeWrapper( |
+ PersonalDataManager* personal_data_manager) { |
+ bridge_.reset([[AutofillKeystoneBridge alloc] |
+ initWithPersonalDataManager:personal_data_manager]); |
+ } |
+ ~AutofillKeystoneBridgeWrapper() {} |
+ |
+ private: |
+ base::scoped_nsobject<AutofillKeystoneBridge> bridge_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(AutofillKeystoneBridgeWrapper); |
+}; |
+ |
+void ChromeAutofillClient::RegisterForKeystoneNotifications() { |
+ bridge_wrapper_ = new AutofillKeystoneBridgeWrapper(GetPersonalDataManager()); |
Ilya Sherman
2014/06/17 19:55:01
I'm realizing that I forgot to answer your questio
erikchen
2014/06/17 22:36:06
ah, thanks.
|
+} |
+ |
+void ChromeAutofillClient::UnregisterFromKeystoneNotifications() { |
+ delete bridge_wrapper_; |
+} |
+ |
+} // namespace autofill |