Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / task_management / providers / child_process_task.cc
blob9770adc3931cdf172fce2ddbd502d433ce90f716
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/task_management/providers/child_process_task.h"
7 #include "base/i18n/rtl.h"
8 #include "chrome/grit/generated_resources.h"
9 #include "components/nacl/common/nacl_process_type.h"
10 #include "content/public/browser/child_process_data.h"
11 #include "content/public/common/process_type.h"
12 #include "grit/theme_resources.h"
13 #include "ui/base/l10n/l10n_util.h"
14 #include "ui/base/resource/resource_bundle.h"
16 namespace task_management {
18 namespace {
20 gfx::ImageSkia* g_default_icon = nullptr;
22 gfx::ImageSkia* GetDefaultIcon() {
23 if (!g_default_icon && ResourceBundle::HasSharedInstance()) {
24 g_default_icon = ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
25 IDR_PLUGINS_FAVICON);
28 return g_default_icon;
31 base::string16 GetLocalizedTitle(const base::string16& title,
32 int process_type) {
33 base::string16 result_title = title;
34 if (result_title.empty()) {
35 switch (process_type) {
36 case content::PROCESS_TYPE_PLUGIN:
37 case content::PROCESS_TYPE_PPAPI_PLUGIN:
38 case content::PROCESS_TYPE_PPAPI_BROKER:
39 result_title = l10n_util::GetStringUTF16(
40 IDS_TASK_MANAGER_UNKNOWN_PLUGIN_NAME);
41 break;
42 default:
43 // Nothing to do for non-plugin processes.
44 break;
48 // Explicitly mark name as LTR if there is no strong RTL character,
49 // to avoid the wrong concatenation result similar to "!Yahoo Mail: the
50 // best web-based Email: NIGULP", in which "NIGULP" stands for the Hebrew
51 // or Arabic word for "plugin".
52 base::i18n::AdjustStringForLocaleDirection(&result_title);
54 switch (process_type) {
55 case content::PROCESS_TYPE_UTILITY:
56 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_UTILITY_PREFIX);
57 case content::PROCESS_TYPE_GPU:
58 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_GPU_PREFIX);
59 case content::PROCESS_TYPE_PLUGIN:
60 case content::PROCESS_TYPE_PPAPI_PLUGIN:
61 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_PLUGIN_PREFIX,
62 result_title);
63 case content::PROCESS_TYPE_PPAPI_BROKER:
64 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_PLUGIN_BROKER_PREFIX,
65 result_title);
66 case PROCESS_TYPE_NACL_BROKER:
67 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NACL_BROKER_PREFIX);
68 case PROCESS_TYPE_NACL_LOADER:
69 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_NACL_PREFIX,
70 result_title);
71 // These types don't need display names or get them from elsewhere.
72 case content::PROCESS_TYPE_BROWSER:
73 case content::PROCESS_TYPE_RENDERER:
74 case content::PROCESS_TYPE_ZYGOTE:
75 case content::PROCESS_TYPE_SANDBOX_HELPER:
76 case content::PROCESS_TYPE_MAX:
77 break;
78 case content::PROCESS_TYPE_UNKNOWN:
79 NOTREACHED() << "Need localized name for child process type.";
82 return result_title;
85 } // namespace
87 ChildProcessTask::ChildProcessTask(const content::ChildProcessData& data)
88 : Task(GetLocalizedTitle(data.name, data.process_type),
89 GetDefaultIcon(),
90 data.handle),
91 unique_child_process_id_(data.id),
92 process_type_(data.process_type) {
95 ChildProcessTask::~ChildProcessTask() {
98 Task::Type ChildProcessTask::GetType() const {
99 // Convert |content::ProcessType| to |task_management::Task::Type|.
100 switch (process_type_) {
101 case content::PROCESS_TYPE_PLUGIN:
102 case content::PROCESS_TYPE_PPAPI_PLUGIN:
103 case content::PROCESS_TYPE_PPAPI_BROKER:
104 return Task::PLUGIN;
105 case content::PROCESS_TYPE_UTILITY:
106 return Task::UTILITY;
107 case content::PROCESS_TYPE_ZYGOTE:
108 return Task::ZYGOTE;
109 case content::PROCESS_TYPE_SANDBOX_HELPER:
110 return Task::SANDBOX_HELPER;
111 case content::PROCESS_TYPE_GPU:
112 return Task::GPU;
113 case PROCESS_TYPE_NACL_LOADER:
114 case PROCESS_TYPE_NACL_BROKER:
115 return Task::NACL;
116 default:
117 return Task::UNKNOWN;
121 int ChildProcessTask::GetChildProcessUniqueID() const {
122 return unique_child_process_id_;
125 } // namespace task_management