| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "extensions/browser/event_router.h" | 5 #include "extensions/browser/event_router.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <tuple> | 9 #include <tuple> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/atomic_sequence_num.h" | 12 #include "base/atomic_sequence_num.h" |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
| 16 #include "base/memory/ptr_util.h" |
| 16 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
| 17 #include "base/metrics/histogram_macros.h" | 18 #include "base/metrics/histogram_macros.h" |
| 18 #include "base/stl_util.h" | 19 #include "base/stl_util.h" |
| 19 #include "base/values.h" | 20 #include "base/values.h" |
| 20 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
| 21 #include "content/public/browser/render_process_host.h" | 22 #include "content/public/browser/render_process_host.h" |
| 22 #include "extensions/browser/api_activity_monitor.h" | 23 #include "extensions/browser/api_activity_monitor.h" |
| 23 #include "extensions/browser/event_router_factory.h" | 24 #include "extensions/browser/event_router_factory.h" |
| 24 #include "extensions/browser/extension_host.h" | 25 #include "extensions/browser/extension_host.h" |
| 25 #include "extensions/browser/extension_prefs.h" | 26 #include "extensions/browser/extension_prefs.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 55 // A dictionary of event names to lists of filters that this extension has | 56 // A dictionary of event names to lists of filters that this extension has |
| 56 // registered from its lazy background page. | 57 // registered from its lazy background page. |
| 57 const char kFilteredEvents[] = "filtered_events"; | 58 const char kFilteredEvents[] = "filtered_events"; |
| 58 | 59 |
| 59 // Sends a notification about an event to the API activity monitor and the | 60 // Sends a notification about an event to the API activity monitor and the |
| 60 // ExtensionHost for |extension_id| on the UI thread. Can be called from any | 61 // ExtensionHost for |extension_id| on the UI thread. Can be called from any |
| 61 // thread. | 62 // thread. |
| 62 void NotifyEventDispatched(void* browser_context_id, | 63 void NotifyEventDispatched(void* browser_context_id, |
| 63 const std::string& extension_id, | 64 const std::string& extension_id, |
| 64 const std::string& event_name, | 65 const std::string& event_name, |
| 65 scoped_ptr<ListValue> args) { | 66 std::unique_ptr<ListValue> args) { |
| 66 // The ApiActivityMonitor can only be accessed from the UI thread. | 67 // The ApiActivityMonitor can only be accessed from the UI thread. |
| 67 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 68 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 68 BrowserThread::PostTask( | 69 BrowserThread::PostTask( |
| 69 BrowserThread::UI, FROM_HERE, | 70 BrowserThread::UI, FROM_HERE, |
| 70 base::Bind(&NotifyEventDispatched, browser_context_id, extension_id, | 71 base::Bind(&NotifyEventDispatched, browser_context_id, extension_id, |
| 71 event_name, base::Passed(&args))); | 72 event_name, base::Passed(&args))); |
| 72 return; | 73 return; |
| 73 } | 74 } |
| 74 | 75 |
| 75 // Notify the ApiActivityMonitor about the event dispatch. | 76 // Notify the ApiActivityMonitor about the event dispatch. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 106 // static | 107 // static |
| 107 void EventRouter::DispatchExtensionMessage(IPC::Sender* ipc_sender, | 108 void EventRouter::DispatchExtensionMessage(IPC::Sender* ipc_sender, |
| 108 void* browser_context_id, | 109 void* browser_context_id, |
| 109 const std::string& extension_id, | 110 const std::string& extension_id, |
| 110 int event_id, | 111 int event_id, |
| 111 const std::string& event_name, | 112 const std::string& event_name, |
| 112 ListValue* event_args, | 113 ListValue* event_args, |
| 113 UserGestureState user_gesture, | 114 UserGestureState user_gesture, |
| 114 const EventFilteringInfo& info) { | 115 const EventFilteringInfo& info) { |
| 115 NotifyEventDispatched(browser_context_id, extension_id, event_name, | 116 NotifyEventDispatched(browser_context_id, extension_id, event_name, |
| 116 make_scoped_ptr(event_args->DeepCopy())); | 117 base::WrapUnique(event_args->DeepCopy())); |
| 117 | 118 |
| 118 // TODO(chirantan): Make event dispatch a separate IPC so that it doesn't | 119 // TODO(chirantan): Make event dispatch a separate IPC so that it doesn't |
| 119 // piggyback off MessageInvoke, which is used for other things. | 120 // piggyback off MessageInvoke, which is used for other things. |
| 120 ListValue args; | 121 ListValue args; |
| 121 args.Set(0, new base::StringValue(event_name)); | 122 args.Set(0, new base::StringValue(event_name)); |
| 122 args.Set(1, event_args); | 123 args.Set(1, event_args); |
| 123 args.Set(2, info.AsValue().release()); | 124 args.Set(2, info.AsValue().release()); |
| 124 args.Set(3, new base::FundamentalValue(event_id)); | 125 args.Set(3, new base::FundamentalValue(event_id)); |
| 125 ipc_sender->Send(new ExtensionMsg_MessageInvoke( | 126 ipc_sender->Send(new ExtensionMsg_MessageInvoke( |
| 126 MSG_ROUTING_CONTROL, | 127 MSG_ROUTING_CONTROL, |
| 127 extension_id, | 128 extension_id, |
| 128 kEventBindings, | 129 kEventBindings, |
| 129 "dispatchEvent", | 130 "dispatchEvent", |
| 130 args, | 131 args, |
| 131 user_gesture == USER_GESTURE_ENABLED)); | 132 user_gesture == USER_GESTURE_ENABLED)); |
| 132 | 133 |
| 133 // DispatchExtensionMessage does _not_ take ownership of event_args, so we | 134 // DispatchExtensionMessage does _not_ take ownership of event_args, so we |
| 134 // must ensure that the destruction of args does not attempt to free it. | 135 // must ensure that the destruction of args does not attempt to free it. |
| 135 scoped_ptr<base::Value> removed_event_args; | 136 std::unique_ptr<base::Value> removed_event_args; |
| 136 args.Remove(1, &removed_event_args); | 137 args.Remove(1, &removed_event_args); |
| 137 ignore_result(removed_event_args.release()); | 138 ignore_result(removed_event_args.release()); |
| 138 } | 139 } |
| 139 | 140 |
| 140 // static | 141 // static |
| 141 EventRouter* EventRouter::Get(content::BrowserContext* browser_context) { | 142 EventRouter* EventRouter::Get(content::BrowserContext* browser_context) { |
| 142 return EventRouterFactory::GetForBrowserContext(browser_context); | 143 return EventRouterFactory::GetForBrowserContext(browser_context); |
| 143 } | 144 } |
| 144 | 145 |
| 145 // static | 146 // static |
| 146 std::string EventRouter::GetBaseEventName(const std::string& full_event_name) { | 147 std::string EventRouter::GetBaseEventName(const std::string& full_event_name) { |
| 147 size_t slash_sep = full_event_name.find('/'); | 148 size_t slash_sep = full_event_name.find('/'); |
| 148 return full_event_name.substr(0, slash_sep); | 149 return full_event_name.substr(0, slash_sep); |
| 149 } | 150 } |
| 150 | 151 |
| 151 // static | 152 // static |
| 152 void EventRouter::DispatchEventToSender(IPC::Sender* ipc_sender, | 153 void EventRouter::DispatchEventToSender(IPC::Sender* ipc_sender, |
| 153 void* browser_context_id, | 154 void* browser_context_id, |
| 154 const std::string& extension_id, | 155 const std::string& extension_id, |
| 155 events::HistogramValue histogram_value, | 156 events::HistogramValue histogram_value, |
| 156 const std::string& event_name, | 157 const std::string& event_name, |
| 157 scoped_ptr<ListValue> event_args, | 158 std::unique_ptr<ListValue> event_args, |
| 158 UserGestureState user_gesture, | 159 UserGestureState user_gesture, |
| 159 const EventFilteringInfo& info) { | 160 const EventFilteringInfo& info) { |
| 160 int event_id = g_extension_event_id.GetNext(); | 161 int event_id = g_extension_event_id.GetNext(); |
| 161 | 162 |
| 162 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 163 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 163 DoDispatchEventToSenderBookkeepingOnUI(browser_context_id, extension_id, | 164 DoDispatchEventToSenderBookkeepingOnUI(browser_context_id, extension_id, |
| 164 event_id, histogram_value, | 165 event_id, histogram_value, |
| 165 event_name); | 166 event_name); |
| 166 } else { | 167 } else { |
| 167 // This is called from WebRequest API. | 168 // This is called from WebRequest API. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 192 | 193 |
| 193 EventRouter::~EventRouter() { | 194 EventRouter::~EventRouter() { |
| 194 for (auto process : observed_process_set_) | 195 for (auto process : observed_process_set_) |
| 195 process->RemoveObserver(this); | 196 process->RemoveObserver(this); |
| 196 } | 197 } |
| 197 | 198 |
| 198 void EventRouter::AddEventListener(const std::string& event_name, | 199 void EventRouter::AddEventListener(const std::string& event_name, |
| 199 content::RenderProcessHost* process, | 200 content::RenderProcessHost* process, |
| 200 const std::string& extension_id) { | 201 const std::string& extension_id) { |
| 201 listeners_.AddListener(EventListener::ForExtension( | 202 listeners_.AddListener(EventListener::ForExtension( |
| 202 event_name, extension_id, process, scoped_ptr<DictionaryValue>())); | 203 event_name, extension_id, process, std::unique_ptr<DictionaryValue>())); |
| 203 } | 204 } |
| 204 | 205 |
| 205 void EventRouter::RemoveEventListener(const std::string& event_name, | 206 void EventRouter::RemoveEventListener(const std::string& event_name, |
| 206 content::RenderProcessHost* process, | 207 content::RenderProcessHost* process, |
| 207 const std::string& extension_id) { | 208 const std::string& extension_id) { |
| 208 scoped_ptr<EventListener> listener = EventListener::ForExtension( | 209 std::unique_ptr<EventListener> listener = EventListener::ForExtension( |
| 209 event_name, extension_id, process, scoped_ptr<DictionaryValue>()); | 210 event_name, extension_id, process, std::unique_ptr<DictionaryValue>()); |
| 210 listeners_.RemoveListener(listener.get()); | 211 listeners_.RemoveListener(listener.get()); |
| 211 } | 212 } |
| 212 | 213 |
| 213 void EventRouter::AddEventListenerForURL(const std::string& event_name, | 214 void EventRouter::AddEventListenerForURL(const std::string& event_name, |
| 214 content::RenderProcessHost* process, | 215 content::RenderProcessHost* process, |
| 215 const GURL& listener_url) { | 216 const GURL& listener_url) { |
| 216 listeners_.AddListener(EventListener::ForURL( | 217 listeners_.AddListener(EventListener::ForURL( |
| 217 event_name, listener_url, process, scoped_ptr<DictionaryValue>())); | 218 event_name, listener_url, process, std::unique_ptr<DictionaryValue>())); |
| 218 } | 219 } |
| 219 | 220 |
| 220 void EventRouter::RemoveEventListenerForURL(const std::string& event_name, | 221 void EventRouter::RemoveEventListenerForURL(const std::string& event_name, |
| 221 content::RenderProcessHost* process, | 222 content::RenderProcessHost* process, |
| 222 const GURL& listener_url) { | 223 const GURL& listener_url) { |
| 223 scoped_ptr<EventListener> listener = EventListener::ForURL( | 224 std::unique_ptr<EventListener> listener = EventListener::ForURL( |
| 224 event_name, listener_url, process, scoped_ptr<DictionaryValue>()); | 225 event_name, listener_url, process, std::unique_ptr<DictionaryValue>()); |
| 225 listeners_.RemoveListener(listener.get()); | 226 listeners_.RemoveListener(listener.get()); |
| 226 } | 227 } |
| 227 | 228 |
| 228 void EventRouter::RegisterObserver(Observer* observer, | 229 void EventRouter::RegisterObserver(Observer* observer, |
| 229 const std::string& event_name) { | 230 const std::string& event_name) { |
| 230 // Observing sub-event names like "foo.onBar/123" is not allowed. | 231 // Observing sub-event names like "foo.onBar/123" is not allowed. |
| 231 DCHECK(event_name.find('/') == std::string::npos); | 232 DCHECK(event_name.find('/') == std::string::npos); |
| 232 observers_[event_name] = observer; | 233 observers_[event_name] = observer; |
| 233 } | 234 } |
| 234 | 235 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 | 283 |
| 283 void EventRouter::RenderProcessHostDestroyed(content::RenderProcessHost* host) { | 284 void EventRouter::RenderProcessHostDestroyed(content::RenderProcessHost* host) { |
| 284 listeners_.RemoveListenersForProcess(host); | 285 listeners_.RemoveListenersForProcess(host); |
| 285 observed_process_set_.erase(host); | 286 observed_process_set_.erase(host); |
| 286 host->RemoveObserver(this); | 287 host->RemoveObserver(this); |
| 287 } | 288 } |
| 288 | 289 |
| 289 void EventRouter::AddLazyEventListener(const std::string& event_name, | 290 void EventRouter::AddLazyEventListener(const std::string& event_name, |
| 290 const std::string& extension_id) { | 291 const std::string& extension_id) { |
| 291 bool is_new = listeners_.AddListener(EventListener::ForExtension( | 292 bool is_new = listeners_.AddListener(EventListener::ForExtension( |
| 292 event_name, extension_id, NULL, scoped_ptr<DictionaryValue>())); | 293 event_name, extension_id, NULL, std::unique_ptr<DictionaryValue>())); |
| 293 | 294 |
| 294 if (is_new) { | 295 if (is_new) { |
| 295 std::set<std::string> events = GetRegisteredEvents(extension_id); | 296 std::set<std::string> events = GetRegisteredEvents(extension_id); |
| 296 bool prefs_is_new = events.insert(event_name).second; | 297 bool prefs_is_new = events.insert(event_name).second; |
| 297 if (prefs_is_new) | 298 if (prefs_is_new) |
| 298 SetRegisteredEvents(extension_id, events); | 299 SetRegisteredEvents(extension_id, events); |
| 299 } | 300 } |
| 300 } | 301 } |
| 301 | 302 |
| 302 void EventRouter::RemoveLazyEventListener(const std::string& event_name, | 303 void EventRouter::RemoveLazyEventListener(const std::string& event_name, |
| 303 const std::string& extension_id) { | 304 const std::string& extension_id) { |
| 304 scoped_ptr<EventListener> listener = EventListener::ForExtension( | 305 std::unique_ptr<EventListener> listener = EventListener::ForExtension( |
| 305 event_name, extension_id, NULL, scoped_ptr<DictionaryValue>()); | 306 event_name, extension_id, NULL, std::unique_ptr<DictionaryValue>()); |
| 306 bool did_exist = listeners_.RemoveListener(listener.get()); | 307 bool did_exist = listeners_.RemoveListener(listener.get()); |
| 307 | 308 |
| 308 if (did_exist) { | 309 if (did_exist) { |
| 309 std::set<std::string> events = GetRegisteredEvents(extension_id); | 310 std::set<std::string> events = GetRegisteredEvents(extension_id); |
| 310 bool prefs_did_exist = events.erase(event_name) > 0; | 311 bool prefs_did_exist = events.erase(event_name) > 0; |
| 311 DCHECK(prefs_did_exist); | 312 DCHECK(prefs_did_exist); |
| 312 SetRegisteredEvents(extension_id, events); | 313 SetRegisteredEvents(extension_id, events); |
| 313 } | 314 } |
| 314 } | 315 } |
| 315 | 316 |
| 316 void EventRouter::AddFilteredEventListener(const std::string& event_name, | 317 void EventRouter::AddFilteredEventListener(const std::string& event_name, |
| 317 content::RenderProcessHost* process, | 318 content::RenderProcessHost* process, |
| 318 const std::string& extension_id, | 319 const std::string& extension_id, |
| 319 const base::DictionaryValue& filter, | 320 const base::DictionaryValue& filter, |
| 320 bool add_lazy_listener) { | 321 bool add_lazy_listener) { |
| 321 listeners_.AddListener(EventListener::ForExtension( | 322 listeners_.AddListener(EventListener::ForExtension( |
| 322 event_name, | 323 event_name, extension_id, process, |
| 323 extension_id, | 324 std::unique_ptr<DictionaryValue>(filter.DeepCopy()))); |
| 324 process, | |
| 325 scoped_ptr<DictionaryValue>(filter.DeepCopy()))); | |
| 326 | 325 |
| 327 if (add_lazy_listener) { | 326 if (add_lazy_listener) { |
| 328 bool added = listeners_.AddListener(EventListener::ForExtension( | 327 bool added = listeners_.AddListener(EventListener::ForExtension( |
| 329 event_name, | 328 event_name, extension_id, NULL, |
| 330 extension_id, | 329 std::unique_ptr<DictionaryValue>(filter.DeepCopy()))); |
| 331 NULL, | |
| 332 scoped_ptr<DictionaryValue>(filter.DeepCopy()))); | |
| 333 | 330 |
| 334 if (added) | 331 if (added) |
| 335 AddFilterToEvent(event_name, extension_id, &filter); | 332 AddFilterToEvent(event_name, extension_id, &filter); |
| 336 } | 333 } |
| 337 } | 334 } |
| 338 | 335 |
| 339 void EventRouter::RemoveFilteredEventListener( | 336 void EventRouter::RemoveFilteredEventListener( |
| 340 const std::string& event_name, | 337 const std::string& event_name, |
| 341 content::RenderProcessHost* process, | 338 content::RenderProcessHost* process, |
| 342 const std::string& extension_id, | 339 const std::string& extension_id, |
| 343 const base::DictionaryValue& filter, | 340 const base::DictionaryValue& filter, |
| 344 bool remove_lazy_listener) { | 341 bool remove_lazy_listener) { |
| 345 scoped_ptr<EventListener> listener = EventListener::ForExtension( | 342 std::unique_ptr<EventListener> listener = EventListener::ForExtension( |
| 346 event_name, | 343 event_name, extension_id, process, |
| 347 extension_id, | 344 std::unique_ptr<DictionaryValue>(filter.DeepCopy())); |
| 348 process, | |
| 349 scoped_ptr<DictionaryValue>(filter.DeepCopy())); | |
| 350 | 345 |
| 351 listeners_.RemoveListener(listener.get()); | 346 listeners_.RemoveListener(listener.get()); |
| 352 | 347 |
| 353 if (remove_lazy_listener) { | 348 if (remove_lazy_listener) { |
| 354 listener->MakeLazy(); | 349 listener->MakeLazy(); |
| 355 bool removed = listeners_.RemoveListener(listener.get()); | 350 bool removed = listeners_.RemoveListener(listener.get()); |
| 356 | 351 |
| 357 if (removed) | 352 if (removed) |
| 358 RemoveFilterFromEvent(event_name, extension_id, &filter); | 353 RemoveFilterFromEvent(event_name, extension_id, &filter); |
| 359 } | 354 } |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 } | 453 } |
| 459 | 454 |
| 460 const DictionaryValue* EventRouter::GetFilteredEvents( | 455 const DictionaryValue* EventRouter::GetFilteredEvents( |
| 461 const std::string& extension_id) { | 456 const std::string& extension_id) { |
| 462 const DictionaryValue* events = NULL; | 457 const DictionaryValue* events = NULL; |
| 463 extension_prefs_->ReadPrefAsDictionary( | 458 extension_prefs_->ReadPrefAsDictionary( |
| 464 extension_id, kFilteredEvents, &events); | 459 extension_id, kFilteredEvents, &events); |
| 465 return events; | 460 return events; |
| 466 } | 461 } |
| 467 | 462 |
| 468 void EventRouter::BroadcastEvent(scoped_ptr<Event> event) { | 463 void EventRouter::BroadcastEvent(std::unique_ptr<Event> event) { |
| 469 DispatchEventImpl(std::string(), linked_ptr<Event>(event.release())); | 464 DispatchEventImpl(std::string(), linked_ptr<Event>(event.release())); |
| 470 } | 465 } |
| 471 | 466 |
| 472 void EventRouter::DispatchEventToExtension(const std::string& extension_id, | 467 void EventRouter::DispatchEventToExtension(const std::string& extension_id, |
| 473 scoped_ptr<Event> event) { | 468 std::unique_ptr<Event> event) { |
| 474 DCHECK(!extension_id.empty()); | 469 DCHECK(!extension_id.empty()); |
| 475 DispatchEventImpl(extension_id, linked_ptr<Event>(event.release())); | 470 DispatchEventImpl(extension_id, linked_ptr<Event>(event.release())); |
| 476 } | 471 } |
| 477 | 472 |
| 478 void EventRouter::DispatchEventWithLazyListener(const std::string& extension_id, | 473 void EventRouter::DispatchEventWithLazyListener(const std::string& extension_id, |
| 479 scoped_ptr<Event> event) { | 474 std::unique_ptr<Event> event) { |
| 480 DCHECK(!extension_id.empty()); | 475 DCHECK(!extension_id.empty()); |
| 481 std::string event_name = event->event_name; | 476 std::string event_name = event->event_name; |
| 482 bool has_listener = ExtensionHasEventListener(extension_id, event_name); | 477 bool has_listener = ExtensionHasEventListener(extension_id, event_name); |
| 483 if (!has_listener) | 478 if (!has_listener) |
| 484 AddLazyEventListener(event_name, extension_id); | 479 AddLazyEventListener(event_name, extension_id); |
| 485 DispatchEventToExtension(extension_id, std::move(event)); | 480 DispatchEventToExtension(extension_id, std::move(event)); |
| 486 if (!has_listener) | 481 if (!has_listener) |
| 487 RemoveLazyEventListener(event_name, extension_id); | 482 RemoveLazyEventListener(event_name, extension_id); |
| 488 } | 483 } |
| 489 | 484 |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 851 | 846 |
| 852 void EventRouter::OnExtensionUnloaded(content::BrowserContext* browser_context, | 847 void EventRouter::OnExtensionUnloaded(content::BrowserContext* browser_context, |
| 853 const Extension* extension, | 848 const Extension* extension, |
| 854 UnloadedExtensionInfo::Reason reason) { | 849 UnloadedExtensionInfo::Reason reason) { |
| 855 // Remove all registered listeners from our cache. | 850 // Remove all registered listeners from our cache. |
| 856 listeners_.RemoveListenersForExtension(extension->id()); | 851 listeners_.RemoveListenersForExtension(extension->id()); |
| 857 } | 852 } |
| 858 | 853 |
| 859 Event::Event(events::HistogramValue histogram_value, | 854 Event::Event(events::HistogramValue histogram_value, |
| 860 const std::string& event_name, | 855 const std::string& event_name, |
| 861 scoped_ptr<base::ListValue> event_args) | 856 std::unique_ptr<base::ListValue> event_args) |
| 862 : Event(histogram_value, event_name, std::move(event_args), nullptr) {} | 857 : Event(histogram_value, event_name, std::move(event_args), nullptr) {} |
| 863 | 858 |
| 864 Event::Event(events::HistogramValue histogram_value, | 859 Event::Event(events::HistogramValue histogram_value, |
| 865 const std::string& event_name, | 860 const std::string& event_name, |
| 866 scoped_ptr<base::ListValue> event_args, | 861 std::unique_ptr<base::ListValue> event_args, |
| 867 BrowserContext* restrict_to_browser_context) | 862 BrowserContext* restrict_to_browser_context) |
| 868 : Event(histogram_value, | 863 : Event(histogram_value, |
| 869 event_name, | 864 event_name, |
| 870 std::move(event_args), | 865 std::move(event_args), |
| 871 restrict_to_browser_context, | 866 restrict_to_browser_context, |
| 872 GURL(), | 867 GURL(), |
| 873 EventRouter::USER_GESTURE_UNKNOWN, | 868 EventRouter::USER_GESTURE_UNKNOWN, |
| 874 EventFilteringInfo()) {} | 869 EventFilteringInfo()) {} |
| 875 | 870 |
| 876 Event::Event(events::HistogramValue histogram_value, | 871 Event::Event(events::HistogramValue histogram_value, |
| 877 const std::string& event_name, | 872 const std::string& event_name, |
| 878 scoped_ptr<ListValue> event_args_tmp, | 873 std::unique_ptr<ListValue> event_args_tmp, |
| 879 BrowserContext* restrict_to_browser_context, | 874 BrowserContext* restrict_to_browser_context, |
| 880 const GURL& event_url, | 875 const GURL& event_url, |
| 881 EventRouter::UserGestureState user_gesture, | 876 EventRouter::UserGestureState user_gesture, |
| 882 const EventFilteringInfo& filter_info) | 877 const EventFilteringInfo& filter_info) |
| 883 : histogram_value(histogram_value), | 878 : histogram_value(histogram_value), |
| 884 event_name(event_name), | 879 event_name(event_name), |
| 885 event_args(std::move(event_args_tmp)), | 880 event_args(std::move(event_args_tmp)), |
| 886 restrict_to_browser_context(restrict_to_browser_context), | 881 restrict_to_browser_context(restrict_to_browser_context), |
| 887 event_url(event_url), | 882 event_url(event_url), |
| 888 user_gesture(user_gesture), | 883 user_gesture(user_gesture), |
| 889 filter_info(filter_info) { | 884 filter_info(filter_info) { |
| 890 DCHECK(event_args); | 885 DCHECK(event_args); |
| 891 DCHECK_NE(events::UNKNOWN, histogram_value) | 886 DCHECK_NE(events::UNKNOWN, histogram_value) |
| 892 << "events::UNKNOWN cannot be used as a histogram value.\n" | 887 << "events::UNKNOWN cannot be used as a histogram value.\n" |
| 893 << "If this is a test, use events::FOR_TEST.\n" | 888 << "If this is a test, use events::FOR_TEST.\n" |
| 894 << "If this is production code, it is important that you use a realistic " | 889 << "If this is production code, it is important that you use a realistic " |
| 895 << "value so that we can accurately track event usage. " | 890 << "value so that we can accurately track event usage. " |
| 896 << "See extension_event_histogram_value.h for inspiration."; | 891 << "See extension_event_histogram_value.h for inspiration."; |
| 897 } | 892 } |
| 898 | 893 |
| 899 Event::~Event() {} | 894 Event::~Event() {} |
| 900 | 895 |
| 901 Event* Event::DeepCopy() { | 896 Event* Event::DeepCopy() { |
| 902 Event* copy = new Event(histogram_value, event_name, | 897 Event* copy = new Event( |
| 903 scoped_ptr<base::ListValue>(event_args->DeepCopy()), | 898 histogram_value, event_name, |
| 904 restrict_to_browser_context, event_url, user_gesture, | 899 std::unique_ptr<base::ListValue>(event_args->DeepCopy()), |
| 905 filter_info); | 900 restrict_to_browser_context, event_url, user_gesture, filter_info); |
| 906 copy->will_dispatch_callback = will_dispatch_callback; | 901 copy->will_dispatch_callback = will_dispatch_callback; |
| 907 return copy; | 902 return copy; |
| 908 } | 903 } |
| 909 | 904 |
| 910 EventListenerInfo::EventListenerInfo(const std::string& event_name, | 905 EventListenerInfo::EventListenerInfo(const std::string& event_name, |
| 911 const std::string& extension_id, | 906 const std::string& extension_id, |
| 912 const GURL& listener_url, | 907 const GURL& listener_url, |
| 913 content::BrowserContext* browser_context) | 908 content::BrowserContext* browser_context) |
| 914 : event_name(event_name), | 909 : event_name(event_name), |
| 915 extension_id(extension_id), | 910 extension_id(extension_id), |
| 916 listener_url(listener_url), | 911 listener_url(listener_url), |
| 917 browser_context(browser_context) { | 912 browser_context(browser_context) { |
| 918 } | 913 } |
| 919 | 914 |
| 920 } // namespace extensions | 915 } // namespace extensions |
| OLD | NEW |