Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 #include "chrome/browser/ui/autofill/chrome_autofill_client.h" | |
| 6 | |
| 7 #import <Cocoa/Cocoa.h> | |
| 8 | |
| 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" | |
| 13 | |
| 14 // Listens to Keystone notifications and passes relevant ones on to the | |
| 15 // PersonalDataManager. | |
| 16 @interface AutofillKeystoneBridge : NSObject { | |
| 17 @private | |
| 18 // The personal data manager is expected to outlive this object. | |
| 19 autofill::PersonalDataManager* personal_data_manager_; | |
| 20 } | |
| 21 | |
| 22 // Designated initializer. The personal data manager is expected to outlive | |
| 23 // this object. | |
| 24 - (instancetype)initWithPersonalDataManager: | |
| 25 (autofill::PersonalDataManager*)personal_data_manager; | |
| 26 | |
| 27 // Receieved a notification from Keystone. | |
| 28 - (void)handleStatusNotification:(NSNotification*)notification; | |
| 29 @end | |
| 30 | |
| 31 @implementation AutofillKeystoneBridge | |
| 32 | |
| 33 - (instancetype)init { | |
| 34 NOTREACHED(); | |
| 35 return nil; | |
| 36 } | |
| 37 | |
| 38 - (instancetype)initWithPersonalDataManager: | |
| 39 (autofill::PersonalDataManager*)personal_data_manager { | |
| 40 DCHECK(personal_data_manager); | |
| 41 self = [super init]; | |
| 42 if (self) { | |
| 43 personal_data_manager_ = personal_data_manager; | |
| 44 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; | |
| 45 [center addObserver:self | |
| 46 selector:@selector(handleStatusNotification:) | |
| 47 name:kAutoupdateStatusNotification | |
| 48 object:nil]; | |
| 49 } | |
| 50 return self; | |
| 51 } | |
| 52 | |
| 53 - (void)dealloc { | |
| 54 [[NSNotificationCenter defaultCenter] removeObserver:self]; | |
| 55 [super dealloc]; | |
| 56 } | |
| 57 | |
| 58 - (void)handleStatusNotification:(NSNotification*)notification { | |
| 59 NSNumber* statusNumber = | |
| 60 [[notification userInfo] objectForKey:kAutoupdateStatusStatus]; | |
| 61 DCHECK(statusNumber); | |
| 62 DCHECK([statusNumber isKindOfClass:[NSNumber class]]); | |
| 63 keystone_glue::AutoupdateStatus status = | |
| 64 static_cast<keystone_glue::AutoupdateStatus>([statusNumber intValue]); | |
| 65 | |
| 66 switch (status) { | |
| 67 case keystone_glue::kAutoupdateInstalling: | |
| 68 case keystone_glue::kAutoupdateInstalled: { | |
| 69 personal_data_manager_->BinaryChanging(); | |
| 70 return; | |
| 71 } | |
| 72 default: | |
| 73 return; | |
| 74 } | |
| 75 } | |
| 76 | |
| 77 @end | |
| 78 | |
| 79 namespace autofill { | |
| 80 | |
| 81 class AutofillKeystoneBridgeWrapper { | |
| 82 public: | |
| 83 explicit AutofillKeystoneBridgeWrapper( | |
| 84 PersonalDataManager* personal_data_manager) { | |
| 85 bridge_.reset([[AutofillKeystoneBridge alloc] | |
| 86 initWithPersonalDataManager:personal_data_manager]); | |
| 87 } | |
| 88 ~AutofillKeystoneBridgeWrapper() {} | |
| 89 | |
| 90 private: | |
| 91 base::scoped_nsobject<AutofillKeystoneBridge> bridge_; | |
| 92 | |
| 93 DISALLOW_COPY_AND_ASSIGN(AutofillKeystoneBridgeWrapper); | |
| 94 }; | |
| 95 | |
| 96 void ChromeAutofillClient::RegisterForKeystoneNotifications() { | |
| 97 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.
| |
| 98 } | |
| 99 | |
| 100 void ChromeAutofillClient::UnregisterFromKeystoneNotifications() { | |
| 101 delete bridge_wrapper_; | |
| 102 } | |
| 103 | |
| 104 } // namespace autofill | |
| OLD | NEW |