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 13 matching lines...) Expand all Loading... |
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 network_usage_(-1), |
34 current_byte_count_(-1), | 34 total_network_usage_(0), |
| 35 network_read_usage_(-1), |
| 36 network_sent_usage_(-1), |
| 37 current_read_byte_count_(-1), |
| 38 current_sent_byte_count_(-1), |
| 39 total_read_byte_count_(0), |
| 40 total_sent_byte_count_(0), |
35 title_(title), | 41 title_(title), |
36 rappor_sample_name_(rappor_sample), | 42 rappor_sample_name_(rappor_sample), |
37 icon_(icon ? *icon : gfx::ImageSkia()), | 43 icon_(icon ? *icon : gfx::ImageSkia()), |
38 process_handle_(handle), | 44 process_handle_(handle), |
39 process_id_(process_id != base::kNullProcessId | 45 process_id_(process_id != base::kNullProcessId |
40 ? process_id | 46 ? process_id |
41 : base::GetProcId(handle)) {} | 47 : base::GetProcId(handle)) {} |
42 | 48 |
43 Task::~Task() {} | 49 Task::~Task() {} |
44 | 50 |
(...skipping 21 matching lines...) Expand all Loading... |
66 DCHECK_NE(process_id(), base::GetCurrentProcId()); | 72 DCHECK_NE(process_id(), base::GetCurrentProcId()); |
67 base::Process process = base::Process::Open(process_id()); | 73 base::Process process = base::Process::Open(process_id()); |
68 process.Terminate(content::RESULT_CODE_KILLED, false); | 74 process.Terminate(content::RESULT_CODE_KILLED, false); |
69 } | 75 } |
70 | 76 |
71 void Task::Refresh(const base::TimeDelta& update_interval, | 77 void Task::Refresh(const base::TimeDelta& update_interval, |
72 int64_t refresh_flags) { | 78 int64_t refresh_flags) { |
73 if ((refresh_flags & REFRESH_TYPE_NETWORK_USAGE) == 0) | 79 if ((refresh_flags & REFRESH_TYPE_NETWORK_USAGE) == 0) |
74 return; | 80 return; |
75 | 81 |
76 if (current_byte_count_ == -1) | 82 if (current_read_byte_count_ == -1 && current_sent_byte_count_ == -1) |
77 return; | 83 return; |
78 | 84 |
79 network_usage_ = | 85 if (current_read_byte_count_ == -1) { |
80 (current_byte_count_ * base::TimeDelta::FromSeconds(1)) / update_interval; | 86 network_read_usage_ = 0; |
| 87 } else { |
| 88 network_read_usage_ = |
| 89 (current_read_byte_count_ * base::TimeDelta::FromSeconds(1)) / |
| 90 update_interval; |
| 91 } |
| 92 |
| 93 if (current_sent_byte_count_ == -1) { |
| 94 network_sent_usage_ = 0; |
| 95 } else { |
| 96 network_sent_usage_ = |
| 97 (current_sent_byte_count_ * base::TimeDelta::FromSeconds(1)) / |
| 98 update_interval; |
| 99 } |
| 100 |
| 101 network_usage_ = network_read_usage_ + network_sent_usage_; |
| 102 |
| 103 total_read_byte_count_ += |
| 104 current_read_byte_count_ == -1 ? 0 : current_read_byte_count_; |
| 105 total_sent_byte_count_ += |
| 106 current_sent_byte_count_ == -1 ? 0 : current_sent_byte_count_; |
81 | 107 |
82 // Reset the current byte count for this task. | 108 // Reset the current byte count for this task. |
83 current_byte_count_ = 0; | 109 current_read_byte_count_ = 0; |
| 110 current_sent_byte_count_ = 0; |
| 111 |
| 112 // Since this isn't getting a rate and is just summing all network use |
| 113 total_network_usage_ = total_read_byte_count_ + total_sent_byte_count_; |
84 } | 114 } |
85 | 115 |
86 void Task::OnNetworkBytesRead(int64_t bytes_read) { | 116 void Task::OnNetworkBytesRead(int64_t bytes_read) { |
87 if (current_byte_count_ == -1) | 117 if (current_read_byte_count_ == -1) { |
88 current_byte_count_ = 0; | 118 current_read_byte_count_ = 0; |
| 119 total_read_byte_count_ = 0; |
| 120 } |
89 | 121 |
90 current_byte_count_ += bytes_read; | 122 current_read_byte_count_ += bytes_read; |
| 123 } |
| 124 |
| 125 void Task::OnNetworkBytesSent(int64_t bytes_sent) { |
| 126 if (current_sent_byte_count_ == -1) { |
| 127 current_sent_byte_count_ = 0; |
| 128 total_sent_byte_count_ = 0; |
| 129 } |
| 130 |
| 131 current_sent_byte_count_ += bytes_sent; |
91 } | 132 } |
92 | 133 |
93 void Task::GetTerminationStatus(base::TerminationStatus* out_status, | 134 void Task::GetTerminationStatus(base::TerminationStatus* out_status, |
94 int* out_error_code) const { | 135 int* out_error_code) const { |
95 DCHECK(out_status); | 136 DCHECK(out_status); |
96 DCHECK(out_error_code); | 137 DCHECK(out_error_code); |
97 | 138 |
98 *out_status = base::TERMINATION_STATUS_STILL_RUNNING; | 139 *out_status = base::TERMINATION_STATUS_STILL_RUNNING; |
99 *out_error_code = 0; | 140 *out_error_code = 0; |
100 } | 141 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 | 186 |
146 int Task::GetKeepaliveCount() const { | 187 int Task::GetKeepaliveCount() const { |
147 return -1; | 188 return -1; |
148 } | 189 } |
149 | 190 |
150 bool Task::ReportsNetworkUsage() const { | 191 bool Task::ReportsNetworkUsage() const { |
151 return network_usage_ != -1; | 192 return network_usage_ != -1; |
152 } | 193 } |
153 | 194 |
154 } // namespace task_manager | 195 } // namespace task_manager |
OLD | NEW |