| 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/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/grit/generated_resources.h" | 10 #include "chrome/grit/generated_resources.h" |
| 11 #include "components/arc/arc_bridge_service.h" | |
| 12 #include "components/arc/arc_service_manager.h" | 11 #include "components/arc/arc_service_manager.h" |
| 13 #include "components/arc/common/process.mojom.h" | 12 #include "components/arc/common/process.mojom.h" |
| 14 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 15 #include "content/public/common/child_process_host.h" | 14 #include "content/public/common/child_process_host.h" |
| 16 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
| 17 #include "ui/gfx/image/image.h" | 16 #include "ui/gfx/image/image.h" |
| 18 | 17 |
| 19 namespace task_management { | 18 namespace task_management { |
| 20 | 19 |
| 21 namespace { | 20 namespace { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 44 | 43 |
| 45 ArcProcessTask::ArcProcessTask(base::ProcessId pid, | 44 ArcProcessTask::ArcProcessTask(base::ProcessId pid, |
| 46 base::ProcessId nspid, | 45 base::ProcessId nspid, |
| 47 const std::string& process_name, | 46 const std::string& process_name, |
| 48 arc::mojom::ProcessState process_state, | 47 arc::mojom::ProcessState process_state, |
| 49 const std::vector<std::string>& packages) | 48 const std::vector<std::string>& packages) |
| 50 : Task(MakeTitle(process_name), process_name, nullptr /* icon */, pid), | 49 : Task(MakeTitle(process_name), process_name, nullptr /* icon */, pid), |
| 51 nspid_(nspid), | 50 nspid_(nspid), |
| 52 process_name_(process_name), | 51 process_name_(process_name), |
| 53 process_state_(process_state), | 52 process_state_(process_state), |
| 53 // |packages| contains an alphabetically-sorted list of package names the |
| 54 // 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 |
| 56 // the |packages| list, just use the first item in the list. |
| 57 package_name_(packages.empty() ? "" : packages.at(0)), |
| 54 weak_ptr_factory_(this) { | 58 weak_ptr_factory_(this) { |
| 55 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 59 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 56 if (packages.empty()) | 60 StartIconLoading(); |
| 61 } |
| 62 |
| 63 void ArcProcessTask::StartIconLoading() { |
| 64 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 65 |
| 66 if (package_name_.empty()) |
| 57 return; | 67 return; |
| 58 | 68 |
| 59 std::vector<arc::ActivityIconLoader::ActivityName> activity; | 69 scoped_refptr<arc::ActivityIconLoader> icon_loader = GetIconLoader(); |
| 60 // |packages| contains an alphabetically-sorted list of package names the | 70 arc::ActivityIconLoader::GetResult result = |
| 61 // process has. Since the Task class can hold only one icon per process, | 71 arc::ActivityIconLoader::GetResult::FAILED_ARC_NOT_READY; |
| 62 // and there is no reliable way to pick the most important process from | 72 if (icon_loader) { |
| 63 // the |packages| list, just use the first item in the list. | 73 std::vector<arc::ActivityIconLoader::ActivityName> activities = { |
| 64 activity.emplace_back(packages.at(0), kEmptyActivityName); | 74 {package_name_, kEmptyActivityName}}; |
| 75 result = icon_loader->GetActivityIcons( |
| 76 activities, base::Bind(&ArcProcessTask::OnIconLoaded, |
| 77 weak_ptr_factory_.GetWeakPtr())); |
| 78 } |
| 65 | 79 |
| 66 scoped_refptr<arc::ActivityIconLoader> icon_loader = GetIconLoader(); | 80 if (result == arc::ActivityIconLoader::GetResult::FAILED_ARC_NOT_READY) { |
| 67 if (!icon_loader) | 81 // Need to retry loading the icon. |
| 68 return; | 82 arc::ArcBridgeService::Get()->AddObserver(this); |
| 69 | 83 } |
| 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())); | |
| 77 } | 84 } |
| 78 | 85 |
| 79 ArcProcessTask::~ArcProcessTask() { | 86 ArcProcessTask::~ArcProcessTask() { |
| 87 arc::ArcBridgeService::Get()->RemoveObserver(this); |
| 80 } | 88 } |
| 81 | 89 |
| 82 Task::Type ArcProcessTask::GetType() const { | 90 Task::Type ArcProcessTask::GetType() const { |
| 83 return Task::ARC; | 91 return Task::ARC; |
| 84 } | 92 } |
| 85 | 93 |
| 86 int ArcProcessTask::GetChildProcessUniqueID() const { | 94 int ArcProcessTask::GetChildProcessUniqueID() const { |
| 87 // ARC process is not a child process of the browser. | 95 // ARC process is not a child process of the browser. |
| 88 return content::ChildProcessHost::kInvalidUniqueID; | 96 return content::ChildProcessHost::kInvalidUniqueID; |
| 89 } | 97 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 101 return; | 109 return; |
| 102 } | 110 } |
| 103 if (arc::ArcBridgeService::Get()->process_version() < 1) { | 111 if (arc::ArcBridgeService::Get()->process_version() < 1) { |
| 104 LOG(ERROR) << "ARC KillProcess IPC is unavailable."; | 112 LOG(ERROR) << "ARC KillProcess IPC is unavailable."; |
| 105 return; | 113 return; |
| 106 } | 114 } |
| 107 arc_process_instance->KillProcess( | 115 arc_process_instance->KillProcess( |
| 108 nspid_, "Killed manually from Task Manager"); | 116 nspid_, "Killed manually from Task Manager"); |
| 109 } | 117 } |
| 110 | 118 |
| 119 void ArcProcessTask::OnIntentHelperInstanceReady() { |
| 120 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 121 |
| 122 VLOG(2) << "intent_helper instance is ready. Fetching the icon for " |
| 123 << package_name_; |
| 124 arc::ArcBridgeService::Get()->RemoveObserver(this); |
| 125 |
| 126 // Instead of calling into StartIconLoading() directly, return to the main |
| 127 // loop first to make sure other ArcBridgeService observers are notified. |
| 128 // Otherwise, arc::ActivityIconLoader::GetActivityIcon() may fail again. |
| 129 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
| 130 base::Bind(&ArcProcessTask::StartIconLoading, |
| 131 weak_ptr_factory_.GetWeakPtr())); |
| 132 } |
| 133 |
| 111 void ArcProcessTask::SetProcessState(arc::mojom::ProcessState process_state) { | 134 void ArcProcessTask::SetProcessState(arc::mojom::ProcessState process_state) { |
| 112 process_state_ = process_state; | 135 process_state_ = process_state; |
| 113 } | 136 } |
| 114 | 137 |
| 115 void ArcProcessTask::OnIconLoaded( | 138 void ArcProcessTask::OnIconLoaded( |
| 116 std::unique_ptr<arc::ActivityIconLoader::ActivityToIconsMap> icons) { | 139 std::unique_ptr<arc::ActivityIconLoader::ActivityToIconsMap> icons) { |
| 117 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 140 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 118 for (const auto& kv : *icons) { | 141 for (const auto& kv : *icons) { |
| 119 const gfx::Image& icon = kv.second.icon16; | 142 const gfx::Image& icon = kv.second.icon16; |
| 120 if (icon.IsEmpty()) | 143 if (icon.IsEmpty()) |
| 121 continue; | 144 continue; |
| 122 set_icon(*icon.ToImageSkia()); | 145 set_icon(*icon.ToImageSkia()); |
| 123 break; // Since the parent class can hold only one icon, break here. | 146 break; // Since the parent class can hold only one icon, break here. |
| 124 } | 147 } |
| 125 } | 148 } |
| 126 | 149 |
| 127 } // namespace task_management | 150 } // namespace task_management |
| OLD | NEW |