| 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 // Only increment in-flight events if the lazy background page is active, |
| 409 // because that's the only time we'll get an ACK. |
| 408 if (extension->has_lazy_background_page()) { | 410 if (extension->has_lazy_background_page()) { |
| 409 profile->GetExtensionProcessManager()->IncrementLazyKeepaliveCount( | 411 ExtensionProcessManager* pm = |
| 410 extension); | 412 ExtensionSystem::Get(profile)->process_manager(); |
| 413 ExtensionHost* host = pm->GetBackgroundHostForExtension(extension->id()); |
| 414 if (host) |
| 415 pm->IncrementLazyKeepaliveCount(extension); |
| 411 } | 416 } |
| 412 } | 417 } |
| 413 | 418 |
| 414 void ExtensionEventRouter::OnExtensionEventAck( | 419 void ExtensionEventRouter::OnEventAck( |
| 415 Profile* profile, const std::string& extension_id) { | 420 Profile* profile, const std::string& extension_id) { |
| 416 const Extension* extension = profile->GetExtensionService()->extensions()-> | 421 ExtensionProcessManager* pm = |
| 417 GetByID(extension_id); | 422 ExtensionSystem::Get(profile)->process_manager(); |
| 418 if (extension && extension->has_lazy_background_page()) { | 423 ExtensionHost* host = pm->GetBackgroundHostForExtension(extension_id); |
| 419 profile->GetExtensionProcessManager()->DecrementLazyKeepaliveCount( | 424 // The event ACK is routed to the background host, so this should never be |
| 420 extension); | 425 // NULL. |
| 421 } | 426 CHECK(host); |
| 427 CHECK(host->extension()->has_lazy_background_page()); |
| 428 pm->DecrementLazyKeepaliveCount(host->extension()); |
| 422 } | 429 } |
| 423 | 430 |
| 424 void ExtensionEventRouter::DispatchPendingEvent( | 431 void ExtensionEventRouter::DispatchPendingEvent( |
| 425 const linked_ptr<ExtensionEvent>& event, ExtensionHost* host) { | 432 const linked_ptr<ExtensionEvent>& event, ExtensionHost* host) { |
| 426 if (!host) | 433 if (!host) |
| 427 return; | 434 return; |
| 428 | 435 |
| 429 ListenerProcess listener(host->render_process_host(), | 436 ListenerProcess listener(host->render_process_host(), |
| 430 host->extension()->id()); | 437 host->extension()->id()); |
| 431 if (listeners_[event->event_name].count(listener) > 0u) | 438 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(); | 496 content::Details<const Extension>(details).ptr(); |
| 490 extensions::RuntimeEventRouter::DispatchOnInstalledEvent( | 497 extensions::RuntimeEventRouter::DispatchOnInstalledEvent( |
| 491 profile_, extension); | 498 profile_, extension); |
| 492 break; | 499 break; |
| 493 } | 500 } |
| 494 default: | 501 default: |
| 495 NOTREACHED(); | 502 NOTREACHED(); |
| 496 return; | 503 return; |
| 497 } | 504 } |
| 498 } | 505 } |
| OLD | NEW |