OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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/task_management/providers/arc/arc_process_task.h" | 5 #include "chrome/browser/task_management/providers/arc/arc_process_task.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/i18n/rtl.h" | 8 #include "base/i18n/rtl.h" |
| 9 #include "base/strings/string_number_conversions.h" |
9 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/grit/generated_resources.h" | 11 #include "chrome/grit/generated_resources.h" |
11 #include "components/arc/arc_service_manager.h" | 12 #include "components/arc/arc_service_manager.h" |
12 #include "components/arc/common/process.mojom.h" | 13 #include "components/arc/common/process.mojom.h" |
13 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
14 #include "content/public/common/child_process_host.h" | 15 #include "content/public/common/child_process_host.h" |
15 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
16 #include "ui/gfx/image/image.h" | 17 #include "ui/gfx/image/image.h" |
17 | 18 |
18 namespace task_management { | 19 namespace task_management { |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 base::string16 MakeTitle(const std::string& process_name) { | 23 base::string16 MakeTitle(const std::string& process_name, |
| 24 arc::mojom::ProcessState process_state) { |
| 25 int name_template = IDS_TASK_MANAGER_ARC_PREFIX; |
| 26 switch (process_state) { |
| 27 case arc::mojom::ProcessState::PERSISTENT: |
| 28 case arc::mojom::ProcessState::PERSISTENT_UI: |
| 29 case arc::mojom::ProcessState::TOP: |
| 30 name_template = IDS_TASK_MANAGER_ARC_SYSTEM; |
| 31 break; |
| 32 case arc::mojom::ProcessState::BOUND_FOREGROUND_SERVICE: |
| 33 case arc::mojom::ProcessState::FOREGROUND_SERVICE: |
| 34 case arc::mojom::ProcessState::SERVICE: |
| 35 case arc::mojom::ProcessState::IMPORTANT_FOREGROUND: |
| 36 case arc::mojom::ProcessState::IMPORTANT_BACKGROUND: |
| 37 name_template = IDS_TASK_MANAGER_ARC_PREFIX_BACKGROUND_SERVICE; |
| 38 break; |
| 39 case arc::mojom::ProcessState::RECEIVER: |
| 40 name_template = IDS_TASK_MANAGER_ARC_PREFIX_RECEIVER; |
| 41 break; |
| 42 default: |
| 43 break; |
| 44 } |
23 base::string16 title = | 45 base::string16 title = |
24 l10n_util::GetStringFUTF16( | 46 l10n_util::GetStringFUTF16( |
25 IDS_TASK_MANAGER_ARC_PREFIX, base::UTF8ToUTF16(process_name)); | 47 name_template, |
| 48 base::UTF8ToUTF16(process_name)); |
26 base::i18n::AdjustStringForLocaleDirection(&title); | 49 base::i18n::AdjustStringForLocaleDirection(&title); |
27 return title; | 50 return title; |
28 } | 51 } |
29 | 52 |
30 scoped_refptr<arc::ActivityIconLoader> GetIconLoader() { | 53 scoped_refptr<arc::ActivityIconLoader> GetIconLoader() { |
31 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 54 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
32 arc::ArcServiceManager* arc_service_manager = arc::ArcServiceManager::Get(); | 55 arc::ArcServiceManager* arc_service_manager = arc::ArcServiceManager::Get(); |
33 if (!arc_service_manager) | 56 if (!arc_service_manager) |
34 return nullptr; | 57 return nullptr; |
35 return arc_service_manager->icon_loader(); | 58 return arc_service_manager->icon_loader(); |
36 } | 59 } |
37 | 60 |
38 // An activity name for retrieving the package's default icon without | 61 // An activity name for retrieving the package's default icon without |
39 // specifying an activity name. | 62 // specifying an activity name. |
40 constexpr char kEmptyActivityName[] = ""; | 63 constexpr char kEmptyActivityName[] = ""; |
41 | 64 |
42 } // namespace | 65 } // namespace |
43 | 66 |
44 ArcProcessTask::ArcProcessTask(base::ProcessId pid, | 67 ArcProcessTask::ArcProcessTask(base::ProcessId pid, |
45 base::ProcessId nspid, | 68 base::ProcessId nspid, |
46 const std::string& process_name, | 69 const std::string& process_name, |
47 arc::mojom::ProcessState process_state, | 70 arc::mojom::ProcessState process_state, |
48 const std::vector<std::string>& packages) | 71 const std::vector<std::string>& packages) |
49 : Task(MakeTitle(process_name), process_name, nullptr /* icon */, pid), | 72 : Task(MakeTitle(process_name, process_state), process_name, |
| 73 nullptr /* icon */, pid), |
50 nspid_(nspid), | 74 nspid_(nspid), |
51 process_name_(process_name), | 75 process_name_(process_name), |
52 process_state_(process_state), | 76 process_state_(process_state), |
53 // |packages| contains an alphabetically-sorted list of package names the | 77 // |packages| contains an alphabetically-sorted list of package names the |
54 // process has. Since the Task class can hold only one icon per process, | 78 // process has. Since the Task class can hold only one icon per process, |
55 // and there is no reliable way to pick the most important process from | 79 // and there is no reliable way to pick the most important process from |
56 // the |packages| list, just use the first item in the list. | 80 // the |packages| list, just use the first item in the list. |
57 package_name_(packages.empty() ? "" : packages.at(0)), | 81 package_name_(packages.empty() ? "" : packages.at(0)), |
58 weak_ptr_factory_(this) { | 82 weak_ptr_factory_(this) { |
59 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 83 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 for (const auto& kv : *icons) { | 165 for (const auto& kv : *icons) { |
142 const gfx::Image& icon = kv.second.icon16; | 166 const gfx::Image& icon = kv.second.icon16; |
143 if (icon.IsEmpty()) | 167 if (icon.IsEmpty()) |
144 continue; | 168 continue; |
145 set_icon(*icon.ToImageSkia()); | 169 set_icon(*icon.ToImageSkia()); |
146 break; // Since the parent class can hold only one icon, break here. | 170 break; // Since the parent class can hold only one icon, break here. |
147 } | 171 } |
148 } | 172 } |
149 | 173 |
150 } // namespace task_management | 174 } // namespace task_management |
OLD | NEW |