Chromium Code Reviews| Index: chrome/browser/chromeos/arc/arc_process_service.h |
| diff --git a/chrome/browser/chromeos/arc/arc_process_service.h b/chrome/browser/chromeos/arc/arc_process_service.h |
| index 32f14863ffb3bc42c4e16b4200de0951a9a3175e..94d1555e55847bef80691e6da301ab6ea5033e41 100644 |
| --- a/chrome/browser/chromeos/arc/arc_process_service.h |
| +++ b/chrome/browser/chromeos/arc/arc_process_service.h |
| @@ -9,10 +9,11 @@ |
| #include <vector> |
| #include "base/callback.h" |
| +#include "base/macros.h" |
| #include "base/memory/ref_counted.h" |
| #include "base/memory/weak_ptr.h" |
| -#include "base/threading/sequenced_worker_pool.h" |
| -#include "base/threading/thread_checker.h" |
| +#include "base/process/process_iterator.h" |
| +#include "base/single_thread_task_runner.h" |
| #include "chrome/browser/chromeos/arc/arc_process.h" |
| #include "components/arc/arc_bridge_service.h" |
| #include "components/arc/arc_service.h" |
| @@ -22,19 +23,26 @@ namespace arc { |
| // A single global entry to get a list of ARC processes. |
| // |
| -// Call RequestProcessList() on the main UI thread to get a list of all ARC |
| -// processes. It returns vector<arc::ArcProcess>, which includes pid <-> nspid |
| -// mapping. |
| +// Call RequestAppProcessList() / RequestSystemProcessList() on the main UI |
| +// thread to get a list of all ARC app / system processes. It returns |
| +// vector<arc::ArcProcess>, which includes pid <-> nspid mapping. |
| // Example: |
| // void OnUpdateProcessList(const vector<arc::ArcProcess>&) {...} |
| // |
| // arc::ArcProcessService* arc_process_service = |
| // arc::ArcProcessService::Get(); |
| // if (!arc_process_service || |
| -// !arc_process_service->RequestProcessList( |
| +// !arc_process_service->RequestAppProcessList( |
| // base::Bind(&OnUpdateProcessList)) { |
| // LOG(ERROR) << "ARC process instance not ready."; |
| // } |
| +// |
| +// [System Process] |
| +// The system process here is defined by the scope. If the process is produced |
| +// under system_server in Android, we regard it as one of Android app process. |
| +// Otherwise, the processes that are introduced by init would then be regarded |
| +// as System Process. RequestAppProcessList() is responsible for app processes |
| +// while RequestSystemProcessList() is responsible for System Processes. |
| class ArcProcessService |
| : public ArcService, |
| public InstanceHolder<mojom::ProcessInstance>::Observer { |
| @@ -53,38 +61,49 @@ class ArcProcessService |
| // Returns true if ARC IPC is ready for process list request, |
| // otherwise false. |
| - bool RequestProcessList(RequestProcessListCallback callback); |
| + bool RequestAppProcessList(RequestProcessListCallback callback); |
| + void RequestSystemProcessList(RequestProcessListCallback callback); |
| private: |
| + using PidMap = std::map<base::ProcessId, base::ProcessId>; |
| + |
| + class NSPidToPidMap : public PidMap, |
|
Luis Héctor Chávez
2016/07/15 16:19:42
Favor composition over inheritance. std::map also
cylee1
2016/07/15 23:17:03
agree
Hsu-Cheng
2016/07/27 08:07:59
Done.
|
| + public base::RefCountedThreadSafe<NSPidToPidMap> { |
| + private: |
| + friend class base::RefCountedThreadSafe<NSPidToPidMap>; |
| + |
| + virtual ~NSPidToPidMap(); |
| + |
| + DISALLOW_COPY_AND_ASSIGN(NSPidToPidMap); |
| + }; |
| + |
| void Reset(); |
| void OnReceiveProcessList( |
| const RequestProcessListCallback& callback, |
| - mojo::Array<arc::mojom::RunningAppProcessInfoPtr> mojo_processes); |
| + mojo::Array<arc::mojom::RunningAppProcessInfoPtr> instance_processes); |
| - void CallbackRelay( |
| - const RequestProcessListCallback& callback, |
| - const std::vector<ArcProcess>* ret_processes); |
| + static std::vector<ArcProcess> UpdateAndReturnProcessList( |
|
Luis Héctor Chávez
2016/07/15 16:19:42
prefer having private static methods as standalone
Hsu-Cheng
2016/07/27 08:07:59
Done.
|
| + scoped_refptr<NSPidToPidMap> pid_map, |
| + mojo::Array<arc::mojom::RunningAppProcessInfoPtr> processes); |
| - void UpdateAndReturnProcessList( |
| - const std::vector<arc::mojom::RunningAppProcessInfoPtr>* raw_processes, |
| - std::vector<ArcProcess>* ret_processes); |
| + static std::vector<ArcProcess> FilterProcessList( |
| + NSPidToPidMap& pid_map, |
| + mojo::Array<arc::mojom::RunningAppProcessInfoPtr> processes); |
| - void PopulateProcessList( |
| - const std::vector<arc::mojom::RunningAppProcessInfoPtr>* raw_processes, |
| - std::vector<ArcProcess>* ret_processes); |
| + // Computes and updates the map from PID in ARC namespace to PID in system |
| + // namespace. |
| + static void UpdateNspidToPidMap(NSPidToPidMap& pid_map); |
| - void UpdateNspidToPidMap(); |
| + // There are some expensive tasks such as traverse whole process tree that |
| + // we can't do it on the UI thread. Thus we need a task runner to handle such |
| + // heavy tasks. |
| + scoped_refptr<base::SingleThreadTaskRunner> heavy_task_runner_; |
| // Keep a cache pid mapping of all arc processes so to minimize the number of |
| // nspid lookup from /proc/<PID>/status. |
| // To play safe, always modify |nspid_to_pid_| on the worker thread. |
| - std::map<base::ProcessId, base::ProcessId> nspid_to_pid_; |
| - |
| - scoped_refptr<base::SequencedWorkerPool> worker_pool_; |
| - |
| - // To ensure internal state changes are done on the same worker thread. |
| - base::ThreadChecker thread_checker_; |
| + scoped_refptr<NSPidToPidMap> nspid_to_pid_; |
| // Always keep this the last member of this class to make sure it's the |
| // first thing to be destructed. |