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

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

Issue 2023643002: Add ARC app icons to the Task Manager UI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix tab_manager_delegate_chromeos_unittest.cc Created 4 years, 6 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_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
38 // An activity name for retrieving the package's default icon without
39 // specifying an activity name.
40 const char kEmptyActivityName[] = "";
41
27 } // namespace 42 } // namespace
28 43
29 ArcProcessTask::ArcProcessTask( 44 ArcProcessTask::ArcProcessTask(base::ProcessId pid,
30 base::ProcessId pid, 45 base::ProcessId nspid,
31 base::ProcessId nspid, 46 const std::string& process_name,
32 const std::string& process_name, 47 arc::mojom::ProcessState process_state,
33 arc::mojom::ProcessState process_state) 48 const std::vector<std::string>& packages)
34 : Task(MakeTitle(process_name), process_name, nullptr, pid), 49 : Task(MakeTitle(process_name), process_name, nullptr /* icon */, pid),
35 nspid_(nspid), 50 nspid_(nspid),
36 process_name_(process_name), 51 process_name_(process_name),
37 process_state_(process_state) { 52 process_state_(process_state),
53 weak_factory_(this) {
54 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
55 if (packages.empty())
56 return;
57
58 std::vector<arc::ActivityIconLoader::ActivityName> activity;
59 // |packages| contains an alphabetically-sorted list of package names the
60 // process has. Since the Task class can hold only one icon per process,
61 // and there is no reliable way to pick the most important process from
62 // the |packages| list, just use the first item in the list.
63 activity.emplace_back(packages.at(0), kEmptyActivityName);
64
65 scoped_refptr<arc::ActivityIconLoader> icon_loader = GetIconLoader();
66 if (!icon_loader)
67 return;
68
69 // TODO(yusukes): ArcProcessTask might be created before intent_helper
70 // instance becomes ready. Because of the race, OnIconLoaded() might
71 // be called synchronously with no icon. Fix the race to ensure that
72 // ArcProcessTask can always fetch icons.
73 icon_loader->GetActivityIcons(
74 activity,
75 base::Bind(&ArcProcessTask::OnIconLoaded, weak_factory_.GetWeakPtr()));
38 } 76 }
39 77
40 ArcProcessTask::~ArcProcessTask() { 78 ArcProcessTask::~ArcProcessTask() {
41 } 79 }
42 80
43 Task::Type ArcProcessTask::GetType() const { 81 Task::Type ArcProcessTask::GetType() const {
44 return Task::ARC; 82 return Task::ARC;
45 } 83 }
46 84
47 int ArcProcessTask::GetChildProcessUniqueID() const { 85 int ArcProcessTask::GetChildProcessUniqueID() const {
(...skipping 18 matching lines...) Expand all
66 return; 104 return;
67 } 105 }
68 arc_process_instance->KillProcess( 106 arc_process_instance->KillProcess(
69 nspid_, "Killed manually from Task Manager"); 107 nspid_, "Killed manually from Task Manager");
70 } 108 }
71 109
72 void ArcProcessTask::SetProcessState(arc::mojom::ProcessState process_state) { 110 void ArcProcessTask::SetProcessState(arc::mojom::ProcessState process_state) {
73 process_state_ = process_state; 111 process_state_ = process_state;
74 } 112 }
75 113
114 void ArcProcessTask::OnIconLoaded(
115 std::unique_ptr<arc::ActivityIconLoader::ActivityToIconsMap> icons) {
116 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
117 for (const auto& kv : *icons) {
118 const gfx::Image& icon = kv.second.icon16;
119 if (icon.IsEmpty())
120 continue;
121 icon_ = icon;
afakhry 2016/06/01 17:07:14 Is there a reason to store gfx::Image as a member
Yusuke Sato 2016/06/01 19:11:29 I read the code again, and you're right. Removed t
122 set_icon(*icon_.ToImageSkia()); // Pass a weak pointer of the |icon_|.
123 break; // Since the parent class can hold only one icon, break here.
124 }
125 }
126
76 } // namespace task_management 127 } // namespace task_management
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698