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_MANAGEMENT_PROVIDERS_ARC_ARC_PROCESS_TASK_PROVIDER_H _ | 5 #ifndef CHROME_BROWSER_TASK_MANAGEMENT_PROVIDERS_ARC_ARC_PROCESS_TASK_PROVIDER_H _ |
6 #define CHROME_BROWSER_TASK_MANAGEMENT_PROVIDERS_ARC_ARC_PROCESS_TASK_PROVIDER_H _ | 6 #define CHROME_BROWSER_TASK_MANAGEMENT_PROVIDERS_ARC_ARC_PROCESS_TASK_PROVIDER_H _ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 #include <set> | 10 #include <set> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/callback.h" | |
14 #include "base/macros.h" | 15 #include "base/macros.h" |
15 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
16 #include "base/process/process.h" | 17 #include "base/process/process.h" |
17 #include "chrome/browser/chromeos/arc/arc_process.h" | 18 #include "chrome/browser/chromeos/arc/arc_process.h" |
18 #include "chrome/browser/task_management/providers/arc/arc_process_task.h" | 19 #include "chrome/browser/task_management/providers/arc/arc_process_task.h" |
19 #include "chrome/browser/task_management/providers/task_provider.h" | 20 #include "chrome/browser/task_management/providers/task_provider.h" |
20 | 21 |
21 namespace task_management { | 22 namespace task_management { |
22 | 23 |
23 // This provides the ARC process tasks. | 24 // This provides the ARC process tasks. |
24 // | 25 // |
25 // Since this provider obtains ARC process information via IPC and procfs, | 26 // 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 | 27 // 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 | 28 // 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, | 29 // 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 | 30 // 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 | 31 // the user did not intend to choose is killed. Since apps are designed |
31 // to be killed at any time, it sounds acceptable. | 32 // to be killed at any time, it sounds acceptable. |
32 class ArcProcessTaskProvider : public TaskProvider { | 33 class ArcProcessTaskProvider : public TaskProvider { |
33 public: | 34 public: |
34 ArcProcessTaskProvider(); | 35 ArcProcessTaskProvider(); |
35 ~ArcProcessTaskProvider() override; | 36 ~ArcProcessTaskProvider() override; |
36 | 37 |
37 // task_management::TaskProvider: | 38 // task_management::TaskProvider: |
38 Task* GetTaskOfUrlRequest(int origin_pid, | 39 Task* GetTaskOfUrlRequest(int origin_pid, |
39 int child_id, | 40 int child_id, |
40 int route_id) override; | 41 int route_id) override; |
41 | 42 |
42 private: | 43 private: |
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( |
51 std::map<base::ProcessId, std::unique_ptr<ArcProcessTask>>& pid_to_task, | |
52 const std::vector<arc::ArcProcess>& processes); | |
53 void OnUpdateProcessList( | |
54 std::map<base::ProcessId, std::unique_ptr<ArcProcessTask>>& pid_to_task, | |
55 const std::vector<arc::ArcProcess>& processes, | |
56 const base::Closure& scheduler); | |
57 void OnUpdateAppProcessList(const std::vector<arc::ArcProcess>& processes); | |
58 void OnUpdateSystemProcessList(const std::vector<arc::ArcProcess>& processes); | |
47 | 59 |
48 // task_management::TaskProvider: | 60 // task_management::TaskProvider: |
49 void StartUpdating() override; | 61 void StartUpdating() override; |
50 void StopUpdating() override; | 62 void StopUpdating() override; |
51 | 63 |
52 void ScheduleNextRequest(); | 64 void ScheduleNextAppRequest(); |
65 void ScheduleNextSystemRequest(); | |
53 | 66 |
54 std::map<base::ProcessId, std::unique_ptr<ArcProcessTask>> nspid_to_task_; | 67 std::map<base::ProcessId, std::unique_ptr<ArcProcessTask>> nspid_to_task_; |
Luis Héctor Chávez
2016/07/15 16:19:42
Can these two be std::unordered_map?
Hsu-Cheng
2016/07/27 08:08:00
Done.
| |
68 std::map<base::ProcessId, std::unique_ptr<ArcProcessTask>> nspid_to_sys_task_; | |
55 | 69 |
56 // Whether to continue the periodical polling. | 70 // Whether to continue the periodical polling. |
57 bool is_updating_; | 71 bool is_updating_; |
58 | 72 |
59 // Always keep this the last member of this class to make sure it's the | 73 // Always keep this the last member of this class to make sure it's the |
60 // first thing to be destructed. | 74 // first thing to be destructed. |
61 base::WeakPtrFactory<ArcProcessTaskProvider> weak_ptr_factory_; | 75 base::WeakPtrFactory<ArcProcessTaskProvider> weak_ptr_factory_; |
62 | 76 |
63 DISALLOW_COPY_AND_ASSIGN(ArcProcessTaskProvider); | 77 DISALLOW_COPY_AND_ASSIGN(ArcProcessTaskProvider); |
64 }; | 78 }; |
65 | 79 |
66 } // namespace task_management | 80 } // namespace task_management |
67 | 81 |
68 #endif // CHROME_BROWSER_TASK_MANAGEMENT_PROVIDERS_ARC_ARC_PROCESS_TASK_PROVIDE R_H_ | 82 #endif // CHROME_BROWSER_TASK_MANAGEMENT_PROVIDERS_ARC_ARC_PROCESS_TASK_PROVIDE R_H_ |
OLD | NEW |