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/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 | 14 |
15 #include "chrome/browser/extensions/api/processes/processes_api_constants.h" | 15 #include "chrome/browser/extensions/api/processes/processes_api_constants.h" |
16 #include "chrome/browser/extensions/api/processes/processes_api_factory.h" | 16 #include "chrome/browser/extensions/api/processes/processes_api_factory.h" |
17 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | 17 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
18 #include "chrome/browser/extensions/event_router.h" | 18 #include "chrome/browser/extensions/event_router.h" |
19 #include "chrome/browser/extensions/extension_function_util.h" | 19 #include "chrome/browser/extensions/extension_function_util.h" |
20 #include "chrome/browser/extensions/extension_service.h" | 20 #include "chrome/browser/extensions/extension_service.h" |
21 #include "chrome/browser/extensions/extension_system.h" | 21 #include "chrome/browser/extensions/extension_system.h" |
22 #include "chrome/browser/extensions/extension_tab_util.h" | 22 #include "chrome/browser/extensions/extension_tab_util.h" |
23 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/task_manager/task_manager.h" | 24 #include "chrome/browser/task_manager/task_manager.h" |
25 #include "chrome/common/chrome_notification_types.h" | 25 #include "chrome/common/chrome_notification_types.h" |
26 #include "chrome/common/extensions/extension_error_utils.h" | |
27 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
28 #include "content/public/browser/notification_details.h" | 27 #include "content/public/browser/notification_details.h" |
29 #include "content/public/browser/notification_service.h" | 28 #include "content/public/browser/notification_service.h" |
30 #include "content/public/browser/notification_source.h" | 29 #include "content/public/browser/notification_source.h" |
31 #include "content/public/browser/notification_types.h" | 30 #include "content/public/browser/notification_types.h" |
32 #include "content/public/browser/render_process_host.h" | 31 #include "content/public/browser/render_process_host.h" |
33 #include "content/public/browser/render_view_host.h" | 32 #include "content/public/browser/render_view_host.h" |
34 #include "content/public/browser/render_widget_host.h" | 33 #include "content/public/browser/render_widget_host.h" |
35 #include "content/public/browser/web_contents.h" | 34 #include "content/public/browser/web_contents.h" |
36 #include "content/public/common/result_codes.h" | 35 #include "content/public/common/result_codes.h" |
| 36 #include "extensions/common/error_utils.h" |
37 | 37 |
38 namespace extensions { | 38 namespace extensions { |
39 | 39 |
40 namespace keys = processes_api_constants; | 40 namespace keys = processes_api_constants; |
41 namespace errors = processes_api_constants; | 41 namespace errors = processes_api_constants; |
42 | 42 |
43 namespace { | 43 namespace { |
44 | 44 |
45 #if defined(ENABLE_TASK_MANAGER) | 45 #if defined(ENABLE_TASK_MANAGER) |
46 | 46 |
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 DCHECK_EQ(type, chrome::NOTIFICATION_TASK_MANAGER_CHILD_PROCESSES_DATA_READY); | 562 DCHECK_EQ(type, chrome::NOTIFICATION_TASK_MANAGER_CHILD_PROCESSES_DATA_READY); |
563 registrar_.RemoveAll(); | 563 registrar_.RemoveAll(); |
564 GetProcessIdForTab(); | 564 GetProcessIdForTab(); |
565 } | 565 } |
566 | 566 |
567 void GetProcessIdForTabFunction::GetProcessIdForTab() { | 567 void GetProcessIdForTabFunction::GetProcessIdForTab() { |
568 content::WebContents* contents = NULL; | 568 content::WebContents* contents = NULL; |
569 int tab_index = -1; | 569 int tab_index = -1; |
570 if (!ExtensionTabUtil::GetTabById(tab_id_, profile(), include_incognito(), | 570 if (!ExtensionTabUtil::GetTabById(tab_id_, profile(), include_incognito(), |
571 NULL, NULL, &contents, &tab_index)) { | 571 NULL, NULL, &contents, &tab_index)) { |
572 error_ = ExtensionErrorUtils::FormatErrorMessage( | 572 error_ = ErrorUtils::FormatErrorMessage( |
573 extensions::tabs_constants::kTabNotFoundError, | 573 extensions::tabs_constants::kTabNotFoundError, |
574 base::IntToString(tab_id_)); | 574 base::IntToString(tab_id_)); |
575 SetResult(Value::CreateIntegerValue(-1)); | 575 SetResult(Value::CreateIntegerValue(-1)); |
576 SendResponse(false); | 576 SendResponse(false); |
577 } else { | 577 } else { |
578 int process_id = contents->GetRenderProcessHost()->GetID(); | 578 int process_id = contents->GetRenderProcessHost()->GetID(); |
579 SetResult(Value::CreateIntegerValue(process_id)); | 579 SetResult(Value::CreateIntegerValue(process_id)); |
580 SendResponse(true); | 580 SendResponse(true); |
581 } | 581 } |
582 | 582 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 found = true; | 640 found = true; |
641 killed = base::KillProcess(model->GetProcess(i), | 641 killed = base::KillProcess(model->GetProcess(i), |
642 content::RESULT_CODE_KILLED, true); | 642 content::RESULT_CODE_KILLED, true); |
643 UMA_HISTOGRAM_COUNTS("ChildProcess.KilledByExtensionAPI", 1); | 643 UMA_HISTOGRAM_COUNTS("ChildProcess.KilledByExtensionAPI", 1); |
644 break; | 644 break; |
645 } | 645 } |
646 } | 646 } |
647 } | 647 } |
648 | 648 |
649 if (!found) { | 649 if (!found) { |
650 error_ = ExtensionErrorUtils::FormatErrorMessage(errors::kProcessNotFound, | 650 error_ = ErrorUtils::FormatErrorMessage(errors::kProcessNotFound, |
651 base::IntToString(process_id_)); | 651 base::IntToString(process_id_)); |
652 SendResponse(false); | 652 SendResponse(false); |
653 } else { | 653 } else { |
654 SetResult(Value::CreateBooleanValue(killed)); | 654 SetResult(Value::CreateBooleanValue(killed)); |
655 SendResponse(true); | 655 SendResponse(true); |
656 } | 656 } |
657 | 657 |
658 // Balance the AddRef in the RunImpl. | 658 // Balance the AddRef in the RunImpl. |
659 Release(); | 659 Release(); |
660 } | 660 } |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
757 | 757 |
758 SetResult(processes); | 758 SetResult(processes); |
759 SendResponse(true); | 759 SendResponse(true); |
760 | 760 |
761 // Balance the AddRef in the RunImpl. | 761 // Balance the AddRef in the RunImpl. |
762 Release(); | 762 Release(); |
763 #endif // defined(ENABLE_TASK_MANAGER) | 763 #endif // defined(ENABLE_TASK_MANAGER) |
764 } | 764 } |
765 | 765 |
766 } // namespace extensions | 766 } // namespace extensions |
OLD | NEW |