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

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

Issue 2034543003: Retry icon fetching after intent_helper is ready (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add a missing public 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/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 21 matching lines...) Expand all
43 } // namespace 42 } // namespace
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),
afakhry 2016/06/02 22:23:20 Nit: I would add here instead: package_name_(!pac
Yusuke Sato 2016/06/02 23:02:34 Done.
54 weak_ptr_factory_(this) { 53 weak_ptr_factory_(this) {
55 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 54 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
56 if (packages.empty()) 55 if (packages.empty())
57 return; 56 return;
58 57
59 std::vector<arc::ActivityIconLoader::ActivityName> activity;
60 // |packages| contains an alphabetically-sorted list of package names the 58 // |packages| contains an alphabetically-sorted list of package names the
61 // process has. Since the Task class can hold only one icon per process, 59 // process has. Since the Task class can hold only one icon per process,
62 // and there is no reliable way to pick the most important process from 60 // and there is no reliable way to pick the most important process from
63 // the |packages| list, just use the first item in the list. 61 // the |packages| list, just use the first item in the list.
64 activity.emplace_back(packages.at(0), kEmptyActivityName); 62 package_name_ = packages.at(0);
63
64 StartIconLoading();
65 }
66
67 void ArcProcessTask::StartIconLoading() {
68 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
65 69
66 scoped_refptr<arc::ActivityIconLoader> icon_loader = GetIconLoader(); 70 scoped_refptr<arc::ActivityIconLoader> icon_loader = GetIconLoader();
67 if (!icon_loader) 71 arc::ActivityIconLoader::GetResult result =
68 return; 72 arc::ActivityIconLoader::GetResult::FAILED_ARC_NOT_READY;
73 if (icon_loader) {
74 std::vector<arc::ActivityIconLoader::ActivityName> activity = {
afakhry 2016/06/02 22:23:20 Nit: I would call this |activities| (plural) since
Yusuke Sato 2016/06/02 23:02:34 Done.
75 {package_name_, kEmptyActivityName}};
76 result = icon_loader->GetActivityIcons(
77 activity, base::Bind(&ArcProcessTask::OnIconLoaded,
78 weak_ptr_factory_.GetWeakPtr()));
79 }
69 80
70 // TODO(yusukes): ArcProcessTask might be created before intent_helper 81 if (result == arc::ActivityIconLoader::GetResult::FAILED_ARC_NOT_READY) {
71 // instance becomes ready. Because of the race, OnIconLoaded() might 82 // Need to retry loading the icon.
72 // be called synchronously with no icon. Fix the race to ensure that 83 arc::ArcBridgeService::Get()->AddObserver(this);
73 // ArcProcessTask can always fetch icons. 84 }
74 icon_loader->GetActivityIcons(activity,
75 base::Bind(&ArcProcessTask::OnIconLoaded,
76 weak_ptr_factory_.GetWeakPtr()));
77 } 85 }
78 86
79 ArcProcessTask::~ArcProcessTask() { 87 ArcProcessTask::~ArcProcessTask() {
88 arc::ArcBridgeService::Get()->RemoveObserver(this);
afakhry 2016/06/02 21:47:12 What happens if you're not observing?
Yusuke Sato 2016/06/02 21:56:06 Nothing happens. It's implemented with base::Obser
afakhry 2016/06/02 22:23:20 Acknowledged.
Yusuke Sato 2016/06/02 23:02:34 Done. CL in CQ: https://codereview.chromium.org/20
80 } 89 }
81 90
82 Task::Type ArcProcessTask::GetType() const { 91 Task::Type ArcProcessTask::GetType() const {
83 return Task::ARC; 92 return Task::ARC;
84 } 93 }
85 94
86 int ArcProcessTask::GetChildProcessUniqueID() const { 95 int ArcProcessTask::GetChildProcessUniqueID() const {
87 // ARC process is not a child process of the browser. 96 // ARC process is not a child process of the browser.
88 return content::ChildProcessHost::kInvalidUniqueID; 97 return content::ChildProcessHost::kInvalidUniqueID;
89 } 98 }
(...skipping 11 matching lines...) Expand all
101 return; 110 return;
102 } 111 }
103 if (arc::ArcBridgeService::Get()->process_version() < 1) { 112 if (arc::ArcBridgeService::Get()->process_version() < 1) {
104 LOG(ERROR) << "ARC KillProcess IPC is unavailable."; 113 LOG(ERROR) << "ARC KillProcess IPC is unavailable.";
105 return; 114 return;
106 } 115 }
107 arc_process_instance->KillProcess( 116 arc_process_instance->KillProcess(
108 nspid_, "Killed manually from Task Manager"); 117 nspid_, "Killed manually from Task Manager");
109 } 118 }
110 119
120 void ArcProcessTask::OnIntentHelperInstanceReady() {
121 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
122
123 VLOG(2) << "intent_helper instance is ready. Fetching the icon for "
124 << package_name_;
125 arc::ArcBridgeService::Get()->RemoveObserver(this);
126
127 // Instead of calling into StartIconLoading() directly, return to the main
128 // loop first to make sure other ArcBridgeService observers are notified.
129 // Otherwise, arc::ActivityIconLoader::GetActivityIcon() may fail again.
130 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
131 base::Bind(&ArcProcessTask::StartIconLoading,
132 weak_ptr_factory_.GetWeakPtr()));
133 }
134
111 void ArcProcessTask::SetProcessState(arc::mojom::ProcessState process_state) { 135 void ArcProcessTask::SetProcessState(arc::mojom::ProcessState process_state) {
112 process_state_ = process_state; 136 process_state_ = process_state;
113 } 137 }
114 138
115 void ArcProcessTask::OnIconLoaded( 139 void ArcProcessTask::OnIconLoaded(
116 std::unique_ptr<arc::ActivityIconLoader::ActivityToIconsMap> icons) { 140 std::unique_ptr<arc::ActivityIconLoader::ActivityToIconsMap> icons) {
117 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 141 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
118 for (const auto& kv : *icons) { 142 for (const auto& kv : *icons) {
119 const gfx::Image& icon = kv.second.icon16; 143 const gfx::Image& icon = kv.second.icon16;
120 if (icon.IsEmpty()) 144 if (icon.IsEmpty())
121 continue; 145 continue;
122 set_icon(*icon.ToImageSkia()); 146 set_icon(*icon.ToImageSkia());
123 break; // Since the parent class can hold only one icon, break here. 147 break; // Since the parent class can hold only one icon, break here.
124 } 148 }
125 } 149 }
126 150
127 } // namespace task_management 151 } // namespace task_management
OLDNEW
« no previous file with comments | « chrome/browser/task_management/providers/arc/arc_process_task.h ('k') | components/arc/intent_helper/activity_icon_loader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698