Chromium Code Reviews| 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/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/extensions/api/runtime/runtime_api.h" | 10 #include "chrome/browser/extensions/api/runtime/runtime_api.h" |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 398 if (queue->ShouldEnqueueTask(profile, extension)) { | 398 if (queue->ShouldEnqueueTask(profile, extension)) { |
| 399 queue->AddPendingTask( | 399 queue->AddPendingTask( |
| 400 profile, extension->id(), | 400 profile, extension->id(), |
| 401 base::Bind(&ExtensionEventRouter::DispatchPendingEvent, | 401 base::Bind(&ExtensionEventRouter::DispatchPendingEvent, |
| 402 base::Unretained(this), event)); | 402 base::Unretained(this), event)); |
| 403 } | 403 } |
| 404 } | 404 } |
| 405 | 405 |
| 406 void ExtensionEventRouter::IncrementInFlightEvents( | 406 void ExtensionEventRouter::IncrementInFlightEvents( |
| 407 Profile* profile, const Extension* extension) { | 407 Profile* profile, const Extension* extension) { |
| 408 if (extension->has_lazy_background_page()) { | 408 // Only increment in-flight events if the lazy background page is active, |
| 409 profile->GetExtensionProcessManager()->IncrementLazyKeepaliveCount( | 409 // because that's the only time we'll get an ACK. |
| 410 extension); | 410 ExtensionProcessManager* pm = |
| 411 } | 411 ExtensionSystem::Get(profile)->process_manager(); |
| 412 ExtensionHost* host = pm->GetBackgroundHostForExtension(extension->id()); | |
|
Yoyo Zhou
2012/04/19 21:47:13
You could put this inside has_lazy_background_page
Matt Perry
2012/04/19 22:21:53
Done.
| |
| 413 if (host && extension->has_lazy_background_page()) | |
| 414 pm->IncrementLazyKeepaliveCount(extension); | |
| 412 } | 415 } |
| 413 | 416 |
| 414 void ExtensionEventRouter::OnExtensionEventAck( | 417 void ExtensionEventRouter::OnEventAck( |
| 415 Profile* profile, const std::string& extension_id) { | 418 Profile* profile, const std::string& extension_id) { |
| 416 const Extension* extension = profile->GetExtensionService()->extensions()-> | 419 ExtensionProcessManager* pm = |
| 417 GetByID(extension_id); | 420 ExtensionSystem::Get(profile)->process_manager(); |
| 418 if (extension && extension->has_lazy_background_page()) { | 421 ExtensionHost* host = pm->GetBackgroundHostForExtension(extension_id); |
| 419 profile->GetExtensionProcessManager()->DecrementLazyKeepaliveCount( | 422 // The event ACK is routed to the background host, so this should never be |
| 420 extension); | 423 // NULL. |
| 421 } | 424 CHECK(host); |
| 425 CHECK(host->extension()->has_lazy_background_page()); | |
| 426 pm->DecrementLazyKeepaliveCount(host->extension()); | |
| 422 } | 427 } |
| 423 | 428 |
| 424 void ExtensionEventRouter::DispatchPendingEvent( | 429 void ExtensionEventRouter::DispatchPendingEvent( |
| 425 const linked_ptr<ExtensionEvent>& event, ExtensionHost* host) { | 430 const linked_ptr<ExtensionEvent>& event, ExtensionHost* host) { |
| 426 if (!host) | 431 if (!host) |
| 427 return; | 432 return; |
| 428 | 433 |
| 429 ListenerProcess listener(host->render_process_host(), | 434 ListenerProcess listener(host->render_process_host(), |
| 430 host->extension()->id()); | 435 host->extension()->id()); |
| 431 if (listeners_[event->event_name].count(listener) > 0u) | 436 if (listeners_[event->event_name].count(listener) > 0u) |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 489 content::Details<const Extension>(details).ptr(); | 494 content::Details<const Extension>(details).ptr(); |
| 490 extensions::RuntimeEventRouter::DispatchOnInstalledEvent( | 495 extensions::RuntimeEventRouter::DispatchOnInstalledEvent( |
| 491 profile_, extension); | 496 profile_, extension); |
| 492 break; | 497 break; |
| 493 } | 498 } |
| 494 default: | 499 default: |
| 495 NOTREACHED(); | 500 NOTREACHED(); |
| 496 return; | 501 return; |
| 497 } | 502 } |
| 498 } | 503 } |
| OLD | NEW |