Chromium Code Reviews| 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" |
| 14 | 17 |
| 15 namespace task_management { | 18 namespace task_management { |
| 16 | 19 |
| 17 namespace { | 20 namespace { |
| 18 | 21 |
| 19 base::string16 MakeTitle(const std::string& process_name) { | 22 base::string16 MakeTitle(const std::string& process_name) { |
| 20 base::string16 title = | 23 base::string16 title = |
| 21 l10n_util::GetStringFUTF16( | 24 l10n_util::GetStringFUTF16( |
| 22 IDS_TASK_MANAGER_ARC_PREFIX, base::UTF8ToUTF16(process_name)); | 25 IDS_TASK_MANAGER_ARC_PREFIX, base::UTF8ToUTF16(process_name)); |
| 23 base::i18n::AdjustStringForLocaleDirection(&title); | 26 base::i18n::AdjustStringForLocaleDirection(&title); |
| 24 return title; | 27 return title; |
| 25 } | 28 } |
| 26 | 29 |
| 30 scoped_refptr<arc::ActivityIconLoader> GetIconLoader() { | |
| 31 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 32 arc::ArcServiceManager* arc_service_manager = arc::ArcServiceManager::Get(); | |
| 33 if (!arc_service_manager) | |
| 34 return nullptr; | |
| 35 return arc_service_manager->icon_loader(); | |
| 36 } | |
| 37 | |
| 27 } // namespace | 38 } // namespace |
| 28 | 39 |
| 29 ArcProcessTask::ArcProcessTask( | 40 ArcProcessTask::ArcProcessTask(base::ProcessId pid, |
| 30 base::ProcessId pid, | 41 base::ProcessId nspid, |
| 31 base::ProcessId nspid, | 42 const std::string& process_name, |
| 32 const std::string& process_name, | 43 arc::mojom::ProcessState process_state, |
| 33 arc::mojom::ProcessState process_state) | 44 const std::vector<std::string>& packages) |
| 34 : Task(MakeTitle(process_name), process_name, nullptr, pid), | 45 : Task(MakeTitle(process_name), process_name, nullptr /* icon */, pid), |
| 35 nspid_(nspid), | 46 nspid_(nspid), |
| 36 process_name_(process_name), | 47 process_name_(process_name), |
| 37 process_state_(process_state) { | 48 process_state_(process_state), |
| 49 weak_factory_(this) { | |
| 50 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 51 if (packages.empty()) | |
| 52 return; | |
| 53 | |
| 54 std::vector<arc::ActivityIconLoader::ActivityName> activity; | |
| 55 activity.emplace_back(packages.at(0), "" /* don't care */); | |
|
Luis Héctor Chávez
2016/05/31 22:10:53
nit: kEmptyActivityName?
Luis Héctor Chávez
2016/05/31 22:10:53
Maybe add a comment explaining why you only choose
Yusuke Sato
2016/05/31 23:11:52
Done.
Yusuke Sato
2016/05/31 23:11:52
Good idea. Done.
| |
| 56 | |
| 57 scoped_refptr<arc::ActivityIconLoader> icon_loader = GetIconLoader(); | |
| 58 if (!icon_loader) | |
| 59 return; | |
| 60 | |
| 61 // TODO(yusukes): ArcProcessTask might be created before intent_helper | |
| 62 // instance becomes ready. Because of the race, OnIconLoaded() might | |
| 63 // be called synchronously with no icon. Fix the race to ensure that | |
| 64 // ArcProcessTask can always fetch icons. | |
| 65 icon_loader->GetActivityIcons( | |
| 66 activity, | |
| 67 base::Bind(&ArcProcessTask::OnIconLoaded, weak_factory_.GetWeakPtr())); | |
| 38 } | 68 } |
| 39 | 69 |
| 40 ArcProcessTask::~ArcProcessTask() { | 70 ArcProcessTask::~ArcProcessTask() { |
| 41 } | 71 } |
| 42 | 72 |
| 43 Task::Type ArcProcessTask::GetType() const { | 73 Task::Type ArcProcessTask::GetType() const { |
| 44 return Task::ARC; | 74 return Task::ARC; |
| 45 } | 75 } |
| 46 | 76 |
| 47 int ArcProcessTask::GetChildProcessUniqueID() const { | 77 int ArcProcessTask::GetChildProcessUniqueID() const { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 66 return; | 96 return; |
| 67 } | 97 } |
| 68 arc_process_instance->KillProcess( | 98 arc_process_instance->KillProcess( |
| 69 nspid_, "Killed manually from Task Manager"); | 99 nspid_, "Killed manually from Task Manager"); |
| 70 } | 100 } |
| 71 | 101 |
| 72 void ArcProcessTask::SetProcessState(arc::mojom::ProcessState process_state) { | 102 void ArcProcessTask::SetProcessState(arc::mojom::ProcessState process_state) { |
| 73 process_state_ = process_state; | 103 process_state_ = process_state; |
| 74 } | 104 } |
| 75 | 105 |
| 106 void ArcProcessTask::OnIconLoaded( | |
| 107 std::unique_ptr<arc::ActivityIconLoader::ActivityToIconsMap> icons) { | |
| 108 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 109 for (const auto& kv : *icons) { | |
| 110 const gfx::Image& icon = kv.second.icon16; | |
| 111 if (icon.IsEmpty()) | |
| 112 continue; | |
| 113 icon_ = icon; | |
| 114 set_icon(*icon_.ToImageSkia()); // pass a weak pointer of the |icon_|. | |
|
Luis Héctor Chávez
2016/05/31 22:10:53
Given that you only use one package name (and expe
Yusuke Sato
2016/05/31 23:11:52
Done.
| |
| 115 } | |
| 116 } | |
| 117 | |
| 76 } // namespace task_management | 118 } // namespace task_management |
| OLD | NEW |