| 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 #ifndef CHROME_BROWSER_CHROMEOS_ARC_PROCESS_ARC_PROCESS_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_ARC_PROCESS_ARC_PROCESS_SERVICE_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_ARC_PROCESS_ARC_PROCESS_SERVICE_H_ | 6 #define CHROME_BROWSER_CHROMEOS_ARC_PROCESS_ARC_PROCESS_SERVICE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 public: | 52 public: |
| 53 using RequestProcessListCallback = | 53 using RequestProcessListCallback = |
| 54 base::Callback<void(const std::vector<ArcProcess>&)>; | 54 base::Callback<void(const std::vector<ArcProcess>&)>; |
| 55 | 55 |
| 56 explicit ArcProcessService(ArcBridgeService* bridge_service); | 56 explicit ArcProcessService(ArcBridgeService* bridge_service); |
| 57 ~ArcProcessService() override; | 57 ~ArcProcessService() override; |
| 58 | 58 |
| 59 // Returns nullptr before the global instance is ready. | 59 // Returns nullptr before the global instance is ready. |
| 60 static ArcProcessService* Get(); | 60 static ArcProcessService* Get(); |
| 61 | 61 |
| 62 // InstanceHolder<mojom::ProcessInstance>::Observer overrides. | |
| 63 void OnInstanceReady() override; | |
| 64 | |
| 65 // Returns true if ARC IPC is ready for process list request, | 62 // Returns true if ARC IPC is ready for process list request, |
| 66 // otherwise false. | 63 // otherwise false. |
| 67 bool RequestAppProcessList(RequestProcessListCallback callback); | 64 bool RequestAppProcessList(RequestProcessListCallback callback); |
| 68 void RequestSystemProcessList(RequestProcessListCallback callback); | 65 void RequestSystemProcessList(RequestProcessListCallback callback); |
| 69 | 66 |
| 70 using PidMap = std::map<base::ProcessId, base::ProcessId>; | 67 using PidMap = std::map<base::ProcessId, base::ProcessId>; |
| 71 | 68 |
| 72 class NSPidToPidMap : public base::RefCountedThreadSafe<NSPidToPidMap> { | 69 class NSPidToPidMap : public base::RefCountedThreadSafe<NSPidToPidMap> { |
| 73 public: | 70 public: |
| 74 NSPidToPidMap(); | 71 NSPidToPidMap(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 96 DISALLOW_COPY_AND_ASSIGN(NSPidToPidMap); | 93 DISALLOW_COPY_AND_ASSIGN(NSPidToPidMap); |
| 97 }; | 94 }; |
| 98 | 95 |
| 99 private: | 96 private: |
| 100 void OnReceiveProcessList( | 97 void OnReceiveProcessList( |
| 101 const RequestProcessListCallback& callback, | 98 const RequestProcessListCallback& callback, |
| 102 std::vector<mojom::RunningAppProcessInfoPtr> instance_processes); | 99 std::vector<mojom::RunningAppProcessInfoPtr> instance_processes); |
| 103 | 100 |
| 104 scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner(); | 101 scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner(); |
| 105 | 102 |
| 103 // InstanceHolder<mojom::ProcessInstance>::Observer overrides. |
| 104 void OnInstanceReady() override; |
| 105 void OnInstanceClosed() override; |
| 106 |
| 107 // Whether ARC is ready to request its process list. |
| 108 bool instance_ready_ = false; |
| 109 |
| 106 // There are some expensive tasks such as traverse whole process tree that | 110 // There are some expensive tasks such as traverse whole process tree that |
| 107 // we can't do it on the UI thread. Thus we need an additional thread to | 111 // we can't do it on the UI thread. Thus we need an additional thread to |
| 108 // handle | 112 // handle |
| 109 // such tasks. | 113 // such tasks. |
| 110 base::Thread heavy_task_thread_; | 114 base::Thread heavy_task_thread_; |
| 111 | 115 |
| 112 // Keep a cache pid mapping of all arc processes so to minimize the number of | 116 // Keep a cache pid mapping of all arc processes so to minimize the number of |
| 113 // nspid lookup from /proc/<PID>/status. | 117 // nspid lookup from /proc/<PID>/status. |
| 114 // To play safe, always modify |nspid_to_pid_| on the |heavy_task_thread_|. | 118 // To play safe, always modify |nspid_to_pid_| on the |heavy_task_thread_|. |
| 115 scoped_refptr<NSPidToPidMap> nspid_to_pid_; | 119 scoped_refptr<NSPidToPidMap> nspid_to_pid_; |
| 116 | 120 |
| 117 // Always keep this the last member of this class to make sure it's the | 121 // Always keep this the last member of this class to make sure it's the |
| 118 // first thing to be destructed. | 122 // first thing to be destructed. |
| 119 base::WeakPtrFactory<ArcProcessService> weak_ptr_factory_; | 123 base::WeakPtrFactory<ArcProcessService> weak_ptr_factory_; |
| 120 | 124 |
| 121 DISALLOW_COPY_AND_ASSIGN(ArcProcessService); | 125 DISALLOW_COPY_AND_ASSIGN(ArcProcessService); |
| 122 }; | 126 }; |
| 123 | 127 |
| 124 } // namespace arc | 128 } // namespace arc |
| 125 | 129 |
| 126 #endif // CHROME_BROWSER_CHROMEOS_ARC_PROCESS_ARC_PROCESS_SERVICE_H_ | 130 #endif // CHROME_BROWSER_CHROMEOS_ARC_PROCESS_ARC_PROCESS_SERVICE_H_ |
| OLD | NEW |