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/string_number_conversions.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 case arc::mojom::ProcessState::IMPORTANT_FOREGROUND: | 35 case arc::mojom::ProcessState::IMPORTANT_FOREGROUND: |
36 case arc::mojom::ProcessState::IMPORTANT_BACKGROUND: | 36 case arc::mojom::ProcessState::IMPORTANT_BACKGROUND: |
37 name_template = IDS_TASK_MANAGER_ARC_PREFIX_BACKGROUND_SERVICE; | 37 name_template = IDS_TASK_MANAGER_ARC_PREFIX_BACKGROUND_SERVICE; |
38 break; | 38 break; |
39 case arc::mojom::ProcessState::RECEIVER: | 39 case arc::mojom::ProcessState::RECEIVER: |
40 name_template = IDS_TASK_MANAGER_ARC_PREFIX_RECEIVER; | 40 name_template = IDS_TASK_MANAGER_ARC_PREFIX_RECEIVER; |
41 break; | 41 break; |
42 default: | 42 default: |
43 break; | 43 break; |
44 } | 44 } |
45 base::string16 title = | 45 base::string16 title = l10n_util::GetStringFUTF16( |
46 l10n_util::GetStringFUTF16( | 46 name_template, base::UTF8ToUTF16(process_name)); |
47 name_template, | |
48 base::UTF8ToUTF16(process_name)); | |
49 base::i18n::AdjustStringForLocaleDirection(&title); | 47 base::i18n::AdjustStringForLocaleDirection(&title); |
50 return title; | 48 return title; |
51 } | 49 } |
52 | 50 |
53 scoped_refptr<arc::ActivityIconLoader> GetIconLoader() { | 51 scoped_refptr<arc::ActivityIconLoader> GetIconLoader() { |
54 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 52 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
55 arc::ArcServiceManager* arc_service_manager = arc::ArcServiceManager::Get(); | 53 arc::ArcServiceManager* arc_service_manager = arc::ArcServiceManager::Get(); |
56 if (!arc_service_manager) | 54 if (!arc_service_manager) |
57 return nullptr; | 55 return nullptr; |
58 return arc_service_manager->icon_loader(); | 56 return arc_service_manager->icon_loader(); |
59 } | 57 } |
60 | 58 |
61 // An activity name for retrieving the package's default icon without | 59 // An activity name for retrieving the package's default icon without |
62 // specifying an activity name. | 60 // specifying an activity name. |
63 constexpr char kEmptyActivityName[] = ""; | 61 constexpr char kEmptyActivityName[] = ""; |
64 | 62 |
65 } // namespace | 63 } // namespace |
66 | 64 |
67 ArcProcessTask::ArcProcessTask(base::ProcessId pid, | 65 ArcProcessTask::ArcProcessTask(base::ProcessId pid, |
68 base::ProcessId nspid, | 66 base::ProcessId nspid, |
69 const std::string& process_name, | 67 const std::string& process_name, |
70 arc::mojom::ProcessState process_state, | 68 arc::mojom::ProcessState process_state, |
71 const std::vector<std::string>& packages) | 69 const std::vector<std::string>& packages) |
72 : Task(MakeTitle(process_name, process_state), process_name, | 70 : Task(MakeTitle(process_name, process_state), |
73 nullptr /* icon */, pid), | 71 process_name, |
| 72 nullptr /* icon */, |
| 73 pid), |
74 nspid_(nspid), | 74 nspid_(nspid), |
75 process_name_(process_name), | 75 process_name_(process_name), |
76 process_state_(process_state), | 76 process_state_(process_state), |
77 // |packages| contains an alphabetically-sorted list of package names the | 77 // |packages| contains an alphabetically-sorted list of package names the |
78 // 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, |
79 // 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 |
80 // the |packages| list, just use the first item in the list. | 80 // the |packages| list, just use the first item in the list. |
81 package_name_(packages.empty() ? "" : packages.at(0)), | 81 package_name_(packages.empty() ? "" : packages.at(0)), |
82 weak_ptr_factory_(this) { | 82 weak_ptr_factory_(this) { |
83 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 83 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
(...skipping 12 matching lines...) Expand all Loading... |
96 if (icon_loader) { | 96 if (icon_loader) { |
97 std::vector<arc::ActivityIconLoader::ActivityName> activities = { | 97 std::vector<arc::ActivityIconLoader::ActivityName> activities = { |
98 {package_name_, kEmptyActivityName}}; | 98 {package_name_, kEmptyActivityName}}; |
99 result = icon_loader->GetActivityIcons( | 99 result = icon_loader->GetActivityIcons( |
100 activities, base::Bind(&ArcProcessTask::OnIconLoaded, | 100 activities, base::Bind(&ArcProcessTask::OnIconLoaded, |
101 weak_ptr_factory_.GetWeakPtr())); | 101 weak_ptr_factory_.GetWeakPtr())); |
102 } | 102 } |
103 | 103 |
104 if (result == arc::ActivityIconLoader::GetResult::FAILED_ARC_NOT_READY) { | 104 if (result == arc::ActivityIconLoader::GetResult::FAILED_ARC_NOT_READY) { |
105 // Need to retry loading the icon. | 105 // Need to retry loading the icon. |
106 arc::ArcBridgeService::Get()->AddObserver(this); | 106 arc::ArcBridgeService::Get()->intent_helper()->AddObserver(this); |
107 } | 107 } |
108 } | 108 } |
109 | 109 |
110 ArcProcessTask::~ArcProcessTask() { | 110 ArcProcessTask::~ArcProcessTask() { |
111 arc::ArcBridgeService::Get()->RemoveObserver(this); | 111 arc::ArcBridgeService::Get()->intent_helper()->RemoveObserver(this); |
112 } | 112 } |
113 | 113 |
114 Task::Type ArcProcessTask::GetType() const { | 114 Task::Type ArcProcessTask::GetType() const { |
115 return Task::ARC; | 115 return Task::ARC; |
116 } | 116 } |
117 | 117 |
118 int ArcProcessTask::GetChildProcessUniqueID() const { | 118 int ArcProcessTask::GetChildProcessUniqueID() const { |
119 // ARC process is not a child process of the browser. | 119 // ARC process is not a child process of the browser. |
120 return content::ChildProcessHost::kInvalidUniqueID; | 120 return content::ChildProcessHost::kInvalidUniqueID; |
121 } | 121 } |
122 | 122 |
123 bool ArcProcessTask::IsKillable() { | 123 bool ArcProcessTask::IsKillable() { |
124 // Do not kill persistent processes. | 124 // Do not kill persistent processes. |
125 return process_state_ > arc::mojom::ProcessState::PERSISTENT_UI; | 125 return process_state_ > arc::mojom::ProcessState::PERSISTENT_UI; |
126 } | 126 } |
127 | 127 |
128 void ArcProcessTask::Kill() { | 128 void ArcProcessTask::Kill() { |
129 arc::mojom::ProcessInstance* arc_process_instance = | 129 arc::mojom::ProcessInstance* arc_process_instance = |
130 arc::ArcBridgeService::Get()->process_instance(); | 130 arc::ArcBridgeService::Get()->process()->instance(); |
131 if (!arc_process_instance) { | 131 if (!arc_process_instance) { |
132 LOG(ERROR) << "ARC process instance is not ready."; | 132 LOG(ERROR) << "ARC process instance is not ready."; |
133 return; | 133 return; |
134 } | 134 } |
135 if (arc::ArcBridgeService::Get()->process_version() < 1) { | 135 if (arc::ArcBridgeService::Get()->process()->version() < 1) { |
136 LOG(ERROR) << "ARC KillProcess IPC is unavailable."; | 136 LOG(ERROR) << "ARC KillProcess IPC is unavailable."; |
137 return; | 137 return; |
138 } | 138 } |
139 arc_process_instance->KillProcess( | 139 arc_process_instance->KillProcess(nspid_, |
140 nspid_, "Killed manually from Task Manager"); | 140 "Killed manually from Task Manager"); |
141 } | 141 } |
142 | 142 |
143 void ArcProcessTask::OnIntentHelperInstanceReady() { | 143 void ArcProcessTask::OnInstanceReady() { |
144 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 144 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
145 | 145 |
146 VLOG(2) << "intent_helper instance is ready. Fetching the icon for " | 146 VLOG(2) << "intent_helper instance is ready. Fetching the icon for " |
147 << package_name_; | 147 << package_name_; |
148 arc::ArcBridgeService::Get()->RemoveObserver(this); | 148 arc::ArcBridgeService::Get()->intent_helper()->RemoveObserver(this); |
149 | 149 |
150 // Instead of calling into StartIconLoading() directly, return to the main | 150 // Instead of calling into StartIconLoading() directly, return to the main |
151 // loop first to make sure other ArcBridgeService observers are notified. | 151 // loop first to make sure other ArcBridgeService observers are notified. |
152 // Otherwise, arc::ActivityIconLoader::GetActivityIcon() may fail again. | 152 // Otherwise, arc::ActivityIconLoader::GetActivityIcon() may fail again. |
153 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | 153 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
154 base::Bind(&ArcProcessTask::StartIconLoading, | 154 base::Bind(&ArcProcessTask::StartIconLoading, |
155 weak_ptr_factory_.GetWeakPtr())); | 155 weak_ptr_factory_.GetWeakPtr())); |
156 } | 156 } |
157 | 157 |
158 void ArcProcessTask::SetProcessState(arc::mojom::ProcessState process_state) { | 158 void ArcProcessTask::SetProcessState(arc::mojom::ProcessState process_state) { |
159 process_state_ = process_state; | 159 process_state_ = process_state; |
160 } | 160 } |
161 | 161 |
162 void ArcProcessTask::OnIconLoaded( | 162 void ArcProcessTask::OnIconLoaded( |
163 std::unique_ptr<arc::ActivityIconLoader::ActivityToIconsMap> icons) { | 163 std::unique_ptr<arc::ActivityIconLoader::ActivityToIconsMap> icons) { |
164 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 164 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
165 for (const auto& kv : *icons) { | 165 for (const auto& kv : *icons) { |
166 const gfx::Image& icon = kv.second.icon16; | 166 const gfx::Image& icon = kv.second.icon16; |
167 if (icon.IsEmpty()) | 167 if (icon.IsEmpty()) |
168 continue; | 168 continue; |
169 set_icon(*icon.ToImageSkia()); | 169 set_icon(*icon.ToImageSkia()); |
170 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. |
171 } | 171 } |
172 } | 172 } |
173 | 173 |
174 } // namespace task_management | 174 } // namespace task_management |
OLD | NEW |