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 #include "chrome/browser/task_manager/providers/task.h" | 5 #include "chrome/browser/task_manager/providers/task.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/process/process.h" | 9 #include "base/process/process.h" |
10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 int64_t g_last_id = 0; | 23 int64_t g_last_id = 0; |
24 | 24 |
25 } // namespace | 25 } // namespace |
26 | 26 |
27 Task::Task(const base::string16& title, | 27 Task::Task(const base::string16& title, |
28 const std::string& rappor_sample, | 28 const std::string& rappor_sample, |
29 const gfx::ImageSkia* icon, | 29 const gfx::ImageSkia* icon, |
30 base::ProcessHandle handle, | 30 base::ProcessHandle handle, |
31 base::ProcessId process_id) | 31 base::ProcessId process_id) |
32 : task_id_(g_last_id++), | 32 : task_id_(g_last_id++), |
33 network_usage_(-1), | 33 last_refresh_cumulative_bytes_sent_(0), |
34 current_byte_count_(-1), | 34 last_refresh_cumulative_bytes_read_(0), |
| 35 cumulative_bytes_sent_(0), |
| 36 cumulative_bytes_read_(0), |
| 37 network_sent_rate_(0), |
| 38 network_read_rate_(0), |
35 title_(title), | 39 title_(title), |
36 rappor_sample_name_(rappor_sample), | 40 rappor_sample_name_(rappor_sample), |
37 icon_(icon ? *icon : gfx::ImageSkia()), | 41 icon_(icon ? *icon : gfx::ImageSkia()), |
38 process_handle_(handle), | 42 process_handle_(handle), |
39 process_id_(process_id != base::kNullProcessId | 43 process_id_(process_id != base::kNullProcessId |
40 ? process_id | 44 ? process_id |
41 : base::GetProcId(handle)) {} | 45 : base::GetProcId(handle)) {} |
42 | 46 |
43 Task::~Task() {} | 47 Task::~Task() {} |
44 | 48 |
(...skipping 18 matching lines...) Expand all Loading... |
63 } | 67 } |
64 | 68 |
65 void Task::Kill() { | 69 void Task::Kill() { |
66 DCHECK_NE(process_id(), base::GetCurrentProcId()); | 70 DCHECK_NE(process_id(), base::GetCurrentProcId()); |
67 base::Process process = base::Process::Open(process_id()); | 71 base::Process process = base::Process::Open(process_id()); |
68 process.Terminate(content::RESULT_CODE_KILLED, false); | 72 process.Terminate(content::RESULT_CODE_KILLED, false); |
69 } | 73 } |
70 | 74 |
71 void Task::Refresh(const base::TimeDelta& update_interval, | 75 void Task::Refresh(const base::TimeDelta& update_interval, |
72 int64_t refresh_flags) { | 76 int64_t refresh_flags) { |
73 if ((refresh_flags & REFRESH_TYPE_NETWORK_USAGE) == 0) | 77 if ((refresh_flags & REFRESH_TYPE_NETWORK_USAGE) == 0 || |
| 78 update_interval == base::TimeDelta()) |
74 return; | 79 return; |
75 | 80 |
76 if (current_byte_count_ == -1) | 81 int64_t current_cycle_read_byte_count = |
77 return; | 82 cumulative_bytes_read_ - last_refresh_cumulative_bytes_read_; |
| 83 network_read_rate_ = |
| 84 (current_cycle_read_byte_count * base::TimeDelta::FromSeconds(1)) / |
| 85 update_interval; |
78 | 86 |
79 network_usage_ = | 87 int64_t current_cycle_sent_byte_count = |
80 (current_byte_count_ * base::TimeDelta::FromSeconds(1)) / update_interval; | 88 cumulative_bytes_sent_ - last_refresh_cumulative_bytes_sent_; |
| 89 network_sent_rate_ = |
| 90 (current_cycle_sent_byte_count * base::TimeDelta::FromSeconds(1)) / |
| 91 update_interval; |
81 | 92 |
82 // Reset the current byte count for this task. | 93 last_refresh_cumulative_bytes_read_ = cumulative_bytes_read_; |
83 current_byte_count_ = 0; | 94 last_refresh_cumulative_bytes_sent_ = cumulative_bytes_sent_; |
84 } | 95 } |
85 | 96 |
86 void Task::OnNetworkBytesRead(int64_t bytes_read) { | 97 void Task::OnNetworkBytesRead(int64_t bytes_read) { |
87 if (current_byte_count_ == -1) | 98 cumulative_bytes_read_ += bytes_read; |
88 current_byte_count_ = 0; | 99 } |
89 | 100 |
90 current_byte_count_ += bytes_read; | 101 void Task::OnNetworkBytesSent(int64_t bytes_sent) { |
| 102 cumulative_bytes_sent_ += bytes_sent; |
91 } | 103 } |
92 | 104 |
93 void Task::GetTerminationStatus(base::TerminationStatus* out_status, | 105 void Task::GetTerminationStatus(base::TerminationStatus* out_status, |
94 int* out_error_code) const { | 106 int* out_error_code) const { |
95 DCHECK(out_status); | 107 DCHECK(out_status); |
96 DCHECK(out_error_code); | 108 DCHECK(out_error_code); |
97 | 109 |
98 *out_status = base::TERMINATION_STATUS_STILL_RUNNING; | 110 *out_status = base::TERMINATION_STATUS_STILL_RUNNING; |
99 *out_error_code = 0; | 111 *out_error_code = 0; |
100 } | 112 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 } | 152 } |
141 | 153 |
142 blink::WebCache::ResourceTypeStats Task::GetWebCacheStats() const { | 154 blink::WebCache::ResourceTypeStats Task::GetWebCacheStats() const { |
143 return blink::WebCache::ResourceTypeStats(); | 155 return blink::WebCache::ResourceTypeStats(); |
144 } | 156 } |
145 | 157 |
146 int Task::GetKeepaliveCount() const { | 158 int Task::GetKeepaliveCount() const { |
147 return -1; | 159 return -1; |
148 } | 160 } |
149 | 161 |
150 bool Task::ReportsNetworkUsage() const { | |
151 return network_usage_ != -1; | |
152 } | |
153 | |
154 } // namespace task_manager | 162 } // namespace task_manager |
OLD | NEW |