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

Unified Diff: chrome/browser/extensions/api/search_engines_private/search_engines_private_event_router.h

Issue 1096143003: Add chrome.searchEnginesPrivate API and Search Settings page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update OWNERS Created 5 years, 8 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/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..af62d2219b0caa9c34a4664617591e4abfcecf33
--- /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 changes to the available and
+// selected search engines via the TemplateURLService, and notify listeners to
+// events on the searchEnginesPrivate API of changes.
+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:
+ explicit SearchEnginesPrivateEventRouter(content::BrowserContext* context);
+
+ // 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_

Powered by Google App Engine
This is Rietveld 408576698