Index: chrome/browser/extensions/api/autofill_private/autofill_private_event_router.cc |
diff --git a/chrome/browser/extensions/api/autofill_private/autofill_private_event_router.cc b/chrome/browser/extensions/api/autofill_private/autofill_private_event_router.cc |
index 5162c97f582b7c0311669283e7acd1a70ce2aadd..f1fd03426cb93470a7610b01958ec0f1f320a771 100644 |
--- a/chrome/browser/extensions/api/autofill_private/autofill_private_event_router.cc |
+++ b/chrome/browser/extensions/api/autofill_private/autofill_private_event_router.cc |
@@ -40,35 +40,15 @@ AutofillPrivateEventRouter::AutofillPrivateEventRouter( |
if (!personal_data_) |
return; |
- event_router_->RegisterObserver( |
- this, |
- api::autofill_private::OnAddressListChanged::kEventName); |
- event_router_->RegisterObserver( |
- this, |
- api::autofill_private::OnCreditCardListChanged::kEventName); |
- StartOrStopListeningForChanges(); |
+ personal_data_->AddObserver(this); |
} |
AutofillPrivateEventRouter::~AutofillPrivateEventRouter() { |
} |
void AutofillPrivateEventRouter::Shutdown() { |
- if (event_router_) |
- event_router_->UnregisterObserver(this); |
-} |
- |
-void AutofillPrivateEventRouter::OnListenerAdded( |
- const EventListenerInfo& details) { |
- // Start listening to change events and propagate the original lists to |
- // listeners. |
- StartOrStopListeningForChanges(); |
- OnPersonalDataChanged(); |
-} |
- |
-void AutofillPrivateEventRouter::OnListenerRemoved( |
- const EventListenerInfo& details) { |
- // Stop listening to events if there are no more listeners. |
- StartOrStopListeningForChanges(); |
+ if (personal_data_) |
+ personal_data_->RemoveObserver(this); |
} |
void AutofillPrivateEventRouter::OnPersonalDataChanged() { |
@@ -97,25 +77,6 @@ void AutofillPrivateEventRouter::OnPersonalDataChanged() { |
event_router_->BroadcastEvent(std::move(extension_event)); |
} |
-void AutofillPrivateEventRouter::StartOrStopListeningForChanges() { |
- if (!personal_data_ || !personal_data_->IsDataLoaded()) |
- return; |
- |
- bool should_listen_for_address_changes = event_router_->HasEventListener( |
- api::autofill_private::OnAddressListChanged::kEventName); |
- bool should_listen_for_credit_card_changes = event_router_->HasEventListener( |
- api::autofill_private::OnCreditCardListChanged::kEventName); |
- bool should_listen = should_listen_for_address_changes || |
- should_listen_for_credit_card_changes; |
- |
- if (should_listen && !listening_) |
- personal_data_->AddObserver(this); |
- else if (!should_listen && listening_) |
- personal_data_->RemoveObserver(this); |
- |
- listening_ = should_listen; |
-} |
- |
AutofillPrivateEventRouter* AutofillPrivateEventRouter::Create( |
content::BrowserContext* context) { |
return new AutofillPrivateEventRouter(context); |