| 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/i18n/rtl.h" | 8 #include "base/i18n/rtl.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/grit/generated_resources.h" | 10 #include "chrome/grit/generated_resources.h" |
| 10 #include "components/arc/arc_bridge_service.h" | 11 #include "components/arc/arc_bridge_service.h" |
| 12 #include "components/arc/arc_service_manager.h" |
| 11 #include "components/arc/common/process.mojom.h" | 13 #include "components/arc/common/process.mojom.h" |
| 14 #include "content/public/browser/browser_thread.h" |
| 12 #include "content/public/common/child_process_host.h" | 15 #include "content/public/common/child_process_host.h" |
| 13 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
| 17 #include "ui/gfx/image/image.h" |
| 14 | 18 |
| 15 namespace task_management { | 19 namespace task_management { |
| 16 | 20 |
| 17 namespace { | 21 namespace { |
| 18 | 22 |
| 19 base::string16 MakeTitle(const std::string& process_name) { | 23 base::string16 MakeTitle(const std::string& process_name) { |
| 20 base::string16 title = | 24 base::string16 title = |
| 21 l10n_util::GetStringFUTF16( | 25 l10n_util::GetStringFUTF16( |
| 22 IDS_TASK_MANAGER_ARC_PREFIX, base::UTF8ToUTF16(process_name)); | 26 IDS_TASK_MANAGER_ARC_PREFIX, base::UTF8ToUTF16(process_name)); |
| 23 base::i18n::AdjustStringForLocaleDirection(&title); | 27 base::i18n::AdjustStringForLocaleDirection(&title); |
| 24 return title; | 28 return title; |
| 25 } | 29 } |
| 26 | 30 |
| 31 scoped_refptr<arc::ActivityIconLoader> GetIconLoader() { |
| 32 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 33 arc::ArcServiceManager* arc_service_manager = arc::ArcServiceManager::Get(); |
| 34 if (!arc_service_manager) |
| 35 return nullptr; |
| 36 return arc_service_manager->icon_loader(); |
| 37 } |
| 38 |
| 39 // An activity name for retrieving the package's default icon without |
| 40 // specifying an activity name. |
| 41 constexpr char kEmptyActivityName[] = ""; |
| 42 |
| 27 } // namespace | 43 } // namespace |
| 28 | 44 |
| 29 ArcProcessTask::ArcProcessTask( | 45 ArcProcessTask::ArcProcessTask(base::ProcessId pid, |
| 30 base::ProcessId pid, | 46 base::ProcessId nspid, |
| 31 base::ProcessId nspid, | 47 const std::string& process_name, |
| 32 const std::string& process_name, | 48 arc::mojom::ProcessState process_state, |
| 33 arc::mojom::ProcessState process_state) | 49 const std::vector<std::string>& packages) |
| 34 : Task(MakeTitle(process_name), process_name, nullptr, pid), | 50 : Task(MakeTitle(process_name), process_name, nullptr /* icon */, pid), |
| 35 nspid_(nspid), | 51 nspid_(nspid), |
| 36 process_name_(process_name), | 52 process_name_(process_name), |
| 37 process_state_(process_state) { | 53 process_state_(process_state), |
| 54 weak_ptr_factory_(this) { |
| 55 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 56 if (packages.empty()) |
| 57 return; |
| 58 |
| 59 std::vector<arc::ActivityIconLoader::ActivityName> activity; |
| 60 // |packages| contains an alphabetically-sorted list of package names the |
| 61 // process has. Since the Task class can hold only one icon per process, |
| 62 // and there is no reliable way to pick the most important process from |
| 63 // the |packages| list, just use the first item in the list. |
| 64 activity.emplace_back(packages.at(0), kEmptyActivityName); |
| 65 |
| 66 scoped_refptr<arc::ActivityIconLoader> icon_loader = GetIconLoader(); |
| 67 if (!icon_loader) |
| 68 return; |
| 69 |
| 70 // TODO(yusukes): ArcProcessTask might be created before intent_helper |
| 71 // instance becomes ready. Because of the race, OnIconLoaded() might |
| 72 // be called synchronously with no icon. Fix the race to ensure that |
| 73 // ArcProcessTask can always fetch icons. |
| 74 icon_loader->GetActivityIcons(activity, |
| 75 base::Bind(&ArcProcessTask::OnIconLoaded, |
| 76 weak_ptr_factory_.GetWeakPtr())); |
| 38 } | 77 } |
| 39 | 78 |
| 40 ArcProcessTask::~ArcProcessTask() { | 79 ArcProcessTask::~ArcProcessTask() { |
| 41 } | 80 } |
| 42 | 81 |
| 43 Task::Type ArcProcessTask::GetType() const { | 82 Task::Type ArcProcessTask::GetType() const { |
| 44 return Task::ARC; | 83 return Task::ARC; |
| 45 } | 84 } |
| 46 | 85 |
| 47 int ArcProcessTask::GetChildProcessUniqueID() const { | 86 int ArcProcessTask::GetChildProcessUniqueID() const { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 66 return; | 105 return; |
| 67 } | 106 } |
| 68 arc_process_instance->KillProcess( | 107 arc_process_instance->KillProcess( |
| 69 nspid_, "Killed manually from Task Manager"); | 108 nspid_, "Killed manually from Task Manager"); |
| 70 } | 109 } |
| 71 | 110 |
| 72 void ArcProcessTask::SetProcessState(arc::mojom::ProcessState process_state) { | 111 void ArcProcessTask::SetProcessState(arc::mojom::ProcessState process_state) { |
| 73 process_state_ = process_state; | 112 process_state_ = process_state; |
| 74 } | 113 } |
| 75 | 114 |
| 115 void ArcProcessTask::OnIconLoaded( |
| 116 std::unique_ptr<arc::ActivityIconLoader::ActivityToIconsMap> icons) { |
| 117 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 118 for (const auto& kv : *icons) { |
| 119 const gfx::Image& icon = kv.second.icon16; |
| 120 if (icon.IsEmpty()) |
| 121 continue; |
| 122 set_icon(*icon.ToImageSkia()); |
| 123 break; // Since the parent class can hold only one icon, break here. |
| 124 } |
| 125 } |
| 126 |
| 76 } // namespace task_management | 127 } // namespace task_management |
| OLD | NEW |