| 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 weak_ptr_factory_.GetWeakPtr(), | 91 weak_ptr_factory_.GetWeakPtr(), |
| 92 callback)); | 92 callback)); |
| 93 return true; | 93 return true; |
| 94 } | 94 } |
| 95 | 95 |
| 96 void ArcProcessService::OnReceiveProcessList( | 96 void ArcProcessService::OnReceiveProcessList( |
| 97 const RequestProcessListCallback& callback, | 97 const RequestProcessListCallback& callback, |
| 98 mojo::Array<arc::mojom::RunningAppProcessInfoPtr> mojo_processes) { | 98 mojo::Array<arc::mojom::RunningAppProcessInfoPtr> mojo_processes) { |
| 99 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 99 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 100 | 100 |
| 101 auto raw_processes = new vector<mojom::RunningAppProcessInfoPtr>(); | 101 auto* raw_processes = new vector<mojom::RunningAppProcessInfoPtr>(); |
| 102 mojo_processes.Swap(raw_processes); | 102 mojo_processes.Swap(raw_processes); |
| 103 | 103 |
| 104 auto ret_processes = new vector<ArcProcess>(); | 104 auto* ret_processes = new vector<ArcProcess>(); |
| 105 // Post to its dedicated worker thread to avoid race condition. | 105 // Post to its dedicated worker thread to avoid race condition. |
| 106 // Since no two tasks with the same token should be run at the same. | 106 // Since no two tasks with the same token should be run at the same. |
| 107 // Note: GetSequencedTaskRunner's shutdown behavior defaults to | 107 // Note: GetSequencedTaskRunner's shutdown behavior defaults to |
| 108 // SKIP_ON_SHUTDOWN (ongoing task blocks shutdown). | 108 // SKIP_ON_SHUTDOWN (ongoing task blocks shutdown). |
| 109 // So in theory using Unretained(this) should be fine since the life cycle | 109 // So in theory using Unretained(this) should be fine since the life cycle |
| 110 // of |this| is the same as the main browser. | 110 // of |this| is the same as the main browser. |
| 111 // To be safe I still use weak pointers, but weak_ptrs can only bind to | 111 // To be safe I still use weak pointers, but weak_ptrs can only bind to |
| 112 // methods without return values. That's why I can't use | 112 // methods without return values. That's why I can't use |
| 113 // PostTaskAndReplyWithResult but handle the return object by myself. | 113 // PostTaskAndReplyWithResult but handle the return object by myself. |
| 114 auto runner = worker_pool_->GetSequencedTaskRunner( | 114 auto runner = worker_pool_->GetSequencedTaskRunner( |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 nspid_to_pid_.find(nspid) != nspid_to_pid_.end()) | 242 nspid_to_pid_.find(nspid) != nspid_to_pid_.end()) |
| 243 nspid_to_pid_[nspid] = pid; | 243 nspid_to_pid_[nspid] = pid; |
| 244 | 244 |
| 245 for (ProcessId child_pid : process_tree[pid]) | 245 for (ProcessId child_pid : process_tree[pid]) |
| 246 queue.push(child_pid); | 246 queue.push(child_pid); |
| 247 } | 247 } |
| 248 } | 248 } |
| 249 } | 249 } |
| 250 | 250 |
| 251 } // namespace arc | 251 } // namespace arc |
| OLD | NEW |