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

Side by Side Diff: chrome/browser/chromeos/arc/process/arc_process_service.cc

Issue 2495913002: arc: Convert more Mojo types to STL (Closed)
Patch Set: Created 4 years, 1 month 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 // The main point of this class is to cache ARC proc nspid<->pid mapping 5 // The main point of this class is to cache ARC proc nspid<->pid mapping
6 // globally. Since the calculation is costly, a dedicated worker thread is 6 // globally. Since the calculation is costly, a dedicated worker thread is
7 // used. All read/write of its internal data structure (i.e., the mapping) 7 // used. All read/write of its internal data structure (i.e., the mapping)
8 // should be on this thread. 8 // should be on this thread.
9 9
10 #include "chrome/browser/chromeos/arc/process/arc_process_service.h" 10 #include "chrome/browser/chromeos/arc/process/arc_process_service.h"
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 (*pid_map)[nspid] = pid; 134 (*pid_map)[nspid] = pid;
135 135
136 for (ProcessId child_pid : process_tree[pid]) 136 for (ProcessId child_pid : process_tree[pid])
137 queue.push(child_pid); 137 queue.push(child_pid);
138 } 138 }
139 } 139 }
140 } 140 }
141 141
142 std::vector<ArcProcess> FilterProcessList( 142 std::vector<ArcProcess> FilterProcessList(
143 const ArcProcessService::NSPidToPidMap& pid_map, 143 const ArcProcessService::NSPidToPidMap& pid_map,
144 mojo::Array<mojom::RunningAppProcessInfoPtr> processes) { 144 std::vector<mojom::RunningAppProcessInfoPtr> processes) {
145 std::vector<ArcProcess> ret_processes; 145 std::vector<ArcProcess> ret_processes;
146 for (const auto& entry : processes) { 146 for (const auto& entry : processes) {
147 const auto it = pid_map.find(entry->pid); 147 const auto it = pid_map.find(entry->pid);
148 // The nspid could be missing due to race condition. For example, the 148 // The nspid could be missing due to race condition. For example, the
149 // process is still running when we get the process snapshot and ends when 149 // process is still running when we get the process snapshot and ends when
150 // we update the nspid to pid mapping. 150 // we update the nspid to pid mapping.
151 if (it == pid_map.end() || it->second == base::kNullProcessId) { 151 if (it == pid_map.end() || it->second == base::kNullProcessId) {
152 continue; 152 continue;
153 } 153 }
154 // Constructs the ArcProcess instance if the mapping is found. 154 // Constructs the ArcProcess instance if the mapping is found.
155 ArcProcess arc_process(entry->pid, pid_map.at(entry->pid), 155 ArcProcess arc_process(entry->pid, pid_map.at(entry->pid),
156 entry->process_name, entry->process_state, 156 entry->process_name, entry->process_state,
157 entry->is_focused, entry->last_activity_time); 157 entry->is_focused, entry->last_activity_time);
158 // |entry->packages| is provided only when process.mojom's verion is >=4. 158 // |entry->packages| is provided only when process.mojom's verion is >=4.
159 if (entry->packages) { 159 if (entry->packages) {
160 for (const auto& package : entry->packages) { 160 for (const auto& package : *entry->packages) {
161 arc_process.packages().push_back(package.get()); 161 arc_process.packages().push_back(package);
162 } 162 }
163 } 163 }
164 ret_processes.push_back(std::move(arc_process)); 164 ret_processes.push_back(std::move(arc_process));
165 } 165 }
166 return ret_processes; 166 return ret_processes;
167 } 167 }
168 168
169 std::vector<ArcProcess> UpdateAndReturnProcessList( 169 std::vector<ArcProcess> UpdateAndReturnProcessList(
170 scoped_refptr<ArcProcessService::NSPidToPidMap> nspid_map, 170 scoped_refptr<ArcProcessService::NSPidToPidMap> nspid_map,
171 mojo::Array<mojom::RunningAppProcessInfoPtr> processes) { 171 std::vector<mojom::RunningAppProcessInfoPtr> processes) {
172 ArcProcessService::NSPidToPidMap& pid_map = *nspid_map; 172 ArcProcessService::NSPidToPidMap& pid_map = *nspid_map;
173 // Cleanup dead pids in the cache |pid_map|. 173 // Cleanup dead pids in the cache |pid_map|.
174 std::unordered_set<ProcessId> nspid_to_remove; 174 std::unordered_set<ProcessId> nspid_to_remove;
175 for (const auto& entry : pid_map) { 175 for (const auto& entry : pid_map) {
176 nspid_to_remove.insert(entry.first); 176 nspid_to_remove.insert(entry.first);
177 } 177 }
178 bool unmapped_nspid = false; 178 bool unmapped_nspid = false;
179 for (const auto& entry : processes) { 179 for (const auto& entry : processes) {
180 // erase() returns 0 if coudln't find the key. It means a new process. 180 // erase() returns 0 if coudln't find the key. It means a new process.
181 if (nspid_to_remove.erase(entry->pid) == 0) { 181 if (nspid_to_remove.erase(entry->pid) == 0) {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 return false; 252 return false;
253 } 253 }
254 process_instance->RequestProcessList( 254 process_instance->RequestProcessList(
255 base::Bind(&ArcProcessService::OnReceiveProcessList, 255 base::Bind(&ArcProcessService::OnReceiveProcessList,
256 weak_ptr_factory_.GetWeakPtr(), callback)); 256 weak_ptr_factory_.GetWeakPtr(), callback));
257 return true; 257 return true;
258 } 258 }
259 259
260 void ArcProcessService::OnReceiveProcessList( 260 void ArcProcessService::OnReceiveProcessList(
261 const RequestProcessListCallback& callback, 261 const RequestProcessListCallback& callback,
262 mojo::Array<mojom::RunningAppProcessInfoPtr> instance_processes) { 262 std::vector<mojom::RunningAppProcessInfoPtr> instance_processes) {
263 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 263 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
264 264
265 base::PostTaskAndReplyWithResult( 265 base::PostTaskAndReplyWithResult(
266 GetTaskRunner().get(), FROM_HERE, 266 GetTaskRunner().get(), FROM_HERE,
267 base::Bind(&UpdateAndReturnProcessList, nspid_to_pid_, 267 base::Bind(&UpdateAndReturnProcessList, nspid_to_pid_,
268 base::Passed(&instance_processes)), 268 base::Passed(&instance_processes)),
269 callback); 269 callback);
270 } 270 }
271 271
272 scoped_refptr<base::SingleThreadTaskRunner> ArcProcessService::GetTaskRunner() { 272 scoped_refptr<base::SingleThreadTaskRunner> ArcProcessService::GetTaskRunner() {
273 return heavy_task_thread_.task_runner(); 273 return heavy_task_thread_.task_runner();
274 } 274 }
275 275
276 inline ArcProcessService::NSPidToPidMap::NSPidToPidMap() {} 276 inline ArcProcessService::NSPidToPidMap::NSPidToPidMap() {}
277 277
278 inline ArcProcessService::NSPidToPidMap::~NSPidToPidMap() {} 278 inline ArcProcessService::NSPidToPidMap::~NSPidToPidMap() {}
279 279
280 } // namespace arc 280 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698