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.h" | 10 #include "base/message_loop.h" |
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 registry->RegisterFunction<extensions::GetProcessInfoFunction>(); | 496 registry->RegisterFunction<extensions::GetProcessInfoFunction>(); |
497 } | 497 } |
498 | 498 |
499 ProcessesAPI::~ProcessesAPI() { | 499 ProcessesAPI::~ProcessesAPI() { |
500 } | 500 } |
501 | 501 |
502 void ProcessesAPI::Shutdown() { | 502 void ProcessesAPI::Shutdown() { |
503 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); | 503 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); |
504 } | 504 } |
505 | 505 |
| 506 static base::LazyInstance<ProfileKeyedAPIFactory<ProcessesAPI> > |
| 507 g_factory = LAZY_INSTANCE_INITIALIZER; |
| 508 |
| 509 // static |
| 510 ProfileKeyedAPIFactory<ProcessesAPI>* ProcessesAPI::GetFactoryInstance() { |
| 511 return &g_factory.Get(); |
| 512 } |
| 513 |
506 // static | 514 // static |
507 ProcessesAPI* ProcessesAPI::Get(Profile* profile) { | 515 ProcessesAPI* ProcessesAPI::Get(Profile* profile) { |
508 return ProfileKeyedAPIFactory<ProcessesAPI>::GetForProfile(profile); | 516 return ProfileKeyedAPIFactory<ProcessesAPI>::GetForProfile(profile); |
509 } | 517 } |
510 | 518 |
511 ProcessesEventRouter* ProcessesAPI::processes_event_router() { | 519 ProcessesEventRouter* ProcessesAPI::processes_event_router() { |
512 if (!processes_event_router_) | 520 if (!processes_event_router_) |
513 processes_event_router_.reset(new ProcessesEventRouter(profile_)); | 521 processes_event_router_.reset(new ProcessesEventRouter(profile_)); |
514 return processes_event_router_.get(); | 522 return processes_event_router_.get(); |
515 } | 523 } |
516 | 524 |
517 void ProcessesAPI::OnListenerAdded(const EventListenerInfo& details) { | 525 void ProcessesAPI::OnListenerAdded(const EventListenerInfo& details) { |
518 // We lazily tell the TaskManager to start updating when listeners to the | 526 // We lazily tell the TaskManager to start updating when listeners to the |
519 // processes.onUpdated or processes.onUpdatedWithMemory events arrive. | 527 // processes.onUpdated or processes.onUpdatedWithMemory events arrive. |
520 processes_event_router()->ListenerAdded(); | 528 processes_event_router()->ListenerAdded(); |
521 } | 529 } |
522 | 530 |
523 void ProcessesAPI::OnListenerRemoved(const EventListenerInfo& details) { | 531 void ProcessesAPI::OnListenerRemoved(const EventListenerInfo& details) { |
524 // If a processes.onUpdated or processes.onUpdatedWithMemory event listener | 532 // If a processes.onUpdated or processes.onUpdatedWithMemory event listener |
525 // is removed (or a process with one exits), then we let the extension API | 533 // is removed (or a process with one exits), then we let the extension API |
526 // know that it has one fewer listener. | 534 // know that it has one fewer listener. |
527 processes_event_router()->ListenerRemoved(); | 535 processes_event_router()->ListenerRemoved(); |
528 } | 536 } |
529 | 537 |
530 static base::LazyInstance<ProfileKeyedAPIFactory<ProcessesAPI> > | |
531 g_factory = LAZY_INSTANCE_INITIALIZER; | |
532 | |
533 template <> | |
534 ProfileKeyedAPIFactory<ProcessesAPI>* | |
535 ProfileKeyedAPIFactory<ProcessesAPI>::GetInstance() { | |
536 return &g_factory.Get(); | |
537 } | |
538 | |
539 GetProcessIdForTabFunction::GetProcessIdForTabFunction() : tab_id_(-1) { | 538 GetProcessIdForTabFunction::GetProcessIdForTabFunction() : tab_id_(-1) { |
540 } | 539 } |
541 | 540 |
542 bool GetProcessIdForTabFunction::RunImpl() { | 541 bool GetProcessIdForTabFunction::RunImpl() { |
543 #if defined(ENABLE_TASK_MANAGER) | 542 #if defined(ENABLE_TASK_MANAGER) |
544 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id_)); | 543 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id_)); |
545 | 544 |
546 // Add a reference, which is balanced in GetProcessIdForTab to keep the object | 545 // Add a reference, which is balanced in GetProcessIdForTab to keep the object |
547 // around and allow for the callback to be invoked. | 546 // around and allow for the callback to be invoked. |
548 AddRef(); | 547 AddRef(); |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
772 | 771 |
773 SetResult(processes); | 772 SetResult(processes); |
774 SendResponse(true); | 773 SendResponse(true); |
775 | 774 |
776 // Balance the AddRef in the RunImpl. | 775 // Balance the AddRef in the RunImpl. |
777 Release(); | 776 Release(); |
778 #endif // defined(ENABLE_TASK_MANAGER) | 777 #endif // defined(ENABLE_TASK_MANAGER) |
779 } | 778 } |
780 | 779 |
781 } // namespace extensions | 780 } // namespace extensions |
OLD | NEW |