Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: chrome/browser/chromeos/arc/arc_process_service.h

Issue 2025593003: Show all system process in the task_manager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix typo and naming. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_ARC_PROCESS_SERVICE_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_ARC_ARC_PROCESS_SERVICE_H_
6 #define CHROME_BROWSER_CHROMEOS_ARC_ARC_PROCESS_SERVICE_H_ 6 #define CHROME_BROWSER_CHROMEOS_ARC_ARC_PROCESS_SERVICE_H_
7 7
8 #include <map> 8 #include <map>
9 #include <vector> 9 #include <vector>
10 10
Yusuke Sato 2016/06/30 19:46:52 nit: IWYU #include "base/macros.h" for DISALLOW_C
11 #include "base/callback.h" 11 #include "base/callback_forward.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "base/process/process_iterator.h"
14 #include "base/threading/sequenced_worker_pool.h" 15 #include "base/threading/sequenced_worker_pool.h"
15 #include "base/threading/thread_checker.h" 16 #include "base/threading/thread_checker.h"
16 #include "chrome/browser/chromeos/arc/arc_process.h" 17 #include "chrome/browser/chromeos/arc/arc_process.h"
17 #include "components/arc/arc_bridge_service.h" 18 #include "components/arc/arc_bridge_service.h"
18 #include "components/arc/arc_service.h" 19 #include "components/arc/arc_service.h"
19 20
20 namespace arc { 21 namespace arc {
21 22
22 // A single global entry to get a list of ARC processes. 23 // A single global entry to get a list of ARC processes.
23 // 24 //
24 // Call RequestProcessList() on the main UI thread to get a list of all ARC 25 // Call RequestAppProcessList() / RequestSystemProcessList() on the main UI
25 // processes. It returns vector<arc::ArcProcess>, which includes pid <-> nspid 26 // thread to get a list of all ARC app / system processes. It returns
26 // mapping. 27 // vector<arc::ArcProcess>, which includes pid <-> nspid mapping.
27 // Example: 28 // Example:
28 // void OnUpdateProcessList(const vector<arc::ArcProcess>&) {...} 29 // void OnUpdateProcessList(const vector<arc::ArcProcess>&) {...}
29 // 30 //
30 // arc::ArcProcessService* arc_process_service = 31 // arc::ArcProcessService* arc_process_service =
31 // arc::ArcProcessService::Get(); 32 // arc::ArcProcessService::Get();
32 // if (!arc_process_service || 33 // if (!arc_process_service ||
33 // !arc_process_service->RequestProcessList( 34 // !arc_process_service->RequestAppProcessList(
34 // base::Bind(&OnUpdateProcessList)) { 35 // base::Bind(&OnUpdateProcessList)) {
35 // LOG(ERROR) << "ARC process instance not ready."; 36 // LOG(ERROR) << "ARC process instance not ready.";
36 // } 37 // }
38 //
39 // [System Process]
40 // The system process here is defined by the scope. If the process is produced
41 // under system_server in Android, we regard it as one of Android app process.
42 // Otherwise, the processes that are introduced by init would then be regarded
43 // as System Process. RequestAppProcessList() is responsible for app processes
44 // while RequestSystemProcessList() is responsible for System Processes.
37 class ArcProcessService : public ArcService, 45 class ArcProcessService : public ArcService,
38 public ArcBridgeService::Observer { 46 public ArcBridgeService::Observer {
39 public: 47 public:
40 using RequestProcessListCallback = 48 using RequestProcessListCallback =
41 base::Callback<void(const std::vector<ArcProcess>&)>; 49 base::Callback<void(const std::vector<ArcProcess>&)>;
42 50
43 explicit ArcProcessService(ArcBridgeService* bridge_service); 51 explicit ArcProcessService(ArcBridgeService* bridge_service);
44 ~ArcProcessService() override; 52 ~ArcProcessService() override;
45 53
46 // Returns nullptr before the global instance is ready. 54 // Returns nullptr before the global instance is ready.
47 static ArcProcessService* Get(); 55 static ArcProcessService* Get();
48 56
49 // ArcBridgeService::Observer overrides. 57 // ArcBridgeService::Observer overrides.
50 void OnProcessInstanceReady() override; 58 void OnProcessInstanceReady() override;
51 59
52 // Returns true if ARC IPC is ready for process list request, 60 // Returns true if ARC IPC is ready for process list request,
53 // otherwise false. 61 // otherwise false.
54 bool RequestProcessList(RequestProcessListCallback callback); 62 bool RequestAppProcessList(RequestProcessListCallback callback);
Yusuke Sato 2016/06/30 19:46:52 nit: const RequestProcessListCallback& ?
63 void RequestSystemProcessList(RequestProcessListCallback callback);
Yusuke Sato 2016/06/30 19:46:52 same
55 64
56 private: 65 private:
57 void Reset(); 66 void Reset();
58 67
68 void GetArcSystemProcessList(std::vector<ArcProcess>* ret_processes);
69
70 static base::ProcessId GetArcInitProcessId(
71 const base::ProcessIterator::ProcessEntries& entry_list);
72
59 void OnReceiveProcessList( 73 void OnReceiveProcessList(
60 const RequestProcessListCallback& callback, 74 const RequestProcessListCallback& callback,
61 mojo::Array<arc::mojom::RunningAppProcessInfoPtr> mojo_processes); 75 mojo::Array<arc::mojom::RunningAppProcessInfoPtr> mojo_processes);
62 76
63 void CallbackRelay( 77 void CallbackRelay(
64 const RequestProcessListCallback& callback, 78 const RequestProcessListCallback& callback,
65 const std::vector<ArcProcess>* ret_processes); 79 const std::vector<ArcProcess>* ret_processes);
66 80
67 void UpdateAndReturnProcessList( 81 void UpdateAndReturnProcessList(
68 const std::vector<arc::mojom::RunningAppProcessInfoPtr>* raw_processes, 82 const std::vector<arc::mojom::RunningAppProcessInfoPtr>* raw_processes,
69 std::vector<ArcProcess>* ret_processes); 83 std::vector<ArcProcess>* ret_processes);
70 84
71 void PopulateProcessList( 85 void PopulateProcessList(
72 const std::vector<arc::mojom::RunningAppProcessInfoPtr>* raw_processes, 86 const std::vector<arc::mojom::RunningAppProcessInfoPtr>* raw_processes,
73 std::vector<ArcProcess>* ret_processes); 87 std::vector<ArcProcess>* ret_processes);
74 88
75 void UpdateNspidToPidMap(); 89 void UpdateNspidToPidMap();
76 90
91 void PostTaskToOwnThreadAndReply(const base::Closure& task,
92 const base::Closure& reply);
93
77 // Keep a cache pid mapping of all arc processes so to minimize the number of 94 // Keep a cache pid mapping of all arc processes so to minimize the number of
78 // nspid lookup from /proc/<PID>/status. 95 // nspid lookup from /proc/<PID>/status.
79 // To play safe, always modify |nspid_to_pid_| on the worker thread. 96 // To play safe, always modify |nspid_to_pid_| on the worker thread.
80 std::map<base::ProcessId, base::ProcessId> nspid_to_pid_; 97 std::map<base::ProcessId, base::ProcessId> nspid_to_pid_;
81 98
82 scoped_refptr<base::SequencedWorkerPool> worker_pool_; 99 scoped_refptr<base::SequencedWorkerPool> worker_pool_;
83 100
84 // To ensure internal state changes are done on the same worker thread. 101 // To ensure internal state changes are done on the same worker thread.
85 base::ThreadChecker thread_checker_; 102 base::ThreadChecker thread_checker_;
86 103
87 // Always keep this the last member of this class to make sure it's the 104 // Always keep this the last member of this class to make sure it's the
88 // first thing to be destructed. 105 // first thing to be destructed.
89 base::WeakPtrFactory<ArcProcessService> weak_ptr_factory_; 106 base::WeakPtrFactory<ArcProcessService> weak_ptr_factory_;
90 107
91 DISALLOW_COPY_AND_ASSIGN(ArcProcessService); 108 DISALLOW_COPY_AND_ASSIGN(ArcProcessService);
92 }; 109 };
93 110
94 } // namespace arc 111 } // namespace arc
95 112
96 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_PROCESS_SERVICE_H_ 113 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_PROCESS_SERVICE_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/arc/arc_process_service.cc » ('j') | chrome/browser/chromeos/arc/arc_process_service.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698