OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_TASK_MANAGER_PROVIDERS_ARC_ARC_PROCESS_TASK_PROVIDER_H_ | 5 #ifndef CHROME_BROWSER_TASK_MANAGER_PROVIDERS_ARC_ARC_PROCESS_TASK_PROVIDER_H_ |
6 #define CHROME_BROWSER_TASK_MANAGER_PROVIDERS_ARC_ARC_PROCESS_TASK_PROVIDER_H_ | 6 #define CHROME_BROWSER_TASK_MANAGER_PROVIDERS_ARC_ARC_PROCESS_TASK_PROVIDER_H_ |
7 | 7 |
8 #include <map> | |
9 #include <memory> | 8 #include <memory> |
10 #include <set> | 9 #include <unordered_map> |
11 #include <string> | |
12 #include <vector> | 10 #include <vector> |
13 | 11 |
| 12 #include "base/callback.h" |
14 #include "base/macros.h" | 13 #include "base/macros.h" |
15 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
16 #include "base/process/process.h" | 15 #include "base/process/process.h" |
17 #include "chrome/browser/chromeos/arc/arc_process.h" | 16 #include "chrome/browser/chromeos/arc/arc_process.h" |
18 #include "chrome/browser/task_manager/providers/arc/arc_process_task.h" | 17 #include "chrome/browser/task_manager/providers/arc/arc_process_task.h" |
19 #include "chrome/browser/task_manager/providers/task_provider.h" | 18 #include "chrome/browser/task_manager/providers/task_provider.h" |
20 | 19 |
21 namespace task_manager { | 20 namespace task_manager { |
22 | 21 |
23 // This provides the ARC process tasks. | 22 // This provides the ARC process tasks. |
24 // | 23 // |
25 // Since this provider obtains ARC process information via IPC and procfs, | 24 // Since this provider obtains ARC process information via IPC and procfs, |
26 // it can never avoid race conditions. For example, in an extreme case such as | 25 // it can never avoid race conditions. For example, in an extreme case such as |
27 // fork(2) is called millions of times in a second, this provider can return | 26 // fork(2) is called millions of times in a second, this provider can return |
28 // wrong results. However, its chance is very low, and even if we hit the case, | 27 // wrong results. However, its chance is very low, and even if we hit the case, |
29 // the worst outcome is just that an app (non-system) process which | 28 // the worst outcome is just that an app (non-system) process which |
30 // the user did not intend to choose is killed. Since apps are designed | 29 // the user did not intend to choose is killed. Since apps are designed |
31 // to be killed at any time, it sounds acceptable. | 30 // to be killed at any time, it sounds acceptable. |
32 class ArcProcessTaskProvider : public TaskProvider { | 31 class ArcProcessTaskProvider : public TaskProvider { |
33 public: | 32 public: |
34 ArcProcessTaskProvider(); | 33 ArcProcessTaskProvider(); |
35 ~ArcProcessTaskProvider() override; | 34 ~ArcProcessTaskProvider() override; |
36 | 35 |
37 // task_manager::TaskProvider: | 36 // task_manager::TaskProvider: |
38 Task* GetTaskOfUrlRequest(int origin_pid, | 37 Task* GetTaskOfUrlRequest(int origin_pid, |
39 int child_id, | 38 int child_id, |
40 int route_id) override; | 39 int route_id) override; |
41 | 40 |
42 private: | 41 private: |
| 42 using ArcTaskMap = |
| 43 std::unordered_map<base::ProcessId, std::unique_ptr<ArcProcessTask>>; |
| 44 void ScheduleNextRequest(const base::Closure& task, const int delaySeconds); |
| 45 |
43 // Auto-retry if ARC bridge service is not ready. | 46 // Auto-retry if ARC bridge service is not ready. |
44 void RequestProcessList(); | 47 void RequestAppProcessList(); |
| 48 void RequestSystemProcessList(); |
45 | 49 |
46 void OnUpdateProcessList(const std::vector<arc::ArcProcess>& processes); | 50 void UpdateProcessList(ArcTaskMap* pid_to_task, |
| 51 const std::vector<arc::ArcProcess>& processes); |
| 52 void OnUpdateAppProcessList(const std::vector<arc::ArcProcess>& processes); |
| 53 void OnUpdateSystemProcessList(const std::vector<arc::ArcProcess>& processes); |
47 | 54 |
48 // task_manager::TaskProvider: | 55 // task_manager::TaskProvider: |
49 void StartUpdating() override; | 56 void StartUpdating() override; |
50 void StopUpdating() override; | 57 void StopUpdating() override; |
51 | 58 |
52 void ScheduleNextRequest(); | 59 void ScheduleNextAppRequest(); |
| 60 void ScheduleNextSystemRequest(); |
53 | 61 |
54 std::map<base::ProcessId, std::unique_ptr<ArcProcessTask>> nspid_to_task_; | 62 ArcTaskMap nspid_to_task_; |
| 63 ArcTaskMap nspid_to_sys_task_; |
55 | 64 |
56 // Whether to continue the periodical polling. | 65 // Whether to continue the periodical polling. |
57 bool is_updating_; | 66 bool is_updating_; |
58 | 67 |
59 // Always keep this the last member of this class to make sure it's the | 68 // Always keep this the last member of this class to make sure it's the |
60 // first thing to be destructed. | 69 // first thing to be destructed. |
61 base::WeakPtrFactory<ArcProcessTaskProvider> weak_ptr_factory_; | 70 base::WeakPtrFactory<ArcProcessTaskProvider> weak_ptr_factory_; |
62 | 71 |
63 DISALLOW_COPY_AND_ASSIGN(ArcProcessTaskProvider); | 72 DISALLOW_COPY_AND_ASSIGN(ArcProcessTaskProvider); |
64 }; | 73 }; |
65 | 74 |
66 } // namespace task_manager | 75 } // namespace task_manager |
67 | 76 |
68 #endif // CHROME_BROWSER_TASK_MANAGER_PROVIDERS_ARC_ARC_PROCESS_TASK_PROVIDER_H
_ | 77 #endif // CHROME_BROWSER_TASK_MANAGER_PROVIDERS_ARC_ARC_PROCESS_TASK_PROVIDER_H
_ |
OLD | NEW |