Chromium Code Reviews| Index: extensions/browser/event_router.cc |
| diff --git a/extensions/browser/event_router.cc b/extensions/browser/event_router.cc |
| index 77c5316da9ba4cb0a1eddaa49f94d7ea9128b164..d1a24ac661919c2be03efe1eeaf29a2778928588 100644 |
| --- a/extensions/browser/event_router.cc |
| +++ b/extensions/browser/event_router.cc |
| @@ -324,7 +324,7 @@ bool EventRouter::ExtensionHasEventListener(const std::string& extension_id, |
| } |
| std::set<std::string> EventRouter::GetRegisteredEvents( |
| - const std::string& extension_id) { |
| + const std::string& extension_id) const { |
| std::set<std::string> events; |
| const ListValue* events_value = NULL; |
| @@ -342,36 +342,6 @@ std::set<std::string> EventRouter::GetRegisteredEvents( |
| return events; |
| } |
| -void EventRouter::SetRegisteredEvents(const std::string& extension_id, |
| - const std::set<std::string>& events) { |
| - auto events_value = base::MakeUnique<base::ListValue>(); |
| - for (std::set<std::string>::const_iterator iter = events.begin(); |
| - iter != events.end(); ++iter) { |
| - events_value->AppendString(*iter); |
| - } |
| - extension_prefs_->UpdateExtensionPref(extension_id, kRegisteredEvents, |
| - std::move(events_value)); |
| -} |
| - |
| -void EventRouter::AddFilterToEvent(const std::string& event_name, |
| - const std::string& extension_id, |
| - const DictionaryValue* filter) { |
| - ExtensionPrefs::ScopedDictionaryUpdate update( |
| - extension_prefs_, extension_id, kFilteredEvents); |
| - DictionaryValue* filtered_events = update.Get(); |
| - if (!filtered_events) |
| - filtered_events = update.Create(); |
| - |
| - ListValue* filter_list = nullptr; |
| - if (!filtered_events->GetListWithoutPathExpansion(event_name, &filter_list)) { |
| - filter_list = new ListValue; |
| - filtered_events->SetWithoutPathExpansion(event_name, |
| - base::WrapUnique(filter_list)); |
| - } |
| - |
| - filter_list->Append(filter->CreateDeepCopy()); |
| -} |
| - |
| void EventRouter::RemoveFilterFromEvent(const std::string& event_name, |
| const std::string& extension_id, |
| const DictionaryValue* filter) { |
| @@ -689,6 +659,15 @@ void EventRouter::OnEventAck(BrowserContext* context, |
| pm->DecrementLazyKeepaliveCount(host->extension()); |
| } |
| +bool EventRouter::HasRegisteredEvents(const ExtensionId& extension_id) const { |
| + return !GetRegisteredEvents(extension_id).empty(); |
| +} |
| + |
| +void EventRouter::ClearRegisteredEventsForTest( |
| + const ExtensionId& extension_id) { |
| + SetRegisteredEvents(extension_id, std::set<std::string>()); |
| +} |
| + |
| void EventRouter::ReportEvent(events::HistogramValue histogram_value, |
| const Extension* extension, |
| bool did_enqueue) { |
| @@ -754,6 +733,36 @@ void EventRouter::DispatchPendingEvent(const linked_ptr<Event>& event, |
| } |
| } |
| +void EventRouter::SetRegisteredEvents(const std::string& extension_id, |
|
lazyboy
2017/05/11 20:58:49
note: This block is moved from line 345.
|
| + const std::set<std::string>& events) { |
| + auto events_value = base::MakeUnique<base::ListValue>(); |
| + for (std::set<std::string>::const_iterator iter = events.begin(); |
| + iter != events.end(); ++iter) { |
| + events_value->AppendString(*iter); |
| + } |
| + extension_prefs_->UpdateExtensionPref(extension_id, kRegisteredEvents, |
| + std::move(events_value)); |
| +} |
| + |
| +void EventRouter::AddFilterToEvent(const std::string& event_name, |
| + const std::string& extension_id, |
| + const DictionaryValue* filter) { |
| + ExtensionPrefs::ScopedDictionaryUpdate update(extension_prefs_, extension_id, |
| + kFilteredEvents); |
| + DictionaryValue* filtered_events = update.Get(); |
| + if (!filtered_events) |
| + filtered_events = update.Create(); |
| + |
| + ListValue* filter_list = nullptr; |
| + if (!filtered_events->GetListWithoutPathExpansion(event_name, &filter_list)) { |
| + filter_list = new ListValue; |
| + filtered_events->SetWithoutPathExpansion(event_name, |
| + base::WrapUnique(filter_list)); |
| + } |
| + |
| + filter_list->Append(filter->CreateDeepCopy()); |
| +} |
| + |
| void EventRouter::Observe(int type, |
| const content::NotificationSource& source, |
| const content::NotificationDetails& details) { |