| 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 <set> | 9 #include <set> |
| 10 #include <string> | |
| 11 #include <vector> | 10 #include <vector> |
| 12 | 11 |
| 13 #include "base/macros.h" | 12 #include "base/macros.h" |
| 14 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 16 #include "base/timer/timer.h" | 15 #include "base/timer/timer.h" |
| 17 #include "chrome/browser/task_management/providers/arc/arc_process_task.h" | 16 #include "chrome/browser/task_management/providers/arc/arc_process_task.h" |
| 18 #include "chrome/browser/task_management/providers/task_provider.h" | 17 #include "chrome/browser/task_management/providers/task_provider.h" |
| 19 #include "components/arc/arc_bridge_service.h" | 18 #include "components/arc/arc_bridge_service.h" |
| 20 | 19 |
| 21 namespace base { | 20 namespace base { |
| 22 class Timer; | 21 class Timer; |
| 23 } // namespace base | 22 } // namespace base |
| 24 | 23 |
| 25 namespace task_management { | 24 namespace task_management { |
| 26 | 25 |
| 27 // This provides the ARC process tasks. | 26 // This provides the ARC process tasks. |
| 28 // | 27 // |
| 29 // Since this provider obtains ARC process information via IPC and procfs, | 28 // Since this provider obtains ARC process information via IPC and procfs, |
| 30 // it can never avoid race conditions. For example, in an extreme case such as | 29 // it can never avoid race conditions. For example, in an extreme case such as |
| 31 // fork(2) is called millions of times in a second, this provider can return | 30 // fork(2) is called millions of times in a second, this provider can return |
| 32 // wrong results. However, its chance is very low, and even if we hit the case, | 31 // wrong results. However, its chance is very low, and even if we hit the case, |
| 33 // the worst outcome is just that an Android app (non-system) process which | 32 // the worst outcome is just that an Android app (non-system) process which |
| 34 // the user did not intend to choose is killed. Since Android apps are designed | 33 // the user did not intend to choose is killed. Since Android apps are designed |
| 35 // to be killed at any time, it sounds acceptable. | 34 // to be killed at any time, it sounds acceptable. |
| 36 class ArcProcessTaskProvider : public TaskProvider { | 35 class ArcProcessTaskProvider : public TaskProvider, |
| 36 public arc::ArcBridgeService::ProcessObserver { |
| 37 public: | 37 public: |
| 38 ArcProcessTaskProvider(); | 38 ArcProcessTaskProvider(); |
| 39 ~ArcProcessTaskProvider() override; | 39 ~ArcProcessTaskProvider() override; |
| 40 | 40 |
| 41 // task_management::TaskProvider: | 41 // task_management::TaskProvider: |
| 42 Task* GetTaskOfUrlRequest(int origin_pid, | 42 Task* GetTaskOfUrlRequest(int origin_pid, |
| 43 int child_id, | 43 int child_id, |
| 44 int route_id) override; | 44 int route_id) override; |
| 45 | 45 |
| 46 // arc::ArcBridgeService::ProcessObserver: |
| 47 void OnUpdateProcessList( |
| 48 const std::vector<arc::RunningAppProcessInfo>& processes) override; |
| 49 |
| 46 private: | 50 private: |
| 47 void RequestProcessList(); | 51 void RequestProcessList(); |
| 48 void OnUpdateProcessList( | |
| 49 mojo::Array<arc::RunningAppProcessInfoPtr> processes); | |
| 50 | 52 |
| 51 void RemoveTasks(const std::set<base::ProcessId>& removed_nspids); | 53 void RemoveTasks(const std::set<base::ProcessId>& removed_nspids); |
| 52 void AddTasks(const std::vector<arc::RunningAppProcessInfo>& added_processes, | 54 void AddTasks(const std::vector<arc::RunningAppProcessInfo>& added_processes, |
| 53 const std::map<base::ProcessId, base::ProcessId>& nspid_to_pid); | 55 const std::map<base::ProcessId, base::ProcessId>& nspid_to_pid); |
| 54 | 56 |
| 55 // task_management::TaskProvider: | 57 // task_management::TaskProvider: |
| 56 void StartUpdating() override; | 58 void StartUpdating() override; |
| 57 void StopUpdating() override; | 59 void StopUpdating() override; |
| 58 | 60 |
| 59 std::map<base::ProcessId, scoped_ptr<ArcProcessTask> > nspid_to_task_; | 61 std::map<base::ProcessId, scoped_ptr<ArcProcessTask> > nspid_to_task_; |
| 60 base::RepeatingTimer timer_; | 62 base::RepeatingTimer timer_; |
| 61 | 63 |
| 62 // Always keep this the last member of this class to make sure it's the | 64 // Always keep this the last member of this class to make sure it's the |
| 63 // first thing to be destructed. | 65 // first thing to be destructed. |
| 64 base::WeakPtrFactory<ArcProcessTaskProvider> weak_ptr_factory_; | 66 base::WeakPtrFactory<ArcProcessTaskProvider> weak_ptr_factory_; |
| 65 | 67 |
| 66 DISALLOW_COPY_AND_ASSIGN(ArcProcessTaskProvider); | 68 DISALLOW_COPY_AND_ASSIGN(ArcProcessTaskProvider); |
| 67 }; | 69 }; |
| 68 | 70 |
| 69 } // namespace task_management | 71 } // namespace task_management |
| 70 | 72 |
| 71 #endif // CHROME_BROWSER_TASK_MANAGEMENT_PROVIDERS_ARC_ARC_PROCESS_TASK_PROVIDE
R_H_ | 73 #endif // CHROME_BROWSER_TASK_MANAGEMENT_PROVIDERS_ARC_ARC_PROCESS_TASK_PROVIDE
R_H_ |
| OLD | NEW |