Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1737)

Unified Diff: chrome/browser/extensions/api/autofill_private/autofill_private_event_router.cc

Issue 1957043002: Separate the listeners and getters for the Autofill Private API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@autofill-lists.gitbr
Patch Set: update histogram.xml and test Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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);

Powered by Google App Engine
This is Rietveld 408576698