OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/extensions/extension_devtools_manager.h" | 10 #include "chrome/browser/extensions/extension_devtools_manager.h" |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
281 // incognito tab event sent to a normal process, or vice versa). | 281 // incognito tab event sent to a normal process, or vice versa). |
282 bool cross_incognito = event->restrict_to_profile && | 282 bool cross_incognito = event->restrict_to_profile && |
283 listener_profile != event->restrict_to_profile; | 283 listener_profile != event->restrict_to_profile; |
284 // Send the event with different arguments to extensions that can't | 284 // Send the event with different arguments to extensions that can't |
285 // cross incognito, if necessary. | 285 // cross incognito, if necessary. |
286 if (cross_incognito && !service->CanCrossIncognito(extension)) { | 286 if (cross_incognito && !service->CanCrossIncognito(extension)) { |
287 if (!event->cross_incognito_args.empty()) { | 287 if (!event->cross_incognito_args.empty()) { |
288 DispatchEvent(listener->process, listener->extension_id, | 288 DispatchEvent(listener->process, listener->extension_id, |
289 event->event_name, event->cross_incognito_args, | 289 event->event_name, event->cross_incognito_args, |
290 event->event_url); | 290 event->event_url); |
291 IncrementInFlightEvents(listener->extension_id); | |
Aaron Boodman
2011/10/31 17:46:08
Out of curiosity, why does it not work to put this
Tessa MacDuff
2011/10/31 19:01:29
Because DispatchEvent is static and can't access i
| |
291 } | 292 } |
292 continue; | 293 continue; |
293 } | 294 } |
294 | 295 |
295 DispatchEvent(listener->process, listener->extension_id, | 296 DispatchEvent(listener->process, listener->extension_id, |
296 event->event_name, event->event_args, event->event_url); | 297 event->event_name, event->event_args, event->event_url); |
298 IncrementInFlightEvents(listener->extension_id); | |
297 } | 299 } |
298 } | 300 } |
299 | 301 |
302 void ExtensionEventRouter::IncrementInFlightEvents( | |
303 const std::string& extension_id) { | |
304 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
305 switches::kEnableLazyBackgroundPages)) | |
306 in_flight_events_[extension_id]++; | |
307 } | |
308 | |
309 void ExtensionEventRouter::DecrementInFlightEvents( | |
310 const std::string& extension_id) { | |
311 CHECK(CommandLine::ForCurrentProcess()->HasSwitch( | |
312 switches::kEnableLazyBackgroundPages)); | |
313 CHECK(in_flight_events_[extension_id] > 0); | |
314 in_flight_events_[extension_id]--; | |
315 } | |
316 | |
317 bool ExtensionEventRouter::HasInFlightEvents(const std::string& extension_id) { | |
318 return in_flight_events_[extension_id] > 0; | |
319 } | |
320 | |
300 void ExtensionEventRouter::AppendEvent( | 321 void ExtensionEventRouter::AppendEvent( |
301 const linked_ptr<ExtensionEvent>& event) { | 322 const linked_ptr<ExtensionEvent>& event) { |
302 PendingEventsList* events_list = NULL; | 323 PendingEventsList* events_list = NULL; |
303 PendingEventsPerExtMap::iterator it = | 324 PendingEventsPerExtMap::iterator it = |
304 pending_events_.find(event->extension_id); | 325 pending_events_.find(event->extension_id); |
305 if (it == pending_events_.end()) { | 326 if (it == pending_events_.end()) { |
306 events_list = new PendingEventsList(); | 327 events_list = new PendingEventsList(); |
307 pending_events_[event->extension_id] = | 328 pending_events_[event->extension_id] = |
308 linked_ptr<PendingEventsList>(events_list); | 329 linked_ptr<PendingEventsList>(events_list); |
309 } else { | 330 } else { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
361 ExtensionHost* eh = content::Details<ExtensionHost>(details).ptr(); | 382 ExtensionHost* eh = content::Details<ExtensionHost>(details).ptr(); |
362 DispatchPendingEvents(eh->extension_id()); | 383 DispatchPendingEvents(eh->extension_id()); |
363 break; | 384 break; |
364 } | 385 } |
365 // TODO(tessamac): if background page crashed/failed clear queue. | 386 // TODO(tessamac): if background page crashed/failed clear queue. |
366 default: | 387 default: |
367 NOTREACHED(); | 388 NOTREACHED(); |
368 return; | 389 return; |
369 } | 390 } |
370 } | 391 } |
OLD | NEW |