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 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 void ProcessesAPI::OnListenerRemoved(const EventListenerInfo& details) { | 531 void ProcessesAPI::OnListenerRemoved(const EventListenerInfo& details) { |
532 // If a processes.onUpdated or processes.onUpdatedWithMemory event listener | 532 // If a processes.onUpdated or processes.onUpdatedWithMemory event listener |
533 // 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 |
534 // know that it has one fewer listener. | 534 // know that it has one fewer listener. |
535 processes_event_router()->ListenerRemoved(); | 535 processes_event_router()->ListenerRemoved(); |
536 } | 536 } |
537 | 537 |
538 GetProcessIdForTabFunction::GetProcessIdForTabFunction() : tab_id_(-1) { | 538 GetProcessIdForTabFunction::GetProcessIdForTabFunction() : tab_id_(-1) { |
539 } | 539 } |
540 | 540 |
541 bool GetProcessIdForTabFunction::RunImpl() { | 541 bool GetProcessIdForTabFunction::RunAsync() { |
542 #if defined(ENABLE_TASK_MANAGER) | 542 #if defined(ENABLE_TASK_MANAGER) |
543 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id_)); | 543 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id_)); |
544 | 544 |
545 // 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 |
546 // around and allow for the callback to be invoked. | 546 // around and allow for the callback to be invoked. |
547 AddRef(); | 547 AddRef(); |
548 | 548 |
549 // If the task manager is already listening, just post a task to execute | 549 // If the task manager is already listening, just post a task to execute |
550 // which will invoke the callback once we have returned from this function. | 550 // which will invoke the callback once we have returned from this function. |
551 // Otherwise, wait for the notification that the task manager is done with | 551 // Otherwise, wait for the notification that the task manager is done with |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 extensions::tabs_constants::kTabNotFoundError, | 585 extensions::tabs_constants::kTabNotFoundError, |
586 base::IntToString(tab_id_)); | 586 base::IntToString(tab_id_)); |
587 SetResult(new base::FundamentalValue(-1)); | 587 SetResult(new base::FundamentalValue(-1)); |
588 SendResponse(false); | 588 SendResponse(false); |
589 } else { | 589 } else { |
590 int process_id = contents->GetRenderProcessHost()->GetID(); | 590 int process_id = contents->GetRenderProcessHost()->GetID(); |
591 SetResult(new base::FundamentalValue(process_id)); | 591 SetResult(new base::FundamentalValue(process_id)); |
592 SendResponse(true); | 592 SendResponse(true); |
593 } | 593 } |
594 | 594 |
595 // Balance the AddRef in the RunImpl. | 595 // Balance the AddRef in the RunAsync. |
596 Release(); | 596 Release(); |
597 } | 597 } |
598 | 598 |
599 TerminateFunction::TerminateFunction() : process_id_(-1) { | 599 TerminateFunction::TerminateFunction() : process_id_(-1) { |
600 } | 600 } |
601 | 601 |
602 bool TerminateFunction::RunImpl() { | 602 bool TerminateFunction::RunAsync() { |
603 #if defined(ENABLE_TASK_MANAGER) | 603 #if defined(ENABLE_TASK_MANAGER) |
604 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &process_id_)); | 604 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &process_id_)); |
605 | 605 |
606 // Add a reference, which is balanced in TerminateProcess to keep the object | 606 // Add a reference, which is balanced in TerminateProcess to keep the object |
607 // around and allow for the callback to be invoked. | 607 // around and allow for the callback to be invoked. |
608 AddRef(); | 608 AddRef(); |
609 | 609 |
610 // If the task manager is already listening, just post a task to execute | 610 // If the task manager is already listening, just post a task to execute |
611 // which will invoke the callback once we have returned from this function. | 611 // which will invoke the callback once we have returned from this function. |
612 // Otherwise, wait for the notification that the task manager is done with | 612 // Otherwise, wait for the notification that the task manager is done with |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 | 655 |
656 if (!found) { | 656 if (!found) { |
657 error_ = ErrorUtils::FormatErrorMessage(errors::kProcessNotFound, | 657 error_ = ErrorUtils::FormatErrorMessage(errors::kProcessNotFound, |
658 base::IntToString(process_id_)); | 658 base::IntToString(process_id_)); |
659 SendResponse(false); | 659 SendResponse(false); |
660 } else { | 660 } else { |
661 SetResult(new base::FundamentalValue(killed)); | 661 SetResult(new base::FundamentalValue(killed)); |
662 SendResponse(true); | 662 SendResponse(true); |
663 } | 663 } |
664 | 664 |
665 // Balance the AddRef in the RunImpl. | 665 // Balance the AddRef in the RunAsync. |
666 Release(); | 666 Release(); |
667 #else | 667 #else |
668 error_ = errors::kExtensionNotSupported; | 668 error_ = errors::kExtensionNotSupported; |
669 SendResponse(false); | 669 SendResponse(false); |
670 #endif // defined(ENABLE_TASK_MANAGER) | 670 #endif // defined(ENABLE_TASK_MANAGER) |
671 } | 671 } |
672 | 672 |
673 GetProcessInfoFunction::GetProcessInfoFunction() | 673 GetProcessInfoFunction::GetProcessInfoFunction() |
674 #if defined(ENABLE_TASK_MANAGER) | 674 #if defined(ENABLE_TASK_MANAGER) |
675 : memory_(false) | 675 : memory_(false) |
676 #endif | 676 #endif |
677 { | 677 { |
678 } | 678 } |
679 | 679 |
680 GetProcessInfoFunction::~GetProcessInfoFunction() { | 680 GetProcessInfoFunction::~GetProcessInfoFunction() { |
681 } | 681 } |
682 | 682 |
683 bool GetProcessInfoFunction::RunImpl() { | 683 bool GetProcessInfoFunction::RunAsync() { |
684 #if defined(ENABLE_TASK_MANAGER) | 684 #if defined(ENABLE_TASK_MANAGER) |
685 base::Value* processes = NULL; | 685 base::Value* processes = NULL; |
686 | 686 |
687 EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &processes)); | 687 EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &processes)); |
688 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &memory_)); | 688 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &memory_)); |
689 | 689 |
690 EXTENSION_FUNCTION_VALIDATE(extensions::ReadOneOrMoreIntegers( | 690 EXTENSION_FUNCTION_VALIDATE(extensions::ReadOneOrMoreIntegers( |
691 processes, &process_ids_)); | 691 processes, &process_ids_)); |
692 | 692 |
693 // Add a reference, which is balanced in GatherProcessInfo to keep the object | 693 // Add a reference, which is balanced in GatherProcessInfo to keep the object |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 break; | 756 break; |
757 } | 757 } |
758 } | 758 } |
759 } | 759 } |
760 DCHECK_EQ(process_ids_.size(), 0U); | 760 DCHECK_EQ(process_ids_.size(), 0U); |
761 } | 761 } |
762 | 762 |
763 SetResult(processes); | 763 SetResult(processes); |
764 SendResponse(true); | 764 SendResponse(true); |
765 | 765 |
766 // Balance the AddRef in the RunImpl. | 766 // Balance the AddRef in the RunAsync. |
767 Release(); | 767 Release(); |
768 #endif // defined(ENABLE_TASK_MANAGER) | 768 #endif // defined(ENABLE_TASK_MANAGER) |
769 } | 769 } |
770 | 770 |
771 } // namespace extensions | 771 } // namespace extensions |
OLD | NEW |