1 // Copyright 2015 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 #ifndef CHROME_BROWSER_EXTENSIONS_API_AUTOFILL_PRIVATE_AUTOFILL_PRIVATE_EVENT_ROUTER_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_AUTOFILL_PRIVATE_AUTOFILL_PRIVATE_EVENT_ROUTER_H_
8 #include "components/autofill/core/browser/personal_data_manager_observer.h"
9 #include "components/keyed_service/core/keyed_service.h"
10 #include "extensions/browser/event_router.h"
13 class PersonalDataManager
;
20 namespace extensions
{
22 // An event router that observes changes to autofill addresses and credit cards
23 // and notifies listeners to the onAddressListChanged and
24 // onCreditCardListChanged events of changes.
25 class AutofillPrivateEventRouter
:
27 public EventRouter::Observer
,
28 public autofill::PersonalDataManagerObserver
{
30 static AutofillPrivateEventRouter
* Create(
31 content::BrowserContext
* browser_context
);
32 ~AutofillPrivateEventRouter() override
;
35 explicit AutofillPrivateEventRouter(content::BrowserContext
* context
);
37 // KeyedService overrides:
38 void Shutdown() override
;
40 // EventRouter::Observer overrides:
41 void OnListenerAdded(const EventListenerInfo
& details
) override
;
42 void OnListenerRemoved(const EventListenerInfo
& details
) override
;
44 // PersonalDataManagerObserver implementation.
45 void OnPersonalDataChanged() override
;
48 // Either listens or unlistens for changes to |personal_data_|, depending on
49 // whether clients are listening to the autofillPrivate API events.
50 void StartOrStopListeningForChanges();
52 content::BrowserContext
* context_
;
54 EventRouter
* event_router_
;
56 autofill::PersonalDataManager
* personal_data_
;
58 // Whether this class is currently listening for changes to |personal_data_|.
61 DISALLOW_COPY_AND_ASSIGN(AutofillPrivateEventRouter
);
64 } // namespace extensions
66 #endif // CHROME_BROWSER_EXTENSIONS_API_AUTOFILL_PRIVATE_AUTOFILL_PRIVATE_EVENT_ROUTER_H_