1 // Copyright 2014 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 #include "chrome/browser/ui/autofill/chrome_autofill_client.h"
7 #import <Cocoa/Cocoa.h>
9 #include "base/logging.h"
10 #include "base/mac/scoped_nsobject.h"
11 #import "chrome/browser/mac/keystone_glue.h"
12 #include "components/autofill/core/browser/personal_data_manager.h"
14 // Listens to Keystone notifications and passes relevant ones on to the
15 // PersonalDataManager.
16 @interface AutofillKeystoneBridge : NSObject {
18 // The PersonalDataManager, if it exists, is expected to outlive this object.
19 autofill::PersonalDataManager* personal_data_manager_;
22 // Designated initializer. The PersonalDataManager, if it exists, is expected
23 // to outlive this object. The PersonalDataManager may be NULL in tests.
24 - (instancetype)initWithPersonalDataManager:
25 (autofill::PersonalDataManager*)personal_data_manager;
27 // Receieved a notification from Keystone.
28 - (void)handleStatusNotification:(NSNotification*)notification;
31 @implementation AutofillKeystoneBridge
33 - (instancetype)init {
38 - (instancetype)initWithPersonalDataManager:
39 (autofill::PersonalDataManager*)personal_data_manager {
42 personal_data_manager_ = personal_data_manager;
43 NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
44 [center addObserver:self
45 selector:@selector(handleStatusNotification:)
46 name:kAutoupdateStatusNotification
53 [[NSNotificationCenter defaultCenter] removeObserver:self];
57 - (void)handleStatusNotification:(NSNotification*)notification {
58 if (!personal_data_manager_)
61 NSNumber* statusNumber =
62 [[notification userInfo] objectForKey:kAutoupdateStatusStatus];
64 DCHECK([statusNumber isKindOfClass:[NSNumber class]]);
65 AutoupdateStatus status =
66 static_cast<AutoupdateStatus>([statusNumber intValue]);
69 case kAutoupdateInstalling:
70 case kAutoupdateInstalled: {
71 personal_data_manager_->BinaryChanging();
83 class AutofillKeystoneBridgeWrapper {
85 explicit AutofillKeystoneBridgeWrapper(
86 PersonalDataManager* personal_data_manager) {
87 bridge_.reset([[AutofillKeystoneBridge alloc]
88 initWithPersonalDataManager:personal_data_manager]);
90 ~AutofillKeystoneBridgeWrapper() {}
93 base::scoped_nsobject<AutofillKeystoneBridge> bridge_;
95 DISALLOW_COPY_AND_ASSIGN(AutofillKeystoneBridgeWrapper);
98 void ChromeAutofillClient::RegisterForKeystoneNotifications() {
99 bridge_wrapper_ = new AutofillKeystoneBridgeWrapper(GetPersonalDataManager());
102 void ChromeAutofillClient::UnregisterFromKeystoneNotifications() {
103 delete bridge_wrapper_;
106 } // namespace autofill