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_manager/providers/arc/arc_process_task.h" | 5 #include "chrome/browser/task_manager/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" |
| 11 #include "chrome/grit/generated_resources.h" | 11 #include "chrome/grit/generated_resources.h" |
| 12 #include "components/arc/arc_bridge_service.h" | 12 #include "components/arc/arc_bridge_service.h" |
| 13 #include "components/arc/arc_service_manager.h" | 13 #include "components/arc/arc_service_manager.h" |
| 14 #include "components/arc/common/process.mojom.h" | 14 #include "components/arc/common/process.mojom.h" |
| 15 #include "components/arc/intent_helper/arc_intent_helper_bridge.h" | |
| 15 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/common/child_process_host.h" | 17 #include "content/public/common/child_process_host.h" |
| 17 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
| 18 #include "ui/gfx/image/image.h" | 19 #include "ui/gfx/image/image.h" |
| 19 | 20 |
| 20 namespace task_manager { | 21 namespace task_manager { |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 base::string16 MakeTitle(const std::string& process_name, | 25 base::string16 MakeTitle(const std::string& process_name, |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 42 break; | 43 break; |
| 43 default: | 44 default: |
| 44 break; | 45 break; |
| 45 } | 46 } |
| 46 base::string16 title = l10n_util::GetStringFUTF16( | 47 base::string16 title = l10n_util::GetStringFUTF16( |
| 47 name_template, base::UTF8ToUTF16(process_name)); | 48 name_template, base::UTF8ToUTF16(process_name)); |
| 48 base::i18n::AdjustStringForLocaleDirection(&title); | 49 base::i18n::AdjustStringForLocaleDirection(&title); |
| 49 return title; | 50 return title; |
| 50 } | 51 } |
| 51 | 52 |
| 52 scoped_refptr<arc::ActivityIconLoader> GetIconLoader() { | |
|
afakhry
2017/01/28 01:08:43
You could still keep this function:
arc::Activity
hidehiko
2017/01/30 17:04:03
Hmm... Could you elaborate what's the goal to keep
| |
| 53 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 54 arc::ArcServiceManager* arc_service_manager = arc::ArcServiceManager::Get(); | |
| 55 if (!arc_service_manager) | |
| 56 return nullptr; | |
| 57 return arc_service_manager->icon_loader(); | |
| 58 } | |
| 59 | |
| 60 // An activity name for retrieving the package's default icon without | 53 // An activity name for retrieving the package's default icon without |
| 61 // specifying an activity name. | 54 // specifying an activity name. |
| 62 constexpr char kEmptyActivityName[] = ""; | 55 constexpr char kEmptyActivityName[] = ""; |
| 63 | 56 |
| 64 } // namespace | 57 } // namespace |
| 65 | 58 |
| 66 ArcProcessTask::ArcProcessTask(base::ProcessId pid, | 59 ArcProcessTask::ArcProcessTask(base::ProcessId pid, |
| 67 base::ProcessId nspid, | 60 base::ProcessId nspid, |
| 68 const std::string& process_name, | 61 const std::string& process_name, |
| 69 arc::mojom::ProcessState process_state, | 62 arc::mojom::ProcessState process_state, |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 81 // the |packages| list, just use the first item in the list. | 74 // the |packages| list, just use the first item in the list. |
| 82 package_name_(packages.empty() ? "" : packages.at(0)), | 75 package_name_(packages.empty() ? "" : packages.at(0)), |
| 83 weak_ptr_factory_(this) { | 76 weak_ptr_factory_(this) { |
| 84 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 77 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 85 StartIconLoading(); | 78 StartIconLoading(); |
| 86 } | 79 } |
| 87 | 80 |
| 88 void ArcProcessTask::StartIconLoading() { | 81 void ArcProcessTask::StartIconLoading() { |
| 89 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 82 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 90 | 83 |
| 91 scoped_refptr<arc::ActivityIconLoader> icon_loader = GetIconLoader(); | 84 auto* intent_helper_bridge = |
| 85 arc::ArcServiceManager::GetGlobalService<arc::ArcIntentHelperBridge>(); | |
| 92 arc::ActivityIconLoader::GetResult result = | 86 arc::ActivityIconLoader::GetResult result = |
| 93 arc::ActivityIconLoader::GetResult::FAILED_ARC_NOT_READY; | 87 arc::ActivityIconLoader::GetResult::FAILED_ARC_NOT_READY; |
| 94 if (icon_loader) { | 88 if (intent_helper_bridge) { |
| 95 // In some case, the package_name_ does not exists, it would be expected to | 89 // In some case, the package_name_ does not exists, it would be expected to |
| 96 // get default process icon. For example, daemon processes in android | 90 // get default process icon. For example, daemon processes in android |
| 97 // container such like surfaceflinger, debuggerd or installd. Each of them | 91 // container such like surfaceflinger, debuggerd or installd. Each of them |
| 98 // would be shown on task manager but does not have a package name. | 92 // would be shown on task manager but does not have a package name. |
| 99 std::vector<arc::ActivityIconLoader::ActivityName> activities = { | 93 std::vector<arc::ActivityIconLoader::ActivityName> activities = { |
| 100 {package_name_, kEmptyActivityName}}; | 94 {package_name_, kEmptyActivityName}}; |
| 101 result = icon_loader->GetActivityIcons( | 95 result = intent_helper_bridge->icon_loader()->GetActivityIcons( |
| 102 activities, base::Bind(&ArcProcessTask::OnIconLoaded, | 96 activities, base::Bind(&ArcProcessTask::OnIconLoaded, |
| 103 weak_ptr_factory_.GetWeakPtr())); | 97 weak_ptr_factory_.GetWeakPtr())); |
| 104 } | 98 } |
| 105 | 99 |
| 106 if (result == arc::ActivityIconLoader::GetResult::FAILED_ARC_NOT_READY) { | 100 if (result == arc::ActivityIconLoader::GetResult::FAILED_ARC_NOT_READY) { |
| 107 // Need to retry loading the icon. | 101 // Need to retry loading the icon. |
| 108 arc::ArcServiceManager::Get() | 102 arc::ArcServiceManager::Get() |
| 109 ->arc_bridge_service() | 103 ->arc_bridge_service() |
| 110 ->intent_helper() | 104 ->intent_helper() |
| 111 ->AddObserver(this); | 105 ->AddObserver(this); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 174 for (const auto& kv : *icons) { | 168 for (const auto& kv : *icons) { |
| 175 const gfx::Image& icon = kv.second.icon16; | 169 const gfx::Image& icon = kv.second.icon16; |
| 176 if (icon.IsEmpty()) | 170 if (icon.IsEmpty()) |
| 177 continue; | 171 continue; |
| 178 set_icon(*icon.ToImageSkia()); | 172 set_icon(*icon.ToImageSkia()); |
| 179 break; // Since the parent class can hold only one icon, break here. | 173 break; // Since the parent class can hold only one icon, break here. |
| 180 } | 174 } |
| 181 } | 175 } |
| 182 | 176 |
| 183 } // namespace task_manager | 177 } // namespace task_manager |
| OLD | NEW |