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/api/processes/processes_api.h" | 5 #include "chrome/browser/extensions/api/processes/processes_api.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "content/public/browser/notification_types.h" | 27 #include "content/public/browser/notification_types.h" |
28 #include "content/public/browser/render_process_host.h" | 28 #include "content/public/browser/render_process_host.h" |
29 #include "content/public/browser/render_view_host.h" | 29 #include "content/public/browser/render_view_host.h" |
30 #include "content/public/browser/render_widget_host.h" | 30 #include "content/public/browser/render_widget_host.h" |
31 #include "content/public/browser/render_widget_host_iterator.h" | 31 #include "content/public/browser/render_widget_host_iterator.h" |
32 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" |
33 #include "content/public/common/result_codes.h" | 33 #include "content/public/common/result_codes.h" |
34 #include "extensions/browser/event_router.h" | 34 #include "extensions/browser/event_router.h" |
35 #include "extensions/browser/extension_function_registry.h" | 35 #include "extensions/browser/extension_function_registry.h" |
36 #include "extensions/browser/extension_function_util.h" | 36 #include "extensions/browser/extension_function_util.h" |
37 #include "extensions/browser/extension_system.h" | |
38 #include "extensions/common/error_utils.h" | 37 #include "extensions/common/error_utils.h" |
39 | 38 |
40 namespace extensions { | 39 namespace extensions { |
41 | 40 |
42 namespace keys = processes_api_constants; | 41 namespace keys = processes_api_constants; |
43 namespace errors = processes_api_constants; | 42 namespace errors = processes_api_constants; |
44 | 43 |
45 namespace { | 44 namespace { |
46 | 45 |
47 #if defined(ENABLE_TASK_MANAGER) | 46 #if defined(ENABLE_TASK_MANAGER) |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 // Third arg: The exit code for the process. | 462 // Third arg: The exit code for the process. |
464 args->Append(new base::FundamentalValue(details->exit_code)); | 463 args->Append(new base::FundamentalValue(details->exit_code)); |
465 | 464 |
466 DispatchEvent(keys::kOnExited, args.Pass()); | 465 DispatchEvent(keys::kOnExited, args.Pass()); |
467 #endif // defined(ENABLE_TASK_MANAGER) | 466 #endif // defined(ENABLE_TASK_MANAGER) |
468 } | 467 } |
469 | 468 |
470 void ProcessesEventRouter::DispatchEvent( | 469 void ProcessesEventRouter::DispatchEvent( |
471 const std::string& event_name, | 470 const std::string& event_name, |
472 scoped_ptr<base::ListValue> event_args) { | 471 scoped_ptr<base::ListValue> event_args) { |
473 if (extensions::ExtensionSystem::Get(browser_context_)->event_router()) { | 472 EventRouter* event_router = EventRouter::Get(browser_context_); |
| 473 if (event_router) { |
474 scoped_ptr<extensions::Event> event(new extensions::Event( | 474 scoped_ptr<extensions::Event> event(new extensions::Event( |
475 event_name, event_args.Pass())); | 475 event_name, event_args.Pass())); |
476 extensions::ExtensionSystem::Get(browser_context_) | 476 event_router->BroadcastEvent(event.Pass()); |
477 ->event_router() | |
478 ->BroadcastEvent(event.Pass()); | |
479 } | 477 } |
480 } | 478 } |
481 | 479 |
482 bool ProcessesEventRouter::HasEventListeners(const std::string& event_name) { | 480 bool ProcessesEventRouter::HasEventListeners(const std::string& event_name) { |
483 extensions::EventRouter* router = | 481 EventRouter* event_router = EventRouter::Get(browser_context_); |
484 extensions::ExtensionSystem::Get(browser_context_)->event_router(); | 482 return event_router && event_router->HasEventListener(event_name); |
485 if (router && router->HasEventListener(event_name)) | |
486 return true; | |
487 return false; | |
488 } | 483 } |
489 | 484 |
490 ProcessesAPI::ProcessesAPI(content::BrowserContext* context) | 485 ProcessesAPI::ProcessesAPI(content::BrowserContext* context) |
491 : browser_context_(context) { | 486 : browser_context_(context) { |
492 ExtensionSystem::Get(browser_context_)->event_router()->RegisterObserver( | 487 EventRouter* event_router = EventRouter::Get(browser_context_); |
493 this, processes_api_constants::kOnUpdated); | 488 event_router->RegisterObserver(this, processes_api_constants::kOnUpdated); |
494 ExtensionSystem::Get(browser_context_)->event_router()->RegisterObserver( | 489 event_router->RegisterObserver(this, |
495 this, processes_api_constants::kOnUpdatedWithMemory); | 490 processes_api_constants::kOnUpdatedWithMemory); |
496 ExtensionFunctionRegistry* registry = | 491 ExtensionFunctionRegistry* registry = |
497 ExtensionFunctionRegistry::GetInstance(); | 492 ExtensionFunctionRegistry::GetInstance(); |
498 registry->RegisterFunction<extensions::GetProcessIdForTabFunction>(); | 493 registry->RegisterFunction<extensions::GetProcessIdForTabFunction>(); |
499 registry->RegisterFunction<extensions::TerminateFunction>(); | 494 registry->RegisterFunction<extensions::TerminateFunction>(); |
500 registry->RegisterFunction<extensions::GetProcessInfoFunction>(); | 495 registry->RegisterFunction<extensions::GetProcessInfoFunction>(); |
501 } | 496 } |
502 | 497 |
503 ProcessesAPI::~ProcessesAPI() { | 498 ProcessesAPI::~ProcessesAPI() { |
504 } | 499 } |
505 | 500 |
506 void ProcessesAPI::Shutdown() { | 501 void ProcessesAPI::Shutdown() { |
507 ExtensionSystem::Get(browser_context_)->event_router()->UnregisterObserver( | 502 EventRouter::Get(browser_context_)->UnregisterObserver(this); |
508 this); | |
509 } | 503 } |
510 | 504 |
511 static base::LazyInstance<BrowserContextKeyedAPIFactory<ProcessesAPI> > | 505 static base::LazyInstance<BrowserContextKeyedAPIFactory<ProcessesAPI> > |
512 g_factory = LAZY_INSTANCE_INITIALIZER; | 506 g_factory = LAZY_INSTANCE_INITIALIZER; |
513 | 507 |
514 // static | 508 // static |
515 BrowserContextKeyedAPIFactory<ProcessesAPI>* | 509 BrowserContextKeyedAPIFactory<ProcessesAPI>* |
516 ProcessesAPI::GetFactoryInstance() { | 510 ProcessesAPI::GetFactoryInstance() { |
517 return g_factory.Pointer(); | 511 return g_factory.Pointer(); |
518 } | 512 } |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
768 | 762 |
769 SetResult(processes); | 763 SetResult(processes); |
770 SendResponse(true); | 764 SendResponse(true); |
771 | 765 |
772 // Balance the AddRef in the RunImpl. | 766 // Balance the AddRef in the RunImpl. |
773 Release(); | 767 Release(); |
774 #endif // defined(ENABLE_TASK_MANAGER) | 768 #endif // defined(ENABLE_TASK_MANAGER) |
775 } | 769 } |
776 | 770 |
777 } // namespace extensions | 771 } // namespace extensions |
OLD | NEW |