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

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: review 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"
Luis Héctor Chávez 2016/06/02 16:59:47 Keep it for IWYU?
Yusuke Sato 2016/06/02 18:03:19 This has been moved to the header side, and as far
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 27 matching lines...) Expand all
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),
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 if (!StartIconLoading()) {
65 // Need to retry loading the icon.
66 arc::ArcBridgeService::Get()->AddObserver(this);
67 }
68 }
69
70 bool ArcProcessTask::StartIconLoading() {
71 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
72 std::vector<arc::ActivityIconLoader::ActivityName> activity;
Luis Héctor Chávez 2016/06/02 16:59:47 nit: maybe only do this in the if block?
Yusuke Sato 2016/06/02 18:03:19 Good catch, done.
73 activity.emplace_back(package_name_, kEmptyActivityName);
65 74
66 scoped_refptr<arc::ActivityIconLoader> icon_loader = GetIconLoader(); 75 scoped_refptr<arc::ActivityIconLoader> icon_loader = GetIconLoader();
67 if (!icon_loader) 76 arc::ActivityIconLoader::GetResult result =
68 return; 77 arc::ActivityIconLoader::GetResult::FAILED_ARC_NOT_READY;
78 if (icon_loader) {
79 result = icon_loader->GetActivityIcons(
80 activity, base::Bind(&ArcProcessTask::OnIconLoaded,
81 weak_ptr_factory_.GetWeakPtr()));
82 }
69 83
70 // TODO(yusukes): ArcProcessTask might be created before intent_helper 84 // Returns true when there is no need to call GetActivityIcons() later.
71 // instance becomes ready. Because of the race, OnIconLoaded() might 85 return result != arc::ActivityIconLoader::GetResult::FAILED_ARC_NOT_READY;
72 // be called synchronously with no icon. Fix the race to ensure that
73 // ArcProcessTask can always fetch icons.
74 icon_loader->GetActivityIcons(activity,
75 base::Bind(&ArcProcessTask::OnIconLoaded,
76 weak_ptr_factory_.GetWeakPtr()));
77 } 86 }
78 87
79 ArcProcessTask::~ArcProcessTask() { 88 ArcProcessTask::~ArcProcessTask() {
89 arc::ArcBridgeService::Get()->RemoveObserver(this);
80 } 90 }
81 91
82 Task::Type ArcProcessTask::GetType() const { 92 Task::Type ArcProcessTask::GetType() const {
83 return Task::ARC; 93 return Task::ARC;
84 } 94 }
85 95
86 int ArcProcessTask::GetChildProcessUniqueID() const { 96 int ArcProcessTask::GetChildProcessUniqueID() const {
87 // ARC process is not a child process of the browser. 97 // ARC process is not a child process of the browser.
88 return content::ChildProcessHost::kInvalidUniqueID; 98 return content::ChildProcessHost::kInvalidUniqueID;
89 } 99 }
(...skipping 11 matching lines...) Expand all
101 return; 111 return;
102 } 112 }
103 if (arc::ArcBridgeService::Get()->process_version() < 1) { 113 if (arc::ArcBridgeService::Get()->process_version() < 1) {
104 LOG(ERROR) << "ARC KillProcess IPC is unavailable."; 114 LOG(ERROR) << "ARC KillProcess IPC is unavailable.";
105 return; 115 return;
106 } 116 }
107 arc_process_instance->KillProcess( 117 arc_process_instance->KillProcess(
108 nspid_, "Killed manually from Task Manager"); 118 nspid_, "Killed manually from Task Manager");
109 } 119 }
110 120
121 void ArcProcessTask::OnIntentHelperInstanceReady() {
122 VLOG(2) << "intent_helper instance is ready. Fetching the icon for "
123 << package_name_;
124 arc::ArcBridgeService::Get()->RemoveObserver(this);
125
126 // Instead of calling into StartIconLoading() directly, return to the main
127 // loop first to make sure other ArcBridgeService observers are notified.
128 // Otherwise, arc::ActivityIconLoader::GetActivityIcon() may fail again.
129 content::BrowserThread::PostTask(
130 content::BrowserThread::UI, FROM_HERE,
131 base::Bind(base::IgnoreResult(&ArcProcessTask::StartIconLoading),
Luis Héctor Chávez 2016/06/02 16:59:47 It might be the case that by the time you call Sta
Yusuke Sato 2016/06/02 18:03:19 Done. I'd keep this PostTask though (because direc
Luis Héctor Chávez 2016/06/02 20:03:51 Keeping the PostTask is the right way to do it.
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

Powered by Google App Engine
This is Rietveld 408576698