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 "chrome/browser/extensions/extension_event_router.h" | 5 #include "chrome/browser/extensions/extension_event_router.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
212 prefs->SetRegisteredEvents(extension_id, events); | 212 prefs->SetRegisteredEvents(extension_id, events); |
213 } | 213 } |
214 } | 214 } |
215 | 215 |
216 void ExtensionEventRouter::AddFilteredEventListener( | 216 void ExtensionEventRouter::AddFilteredEventListener( |
217 const std::string& event_name, | 217 const std::string& event_name, |
218 content::RenderProcessHost* process, | 218 content::RenderProcessHost* process, |
219 const std::string& extension_id, | 219 const std::string& extension_id, |
220 const base::DictionaryValue& filter, | 220 const base::DictionaryValue& filter, |
221 bool add_lazy_listener) { | 221 bool add_lazy_listener) { |
222 listeners_.AddListener(scoped_ptr<EventListener>(new EventListener( | |
223 event_name, extension_id, process, | |
224 scoped_ptr<DictionaryValue>(filter.DeepCopy())))); | |
225 | |
226 if (add_lazy_listener) { | 222 if (add_lazy_listener) { |
227 bool added = listeners_.AddListener(scoped_ptr<EventListener>( | 223 bool added = listeners_.AddListener(scoped_ptr<EventListener>( |
228 new EventListener(event_name, extension_id, NULL, | 224 new EventListener(event_name, extension_id, NULL, |
229 scoped_ptr<DictionaryValue>(filter.DeepCopy())))); | 225 scoped_ptr<DictionaryValue>(filter.DeepCopy())))); |
230 | 226 |
231 if (added) { | 227 if (added) { |
232 extensions::ExtensionPrefs* prefs = | 228 extensions::ExtensionPrefs* prefs = |
233 profile_->GetExtensionService()->extension_prefs(); | 229 profile_->GetExtensionService()->extension_prefs(); |
234 prefs->AddFilterToEvent(event_name, extension_id, &filter); | 230 prefs->AddFilterToEvent(event_name, extension_id, &filter); |
235 } | 231 } |
232 } else { | |
Matt Perry
2012/07/24 19:25:15
Did you mean to make this change? It seems unrelat
| |
233 listeners_.AddListener(scoped_ptr<EventListener>(new EventListener( | |
234 event_name, extension_id, process, | |
235 scoped_ptr<DictionaryValue>(filter.DeepCopy())))); | |
236 } | 236 } |
237 } | 237 } |
238 | 238 |
239 void ExtensionEventRouter::RemoveFilteredEventListener( | 239 void ExtensionEventRouter::RemoveFilteredEventListener( |
240 const std::string& event_name, | 240 const std::string& event_name, |
241 content::RenderProcessHost* process, | 241 content::RenderProcessHost* process, |
242 const std::string& extension_id, | 242 const std::string& extension_id, |
243 const base::DictionaryValue& filter, | 243 const base::DictionaryValue& filter, |
244 bool remove_lazy_listener) { | 244 bool remove_lazy_listener) { |
245 EventListener listener(event_name, extension_id, process, | 245 EventListener listener(event_name, extension_id, process, |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
469 void ExtensionEventRouter::MaybeLoadLazyBackgroundPageToDispatchEvent( | 469 void ExtensionEventRouter::MaybeLoadLazyBackgroundPageToDispatchEvent( |
470 Profile* profile, | 470 Profile* profile, |
471 const Extension* extension, | 471 const Extension* extension, |
472 const linked_ptr<ExtensionEvent>& event) { | 472 const linked_ptr<ExtensionEvent>& event) { |
473 const Value* event_args = NULL; | 473 const Value* event_args = NULL; |
474 if (!CanDispatchEventToProfile(profile, extension, event, &event_args)) | 474 if (!CanDispatchEventToProfile(profile, extension, event, &event_args)) |
475 return; | 475 return; |
476 | 476 |
477 extensions::LazyBackgroundTaskQueue* queue = | 477 extensions::LazyBackgroundTaskQueue* queue = |
478 extensions::ExtensionSystem::Get(profile)->lazy_background_task_queue(); | 478 extensions::ExtensionSystem::Get(profile)->lazy_background_task_queue(); |
479 if (queue->ShouldEnqueueTask(profile, extension)) { | 479 queue->AddPendingTask( |
Matt Perry
2012/07/24 19:25:15
Doesn't removing this result in a double dispatch
koz (OOO until 15th September)
2012/07/25 07:48:31
The idea here was to make it so lazy background pa
| |
480 queue->AddPendingTask( | 480 profile, extension->id(), |
481 profile, extension->id(), | 481 base::Bind(&ExtensionEventRouter::DispatchPendingEvent, |
482 base::Bind(&ExtensionEventRouter::DispatchPendingEvent, | 482 base::Unretained(this), event)); |
483 base::Unretained(this), event)); | |
484 } | |
485 } | 483 } |
486 | 484 |
487 void ExtensionEventRouter::IncrementInFlightEvents( | 485 void ExtensionEventRouter::IncrementInFlightEvents( |
488 Profile* profile, const Extension* extension) { | 486 Profile* profile, const Extension* extension) { |
489 // Only increment in-flight events if the lazy background page is active, | 487 // Only increment in-flight events if the lazy background page is active, |
490 // because that's the only time we'll get an ACK. | 488 // because that's the only time we'll get an ACK. |
491 if (extension->has_lazy_background_page()) { | 489 if (extension->has_lazy_background_page()) { |
492 ExtensionProcessManager* pm = | 490 ExtensionProcessManager* pm = |
493 extensions::ExtensionSystem::Get(profile)->process_manager(); | 491 extensions::ExtensionSystem::Get(profile)->process_manager(); |
494 ExtensionHost* host = pm->GetBackgroundHostForExtension(extension->id()); | 492 ExtensionHost* host = pm->GetBackgroundHostForExtension(extension->id()); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
619 event_args(event_args.DeepCopy()), | 617 event_args(event_args.DeepCopy()), |
620 event_url(event_url), | 618 event_url(event_url), |
621 restrict_to_profile(restrict_to_profile), | 619 restrict_to_profile(restrict_to_profile), |
622 cross_incognito_args(NULL), | 620 cross_incognito_args(NULL), |
623 user_gesture(user_gesture), | 621 user_gesture(user_gesture), |
624 info(info) { | 622 info(info) { |
625 } | 623 } |
626 | 624 |
627 ExtensionEvent::~ExtensionEvent() { | 625 ExtensionEvent::~ExtensionEvent() { |
628 } | 626 } |
OLD | NEW |