| 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 25 matching lines...) Expand all Loading... |
| 36 using base::SequencedWorkerPool; | 36 using base::SequencedWorkerPool; |
| 37 using std::map; | 37 using std::map; |
| 38 using std::set; | 38 using std::set; |
| 39 using std::vector; | 39 using std::vector; |
| 40 | 40 |
| 41 ArcProcessService::ArcProcessService(ArcBridgeService* bridge_service) | 41 ArcProcessService::ArcProcessService(ArcBridgeService* bridge_service) |
| 42 : ArcService(bridge_service), | 42 : ArcService(bridge_service), |
| 43 worker_pool_(new SequencedWorkerPool(1, "arc_process_manager")), | 43 worker_pool_(new SequencedWorkerPool(1, "arc_process_manager")), |
| 44 weak_ptr_factory_(this) { | 44 weak_ptr_factory_(this) { |
| 45 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 45 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 46 arc_bridge_service()->AddObserver(this); | 46 arc_bridge_service()->process()->AddObserver(this); |
| 47 DCHECK(!g_arc_process_service); | 47 DCHECK(!g_arc_process_service); |
| 48 g_arc_process_service = this; | 48 g_arc_process_service = this; |
| 49 // Not intended to be used from the creating thread. | 49 // Not intended to be used from the creating thread. |
| 50 thread_checker_.DetachFromThread(); | 50 thread_checker_.DetachFromThread(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 ArcProcessService::~ArcProcessService() { | 53 ArcProcessService::~ArcProcessService() { |
| 54 DCHECK(g_arc_process_service == this); | 54 DCHECK(g_arc_process_service == this); |
| 55 g_arc_process_service = nullptr; | 55 g_arc_process_service = nullptr; |
| 56 arc_bridge_service()->RemoveObserver(this); | 56 arc_bridge_service()->process()->RemoveObserver(this); |
| 57 worker_pool_->Shutdown(); | 57 worker_pool_->Shutdown(); |
| 58 } | 58 } |
| 59 | 59 |
| 60 // static | 60 // static |
| 61 ArcProcessService* ArcProcessService::Get() { | 61 ArcProcessService* ArcProcessService::Get() { |
| 62 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 62 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 63 return g_arc_process_service; | 63 return g_arc_process_service; |
| 64 } | 64 } |
| 65 | 65 |
| 66 void ArcProcessService::OnProcessInstanceReady() { | 66 void ArcProcessService::OnInstanceReady() { |
| 67 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 67 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 68 worker_pool_->PostNamedSequencedWorkerTask( | 68 worker_pool_->PostNamedSequencedWorkerTask( |
| 69 kSequenceToken, | 69 kSequenceToken, |
| 70 FROM_HERE, | 70 FROM_HERE, |
| 71 base::Bind(&ArcProcessService::Reset, | 71 base::Bind(&ArcProcessService::Reset, |
| 72 weak_ptr_factory_.GetWeakPtr())); | 72 weak_ptr_factory_.GetWeakPtr())); |
| 73 } | 73 } |
| 74 | 74 |
| 75 void ArcProcessService::Reset() { | 75 void ArcProcessService::Reset() { |
| 76 DCHECK(thread_checker_.CalledOnValidThread()); | 76 DCHECK(thread_checker_.CalledOnValidThread()); |
| 77 nspid_to_pid_.clear(); | 77 nspid_to_pid_.clear(); |
| 78 } | 78 } |
| 79 | 79 |
| 80 bool ArcProcessService::RequestProcessList( | 80 bool ArcProcessService::RequestProcessList( |
| 81 RequestProcessListCallback callback) { | 81 RequestProcessListCallback callback) { |
| 82 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 82 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 83 | 83 |
| 84 arc::mojom::ProcessInstance* process_instance = | 84 arc::mojom::ProcessInstance* process_instance = |
| 85 arc_bridge_service()->process_instance(); | 85 arc_bridge_service()->process()->instance(); |
| 86 if (!process_instance) { | 86 if (!process_instance) { |
| 87 return false; | 87 return false; |
| 88 } | 88 } |
| 89 process_instance->RequestProcessList( | 89 process_instance->RequestProcessList( |
| 90 base::Bind(&ArcProcessService::OnReceiveProcessList, | 90 base::Bind(&ArcProcessService::OnReceiveProcessList, |
| 91 weak_ptr_factory_.GetWeakPtr(), | 91 weak_ptr_factory_.GetWeakPtr(), |
| 92 callback)); | 92 callback)); |
| 93 return true; | 93 return true; |
| 94 } | 94 } |
| 95 | 95 |
| (...skipping 146 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 |