| 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_SAMPLING_TASK_MANAGER_IMPL_H_ | 5 #ifndef CHROME_BROWSER_TASK_MANAGER_SAMPLING_TASK_MANAGER_IMPL_H_ |
| 6 #define CHROME_BROWSER_TASK_MANAGER_SAMPLING_TASK_MANAGER_IMPL_H_ | 6 #define CHROME_BROWSER_TASK_MANAGER_SAMPLING_TASK_MANAGER_IMPL_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <map> | 11 #include <map> |
| 12 #include <memory> | 12 #include <memory> |
| 13 #include <string> | 13 #include <string> |
| 14 #include <vector> | 14 #include <vector> |
| 15 | 15 |
| 16 #include "base/lazy_instance.h" | 16 #include "base/lazy_instance.h" |
| 17 #include "base/macros.h" | 17 #include "base/macros.h" |
| 18 #include "base/memory/weak_ptr.h" |
| 18 #include "base/sequenced_task_runner.h" | 19 #include "base/sequenced_task_runner.h" |
| 19 #include "base/time/time.h" | 20 #include "base/time/time.h" |
| 20 #include "chrome/browser/task_manager/providers/task_provider.h" | 21 #include "chrome/browser/task_manager/providers/task_provider.h" |
| 21 #include "chrome/browser/task_manager/providers/task_provider_observer.h" | 22 #include "chrome/browser/task_manager/providers/task_provider_observer.h" |
| 22 #include "chrome/browser/task_manager/sampling/task_group.h" | 23 #include "chrome/browser/task_manager/sampling/task_group.h" |
| 23 #include "chrome/browser/task_manager/sampling/task_manager_io_thread_helper.h" | 24 #include "chrome/browser/task_manager/sampling/task_manager_io_thread_helper.h" |
| 24 #include "chrome/browser/task_manager/task_manager_interface.h" | 25 #include "chrome/browser/task_manager/task_manager_interface.h" |
| 25 #include "content/public/browser/gpu_data_manager_observer.h" | |
| 26 #include "gpu/ipc/common/memory_stats.h" | 26 #include "gpu/ipc/common/memory_stats.h" |
| 27 | 27 |
| 28 namespace task_manager { | 28 namespace task_manager { |
| 29 | 29 |
| 30 class SharedSampler; | 30 class SharedSampler; |
| 31 | 31 |
| 32 // Defines a concrete implementation of the TaskManagerInterface. | 32 // Defines a concrete implementation of the TaskManagerInterface. |
| 33 class TaskManagerImpl : | 33 class TaskManagerImpl : public TaskManagerInterface, |
| 34 public TaskManagerInterface, | 34 public TaskProviderObserver { |
| 35 public TaskProviderObserver, | |
| 36 content::GpuDataManagerObserver { | |
| 37 public: | 35 public: |
| 38 ~TaskManagerImpl() override; | 36 ~TaskManagerImpl() override; |
| 39 | 37 |
| 40 static TaskManagerImpl* GetInstance(); | 38 static TaskManagerImpl* GetInstance(); |
| 41 | 39 |
| 42 // task_manager::TaskManagerInterface: | 40 // task_manager::TaskManagerInterface: |
| 43 void ActivateTask(TaskId task_id) override; | 41 void ActivateTask(TaskId task_id) override; |
| 44 bool IsTaskKillable(TaskId task_id) override; | 42 bool IsTaskKillable(TaskId task_id) override; |
| 45 void KillTask(TaskId task_id) override; | 43 void KillTask(TaskId task_id) override; |
| 46 double GetCpuUsage(TaskId task_id) const override; | 44 double GetCpuUsage(TaskId task_id) const override; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 TaskIdList GetIdsOfTasksSharingSameProcess(TaskId task_id) const override; | 87 TaskIdList GetIdsOfTasksSharingSameProcess(TaskId task_id) const override; |
| 90 size_t GetNumberOfTasksOnSameProcess(TaskId task_id) const override; | 88 size_t GetNumberOfTasksOnSameProcess(TaskId task_id) const override; |
| 91 TaskId GetTaskIdForWebContents( | 89 TaskId GetTaskIdForWebContents( |
| 92 content::WebContents* web_contents) const override; | 90 content::WebContents* web_contents) const override; |
| 93 | 91 |
| 94 // task_manager::TaskProviderObserver: | 92 // task_manager::TaskProviderObserver: |
| 95 void TaskAdded(Task* task) override; | 93 void TaskAdded(Task* task) override; |
| 96 void TaskRemoved(Task* task) override; | 94 void TaskRemoved(Task* task) override; |
| 97 void TaskUnresponsive(Task* task) override; | 95 void TaskUnresponsive(Task* task) override; |
| 98 | 96 |
| 99 // content::GpuDataManagerObserver: | |
| 100 void OnVideoMemoryUsageStatsUpdate( | |
| 101 const gpu::VideoMemoryUsageStats& gpu_memory_stats) override; | |
| 102 | |
| 103 // The notification method on the UI thread when multiple bytes are read | 97 // The notification method on the UI thread when multiple bytes are read |
| 104 // from URLRequests. This will be called by the |io_thread_helper_| | 98 // from URLRequests. This will be called by the |io_thread_helper_| |
| 105 static void OnMultipleBytesReadUI(std::vector<BytesReadParam>* params); | 99 static void OnMultipleBytesReadUI(std::vector<BytesReadParam>* params); |
| 106 | 100 |
| 107 private: | 101 private: |
| 108 friend struct base::LazyInstanceTraitsBase<TaskManagerImpl>; | 102 friend struct base::LazyInstanceTraitsBase<TaskManagerImpl>; |
| 109 | 103 |
| 110 TaskManagerImpl(); | 104 TaskManagerImpl(); |
| 111 | 105 |
| 106 void OnVideoMemoryUsageStatsUpdate( |
| 107 const gpu::VideoMemoryUsageStats& gpu_memory_stats); |
| 108 |
| 112 // task_manager::TaskManagerInterface: | 109 // task_manager::TaskManagerInterface: |
| 113 void Refresh() override; | 110 void Refresh() override; |
| 114 void StartUpdating() override; | 111 void StartUpdating() override; |
| 115 void StopUpdating() override; | 112 void StopUpdating() override; |
| 116 | 113 |
| 117 // Lookup a task by its pid, child_id and possibly route_id. | 114 // Lookup a task by its pid, child_id and possibly route_id. |
| 118 Task* GetTaskByPidOrRoute(int pid, int child_id, int route_id) const; | 115 Task* GetTaskByPidOrRoute(int pid, int child_id, int route_id) const; |
| 119 | 116 |
| 120 // Based on |param| the appropriate task will be updated by its network usage. | 117 // Based on |param| the appropriate task will be updated by its network usage. |
| 121 // Returns true if it was able to match |param| to an existing task, returns | 118 // Returns true if it was able to match |param| to an existing task, returns |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 scoped_refptr<base::SequencedTaskRunner> blocking_pool_runner_; | 159 scoped_refptr<base::SequencedTaskRunner> blocking_pool_runner_; |
| 163 | 160 |
| 164 // A special sampler shared with all instances of TaskGroup that calculates a | 161 // A special sampler shared with all instances of TaskGroup that calculates a |
| 165 // subset of resources for all processes at once. | 162 // subset of resources for all processes at once. |
| 166 scoped_refptr<SharedSampler> shared_sampler_; | 163 scoped_refptr<SharedSampler> shared_sampler_; |
| 167 | 164 |
| 168 // This will be set to true while there are observers and the task manager is | 165 // This will be set to true while there are observers and the task manager is |
| 169 // running. | 166 // running. |
| 170 bool is_running_; | 167 bool is_running_; |
| 171 | 168 |
| 169 base::WeakPtrFactory<TaskManagerImpl> weak_ptr_factory_; |
| 172 DISALLOW_COPY_AND_ASSIGN(TaskManagerImpl); | 170 DISALLOW_COPY_AND_ASSIGN(TaskManagerImpl); |
| 173 }; | 171 }; |
| 174 | 172 |
| 175 } // namespace task_manager | 173 } // namespace task_manager |
| 176 | 174 |
| 177 #endif // CHROME_BROWSER_TASK_MANAGER_SAMPLING_TASK_MANAGER_IMPL_H_ | 175 #endif // CHROME_BROWSER_TASK_MANAGER_SAMPLING_TASK_MANAGER_IMPL_H_ |
| OLD | NEW |