| OLD | NEW |
| 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/arc_process_service.h" | 10 #include "chrome/browser/chromeos/arc/arc_process_service.h" |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 UpdateNspidToPidMap(); | 159 UpdateNspidToPidMap(); |
| 160 } | 160 } |
| 161 | 161 |
| 162 PopulateProcessList(raw_processes, ret_processes); | 162 PopulateProcessList(raw_processes, ret_processes); |
| 163 } | 163 } |
| 164 | 164 |
| 165 void ArcProcessService::PopulateProcessList( | 165 void ArcProcessService::PopulateProcessList( |
| 166 const vector<arc::mojom::RunningAppProcessInfoPtr>* raw_processes, | 166 const vector<arc::mojom::RunningAppProcessInfoPtr>* raw_processes, |
| 167 vector<ArcProcess>* ret_processes) { | 167 vector<ArcProcess>* ret_processes) { |
| 168 DCHECK(thread_checker_.CalledOnValidThread()); | 168 DCHECK(thread_checker_.CalledOnValidThread()); |
| 169 |
| 169 for (const auto& entry : *raw_processes) { | 170 for (const auto& entry : *raw_processes) { |
| 170 const auto it = nspid_to_pid_.find(entry->pid); | 171 const auto it = nspid_to_pid_.find(entry->pid); |
| 171 // In case the process already dies so couldn't find corresponding pid. | 172 // In case the process already dies so couldn't find corresponding pid. |
| 172 if (it != nspid_to_pid_.end() && it->second != kNullProcessId) { | 173 if (it != nspid_to_pid_.end() && it->second != kNullProcessId) { |
| 173 ArcProcess arc_process = { | 174 ArcProcess arc_process(entry->pid, it->second, entry->process_name, |
| 174 entry->pid, it->second, entry->process_name, entry->process_state}; | 175 entry->process_state); |
| 175 ret_processes->push_back(arc_process); | 176 // |entry->packages| is provided only when process.mojom's verion is >=4. |
| 177 if (entry->packages) { |
| 178 for (const auto& package : entry->packages) { |
| 179 arc_process.packages().push_back(package.get()); |
| 180 } |
| 181 } |
| 182 ret_processes->push_back(std::move(arc_process)); |
| 176 } | 183 } |
| 177 } | 184 } |
| 178 } | 185 } |
| 179 | 186 |
| 180 // Computes a map from PID in ARC namespace to PID in system namespace. | 187 // Computes a map from PID in ARC namespace to PID in system namespace. |
| 181 // The returned map contains ARC processes only. | 188 // The returned map contains ARC processes only. |
| 182 void ArcProcessService::UpdateNspidToPidMap() { | 189 void ArcProcessService::UpdateNspidToPidMap() { |
| 183 DCHECK(thread_checker_.CalledOnValidThread()); | 190 DCHECK(thread_checker_.CalledOnValidThread()); |
| 184 | 191 |
| 185 TRACE_EVENT0("browser", "ArcProcessService::UpdateNspidToPidMap"); | 192 TRACE_EVENT0("browser", "ArcProcessService::UpdateNspidToPidMap"); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 nspid_to_pid_.find(nspid) != nspid_to_pid_.end()) | 242 nspid_to_pid_.find(nspid) != nspid_to_pid_.end()) |
| 236 nspid_to_pid_[nspid] = pid; | 243 nspid_to_pid_[nspid] = pid; |
| 237 | 244 |
| 238 for (ProcessId child_pid : process_tree[pid]) | 245 for (ProcessId child_pid : process_tree[pid]) |
| 239 queue.push(child_pid); | 246 queue.push(child_pid); |
| 240 } | 247 } |
| 241 } | 248 } |
| 242 } | 249 } |
| 243 | 250 |
| 244 } // namespace arc | 251 } // namespace arc |
| OLD | NEW |