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

Unified Diff: extensions/browser/event_router.h

Issue 2887293003: Modernize some extensions code. (Closed)
Patch Set: address comments Created 3 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
« no previous file with comments | « extensions/browser/event_listener_map_unittest.cc ('k') | extensions/browser/event_router.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/browser/event_router.h
diff --git a/extensions/browser/event_router.h b/extensions/browser/event_router.h
index 48bc266980cce4ce121f64a3402d8afbc5926e8a..83bc635e38ba4cacfbb1814b8339ce90a1f11ccf 100644
--- a/extensions/browser/event_router.h
+++ b/extensions/browser/event_router.h
@@ -7,11 +7,11 @@
#include <set>
#include <string>
+#include <unordered_map>
#include <utility>
#include "base/callback.h"
#include "base/compiler_specific.h"
-#include "base/containers/hash_tables.h"
#include "base/macros.h"
#include "base/memory/linked_ptr.h"
#include "base/memory/ref_counted.h"
@@ -72,6 +72,9 @@ class EventRouter : public KeyedService,
virtual void OnListenerAdded(const EventListenerInfo& details) {}
// Called when a listener is removed.
virtual void OnListenerRemoved(const EventListenerInfo& details) {}
+
+ protected:
+ virtual ~Observer() {}
};
// Gets the EventRouter for |browser_context|.
@@ -126,8 +129,7 @@ class EventRouter : public KeyedService,
// Registers an observer to be notified when an event listener for
// |event_name| is added or removed. There can currently be only one observer
// for each distinct |event_name|.
- void RegisterObserver(Observer* observer,
- const std::string& event_name);
+ void RegisterObserver(Observer* observer, const std::string& event_name);
// Unregisters an observer from all events.
void UnregisterObserver(Observer* observer);
@@ -157,11 +159,12 @@ class EventRouter : public KeyedService,
bool remove_lazy_listener);
// Returns true if there is at least one listener for the given event.
- bool HasEventListener(const std::string& event_name);
+ bool HasEventListener(const std::string& event_name) const;
// Returns true if the extension is listening to the given event.
+ // (virtual for testing only.)
virtual bool ExtensionHasEventListener(const std::string& extension_id,
- const std::string& event_name);
+ const std::string& event_name) const;
// Broadcasts an event to every listener registered for that event.
virtual void BroadcastEvent(std::unique_ptr<Event> event);
@@ -321,11 +324,11 @@ class EventRouter : public KeyedService,
int exit_code) override;
void RenderProcessHostDestroyed(content::RenderProcessHost* host) override;
- content::BrowserContext* browser_context_;
+ content::BrowserContext* const browser_context_;
// The ExtensionPrefs associated with |browser_context_|. May be NULL in
// tests.
- ExtensionPrefs* extension_prefs_;
+ ExtensionPrefs* const extension_prefs_;
content::NotificationRegistrar registrar_;
@@ -335,7 +338,7 @@ class EventRouter : public KeyedService,
EventListenerMap listeners_;
// Map from base event name to observer.
- typedef base::hash_map<std::string, Observer*> ObserverMap;
+ using ObserverMap = std::unordered_map<std::string, Observer*>;
ObserverMap observers_;
std::set<content::RenderProcessHost*> observed_process_set_;
@@ -346,19 +349,19 @@ class EventRouter : public KeyedService,
struct Event {
// This callback should return true if the event should be dispatched to the
// given context and extension, and false otherwise.
- typedef base::Callback<bool(content::BrowserContext*,
- const Extension*,
- Event*,
- const base::DictionaryValue*)>
- WillDispatchCallback;
+ using WillDispatchCallback =
+ base::Callback<bool(content::BrowserContext*,
+ const Extension*,
+ Event*,
+ const base::DictionaryValue*)>;
// The identifier for the event, for histograms. In most cases this
// correlates 1:1 with |event_name|, in some cases events will generate
// their own names, but they cannot generate their own identifier.
- events::HistogramValue histogram_value;
+ const events::HistogramValue histogram_value;
// The event to dispatch.
- std::string event_name;
+ const std::string event_name;
// Arguments to send to the event listener.
std::unique_ptr<base::ListValue> event_args;
@@ -423,7 +426,7 @@ struct EventListenerInfo {
const std::string extension_id;
const GURL listener_url;
- content::BrowserContext* browser_context;
+ content::BrowserContext* const browser_context;
};
} // namespace extensions
« no previous file with comments | « extensions/browser/event_listener_map_unittest.cc ('k') | extensions/browser/event_router.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698