Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1120)

Side by Side Diff: chrome/browser/task_manager/providers/arc/arc_process_task.cc

Issue 2655233007: Get rid of RefCounted for ActivityIconLoader. (Closed)
Patch Set: address comments Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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() {
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
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 =
92 arc::ActivityIconLoader::GetResult result = 85 arc::ArcServiceManager::GetGlobalService<arc::ArcIntentHelperBridge>();
93 arc::ActivityIconLoader::GetResult::FAILED_ARC_NOT_READY; 86 arc::ArcIntentHelperBridge::GetResult result =
94 if (icon_loader) { 87 arc::ArcIntentHelperBridge::GetResult::FAILED_ARC_NOT_READY;
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::ArcIntentHelperBridge::ActivityName> activities = {
100 {package_name_, kEmptyActivityName}}; 94 {package_name_, kEmptyActivityName}};
101 result = icon_loader->GetActivityIcons( 95 result = intent_helper_bridge->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::ArcIntentHelperBridge::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);
112 } 106 }
113 } 107 }
114 108
115 ArcProcessTask::~ArcProcessTask() { 109 ArcProcessTask::~ArcProcessTask() {
116 auto* service_manager = arc::ArcServiceManager::Get(); 110 auto* service_manager = arc::ArcServiceManager::Get();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 145
152 VLOG(2) << "intent_helper instance is ready. Fetching the icon for " 146 VLOG(2) << "intent_helper instance is ready. Fetching the icon for "
153 << package_name_; 147 << package_name_;
154 arc::ArcServiceManager::Get() 148 arc::ArcServiceManager::Get()
155 ->arc_bridge_service() 149 ->arc_bridge_service()
156 ->intent_helper() 150 ->intent_helper()
157 ->RemoveObserver(this); 151 ->RemoveObserver(this);
158 152
159 // Instead of calling into StartIconLoading() directly, return to the main 153 // Instead of calling into StartIconLoading() directly, return to the main
160 // loop first to make sure other ArcBridgeService observers are notified. 154 // loop first to make sure other ArcBridgeService observers are notified.
161 // Otherwise, arc::ActivityIconLoader::GetActivityIcon() may fail again. 155 // Otherwise, arc::ArcIntentHelperBridge::GetActivityIcon() may fail again.
162 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, 156 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
163 base::Bind(&ArcProcessTask::StartIconLoading, 157 base::Bind(&ArcProcessTask::StartIconLoading,
164 weak_ptr_factory_.GetWeakPtr())); 158 weak_ptr_factory_.GetWeakPtr()));
165 } 159 }
166 160
167 void ArcProcessTask::SetProcessState(arc::mojom::ProcessState process_state) { 161 void ArcProcessTask::SetProcessState(arc::mojom::ProcessState process_state) {
168 process_state_ = process_state; 162 process_state_ = process_state;
169 } 163 }
170 164
171 void ArcProcessTask::OnIconLoaded( 165 void ArcProcessTask::OnIconLoaded(
172 std::unique_ptr<arc::ActivityIconLoader::ActivityToIconsMap> icons) { 166 std::unique_ptr<arc::ArcIntentHelperBridge::ActivityToIconsMap> icons) {
173 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 167 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
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
OLDNEW
« no previous file with comments | « chrome/browser/task_manager/providers/arc/arc_process_task.h ('k') | components/arc/arc_service_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698