Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / ui / autofill / chrome_autofill_client_mac.mm
blob94a25c5176d436aa026c2b85a0e10ec91c8ec360
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 {
17  @private
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;
29 @end
31 @implementation AutofillKeystoneBridge
33 - (instancetype)init {
34   NOTREACHED();
35   return nil;
38 - (instancetype)initWithPersonalDataManager:
39     (autofill::PersonalDataManager*)personal_data_manager {
40   self = [super init];
41   if (self) {
42     personal_data_manager_ = personal_data_manager;
43     NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
44     [center addObserver:self
45                selector:@selector(handleStatusNotification:)
46                    name:kAutoupdateStatusNotification
47                  object:nil];
48   }
49   return self;
52 - (void)dealloc {
53   [[NSNotificationCenter defaultCenter] removeObserver:self];
54   [super dealloc];
57 - (void)handleStatusNotification:(NSNotification*)notification {
58   if (!personal_data_manager_)
59     return;
61   NSNumber* statusNumber =
62       [[notification userInfo] objectForKey:kAutoupdateStatusStatus];
63   DCHECK(statusNumber);
64   DCHECK([statusNumber isKindOfClass:[NSNumber class]]);
65   AutoupdateStatus status =
66       static_cast<AutoupdateStatus>([statusNumber intValue]);
68   switch (status) {
69     case kAutoupdateInstalling:
70     case kAutoupdateInstalled: {
71       personal_data_manager_->BinaryChanging();
72       return;
73     }
74     default:
75       return;
76   }
79 @end
81 namespace autofill {
83 class AutofillKeystoneBridgeWrapper {
84  public:
85   explicit AutofillKeystoneBridgeWrapper(
86       PersonalDataManager* personal_data_manager) {
87     bridge_.reset([[AutofillKeystoneBridge alloc]
88         initWithPersonalDataManager:personal_data_manager]);
89   }
90   ~AutofillKeystoneBridgeWrapper() {}
92  private:
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