Index: chrome/browser/extensions/api/search_engines_private/search_engines_private_event_router.h |
diff --git a/chrome/browser/extensions/api/search_engines_private/search_engines_private_event_router.h b/chrome/browser/extensions/api/search_engines_private/search_engines_private_event_router.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e98b3456b8f719b02fe33e1c4d9dcbdb947fe1c4 |
--- /dev/null |
+++ b/chrome/browser/extensions/api/search_engines_private/search_engines_private_event_router.h |
@@ -0,0 +1,62 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CHROME_BROWSER_EXTENSIONS_API_SEARCH_ENGINES_PRIVATE_SEARCH_ENGINES_PRIVATE_EVENT_ROUTER_H_ |
+#define CHROME_BROWSER_EXTENSIONS_API_SEARCH_ENGINES_PRIVATE_SEARCH_ENGINES_PRIVATE_EVENT_ROUTER_H_ |
+ |
+#include "components/keyed_service/core/keyed_service.h" |
+#include "components/search_engines/template_url_service.h" |
+#include "components/search_engines/template_url_service_observer.h" |
+#include "extensions/browser/event_router.h" |
+ |
+namespace content { |
+class BrowserContext; |
+} |
+ |
+namespace extensions { |
+ |
+class SearchEnginesPrivateDelegate; |
+ |
+// This is an event router that will observe listeners to search engines changes |
+// and notify listeners on the JavaScript searchEnginesPrivate API. |
stevenjb
2015/04/23 17:26:01
nit: Clarify "observe listeners to search engines
Oren Blasberg
2015/04/23 21:31:51
Done.
|
+class SearchEnginesPrivateEventRouter : public KeyedService, |
+ public EventRouter::Observer, |
+ public TemplateURLServiceObserver { |
+ public: |
+ static SearchEnginesPrivateEventRouter* Create( |
+ content::BrowserContext* browser_context); |
+ ~SearchEnginesPrivateEventRouter() override; |
+ |
+ // TemplateURLServiceObserver implementation. |
+ void OnTemplateURLServiceChanged() override; |
+ |
+ protected: |
+ SearchEnginesPrivateEventRouter() {} |
stevenjb
2015/04/23 17:26:01
Don't inline the constructor, and please initializ
Oren Blasberg
2015/04/23 21:31:51
Done.
|
+ explicit SearchEnginesPrivateEventRouter(content::BrowserContext* context); |
stevenjb
2015/04/23 17:26:01
Ugh. Avoid multiple constructors. Default construc
Oren Blasberg
2015/04/23 21:31:51
Done.
|
+ |
+ // KeyedService overrides: |
+ void Shutdown() override; |
+ |
+ // EventRouter::Observer overrides: |
+ void OnListenerAdded(const EventListenerInfo& details) override; |
+ void OnListenerRemoved(const EventListenerInfo& details) override; |
+ |
+ TemplateURLService* template_url_service_; |
+ |
+ private: |
+ // Decide if we should listen for search engines changes or not. If there are |
+ // any JavaScript listeners registered for the onDefaultSearchEnginesChanged |
+ // event, then we want to register for change notifications. |
+ // Otherwise, we want to unregister and not be listening for changes. |
+ void StartOrStopListeningForSearchEnginesChanges(); |
+ |
+ content::BrowserContext* context_; |
+ bool listening_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(SearchEnginesPrivateEventRouter); |
+}; |
+ |
+} // namespace extensions |
+ |
+#endif // CHROME_BROWSER_EXTENSIONS_API_SEARCH_ENGINES_PRIVATE_SEARCH_ENGINES_PRIVATE_EVENT_ROUTER_H_ |