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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 UserGestureState user_gesture, | 96 UserGestureState user_gesture, |
97 const extensions::EventFilteringInfo& info) { | 97 const extensions::EventFilteringInfo& info) { |
98 scoped_ptr<Value> event_args_value(Value::CreateStringValue(event_args)); | 98 scoped_ptr<Value> event_args_value(Value::CreateStringValue(event_args)); |
99 DispatchEvent(ipc_sender, extension_id, event_name, *event_args_value.get(), | 99 DispatchEvent(ipc_sender, extension_id, event_name, *event_args_value.get(), |
100 event_url, user_gesture, info); | 100 event_url, user_gesture, info); |
101 } | 101 } |
102 | 102 |
103 ExtensionEventRouter::ExtensionEventRouter(Profile* profile) | 103 ExtensionEventRouter::ExtensionEventRouter(Profile* profile) |
104 : profile_(profile), | 104 : profile_(profile), |
105 extension_devtools_manager_( | 105 extension_devtools_manager_( |
106 ExtensionSystem::Get(profile)->devtools_manager()), | 106 extensions::ExtensionSystem::Get(profile)->devtools_manager()), |
107 listeners_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 107 listeners_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
108 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, | 108 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
109 content::NotificationService::AllSources()); | 109 content::NotificationService::AllSources()); |
110 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 110 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
111 content::NotificationService::AllSources()); | 111 content::NotificationService::AllSources()); |
112 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 112 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
113 content::Source<Profile>(profile_)); | 113 content::Source<Profile>(profile_)); |
114 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 114 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
115 content::Source<Profile>(profile_)); | 115 content::Source<Profile>(profile_)); |
116 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED, | 116 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED, |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 | 465 |
466 void ExtensionEventRouter::MaybeLoadLazyBackgroundPageToDispatchEvent( | 466 void ExtensionEventRouter::MaybeLoadLazyBackgroundPageToDispatchEvent( |
467 Profile* profile, | 467 Profile* profile, |
468 const Extension* extension, | 468 const Extension* extension, |
469 const linked_ptr<ExtensionEvent>& event) { | 469 const linked_ptr<ExtensionEvent>& event) { |
470 const Value* event_args = NULL; | 470 const Value* event_args = NULL; |
471 if (!CanDispatchEventToProfile(profile, extension, event, &event_args)) | 471 if (!CanDispatchEventToProfile(profile, extension, event, &event_args)) |
472 return; | 472 return; |
473 | 473 |
474 extensions::LazyBackgroundTaskQueue* queue = | 474 extensions::LazyBackgroundTaskQueue* queue = |
475 ExtensionSystem::Get(profile)->lazy_background_task_queue(); | 475 extensions::ExtensionSystem::Get(profile)->lazy_background_task_queue(); |
476 if (queue->ShouldEnqueueTask(profile, extension)) { | 476 if (queue->ShouldEnqueueTask(profile, extension)) { |
477 queue->AddPendingTask( | 477 queue->AddPendingTask( |
478 profile, extension->id(), | 478 profile, extension->id(), |
479 base::Bind(&ExtensionEventRouter::DispatchPendingEvent, | 479 base::Bind(&ExtensionEventRouter::DispatchPendingEvent, |
480 base::Unretained(this), event)); | 480 base::Unretained(this), event)); |
481 } | 481 } |
482 } | 482 } |
483 | 483 |
484 void ExtensionEventRouter::IncrementInFlightEvents( | 484 void ExtensionEventRouter::IncrementInFlightEvents( |
485 Profile* profile, const Extension* extension) { | 485 Profile* profile, const Extension* extension) { |
486 // Only increment in-flight events if the lazy background page is active, | 486 // Only increment in-flight events if the lazy background page is active, |
487 // because that's the only time we'll get an ACK. | 487 // because that's the only time we'll get an ACK. |
488 if (extension->has_lazy_background_page()) { | 488 if (extension->has_lazy_background_page()) { |
489 ExtensionProcessManager* pm = | 489 ExtensionProcessManager* pm = |
490 ExtensionSystem::Get(profile)->process_manager(); | 490 extensions::ExtensionSystem::Get(profile)->process_manager(); |
491 ExtensionHost* host = pm->GetBackgroundHostForExtension(extension->id()); | 491 ExtensionHost* host = pm->GetBackgroundHostForExtension(extension->id()); |
492 if (host) | 492 if (host) |
493 pm->IncrementLazyKeepaliveCount(extension); | 493 pm->IncrementLazyKeepaliveCount(extension); |
494 } | 494 } |
495 } | 495 } |
496 | 496 |
497 void ExtensionEventRouter::OnEventAck( | 497 void ExtensionEventRouter::OnEventAck( |
498 Profile* profile, const std::string& extension_id) { | 498 Profile* profile, const std::string& extension_id) { |
499 ExtensionProcessManager* pm = | 499 ExtensionProcessManager* pm = |
500 ExtensionSystem::Get(profile)->process_manager(); | 500 extensions::ExtensionSystem::Get(profile)->process_manager(); |
501 ExtensionHost* host = pm->GetBackgroundHostForExtension(extension_id); | 501 ExtensionHost* host = pm->GetBackgroundHostForExtension(extension_id); |
502 // The event ACK is routed to the background host, so this should never be | 502 // The event ACK is routed to the background host, so this should never be |
503 // NULL. | 503 // NULL. |
504 CHECK(host); | 504 CHECK(host); |
505 // TODO(mpcomplete): We should never get this message unless | 505 // TODO(mpcomplete): We should never get this message unless |
506 // has_lazy_background_page is true. Find out why we're getting it anyway. | 506 // has_lazy_background_page is true. Find out why we're getting it anyway. |
507 if (host->extension() && host->extension()->has_lazy_background_page()) | 507 if (host->extension() && host->extension()->has_lazy_background_page()) |
508 pm->DecrementLazyKeepaliveCount(host->extension()); | 508 pm->DecrementLazyKeepaliveCount(host->extension()); |
509 } | 509 } |
510 | 510 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 event_args(event_args.DeepCopy()), | 616 event_args(event_args.DeepCopy()), |
617 event_url(event_url), | 617 event_url(event_url), |
618 restrict_to_profile(restrict_to_profile), | 618 restrict_to_profile(restrict_to_profile), |
619 cross_incognito_args(NULL), | 619 cross_incognito_args(NULL), |
620 user_gesture(user_gesture), | 620 user_gesture(user_gesture), |
621 info(info) { | 621 info(info) { |
622 } | 622 } |
623 | 623 |
624 ExtensionEvent::~ExtensionEvent() { | 624 ExtensionEvent::~ExtensionEvent() { |
625 } | 625 } |
OLD | NEW |