OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/task_manager.h" | 5 #include "chrome/browser/task_manager/task_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/i18n/number_formatting.h" | 8 #include "base/i18n/number_formatting.h" |
9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
10 #include "base/prefs/pref_registry_simple.h" | 10 #include "base/prefs/pref_registry_simple.h" |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 | 234 |
235 //////////////////////////////////////////////////////////////////////////////// | 235 //////////////////////////////////////////////////////////////////////////////// |
236 // TaskManagerModel class | 236 // TaskManagerModel class |
237 //////////////////////////////////////////////////////////////////////////////// | 237 //////////////////////////////////////////////////////////////////////////////// |
238 | 238 |
239 TaskManagerModel::TaskManagerModel(TaskManager* task_manager) | 239 TaskManagerModel::TaskManagerModel(TaskManager* task_manager) |
240 : pending_video_memory_usage_stats_update_(false), | 240 : pending_video_memory_usage_stats_update_(false), |
241 update_requests_(0), | 241 update_requests_(0), |
242 listen_requests_(0), | 242 listen_requests_(0), |
243 update_state_(IDLE), | 243 update_state_(IDLE), |
244 is_updating_byte_count_(false), | |
244 goat_salt_(base::RandUint64()) { | 245 goat_salt_(base::RandUint64()) { |
245 AddResourceProvider( | 246 AddResourceProvider( |
246 new task_manager::BrowserProcessResourceProvider(task_manager)); | 247 new task_manager::BrowserProcessResourceProvider(task_manager)); |
247 AddResourceProvider(new task_manager::WebContentsResourceProvider( | 248 AddResourceProvider(new task_manager::WebContentsResourceProvider( |
248 task_manager, | 249 task_manager, |
249 scoped_ptr<WebContentsInformation>( | 250 scoped_ptr<WebContentsInformation>( |
250 new task_manager::BackgroundInformation()))); | 251 new task_manager::BackgroundInformation()))); |
251 AddResourceProvider(new task_manager::WebContentsResourceProvider( | 252 AddResourceProvider(new task_manager::WebContentsResourceProvider( |
252 task_manager, | 253 task_manager, |
253 scoped_ptr<WebContentsInformation>( | 254 scoped_ptr<WebContentsInformation>( |
(...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1048 } | 1049 } |
1049 update_state_ = TASK_PENDING; | 1050 update_state_ = TASK_PENDING; |
1050 | 1051 |
1051 // Notify resource providers that we are updating. | 1052 // Notify resource providers that we are updating. |
1052 StartListening(); | 1053 StartListening(); |
1053 | 1054 |
1054 if (!resources_.empty()) { | 1055 if (!resources_.empty()) { |
1055 FOR_EACH_OBSERVER(TaskManagerModelObserver, observer_list_, | 1056 FOR_EACH_OBSERVER(TaskManagerModelObserver, observer_list_, |
1056 OnReadyPeriodicalUpdate()); | 1057 OnReadyPeriodicalUpdate()); |
1057 } | 1058 } |
1059 | |
1060 BrowserThread::PostTask( | |
1061 BrowserThread::IO, FROM_HERE, | |
1062 base::Bind(&TaskManagerModel::StartUpdatingByteCount, this)); | |
1058 } | 1063 } |
1059 | 1064 |
1060 void TaskManagerModel::StopUpdating() { | 1065 void TaskManagerModel::StopUpdating() { |
1061 // Don't actually stop updating until we have heard as many calls as those | 1066 // Don't actually stop updating until we have heard as many calls as those |
1062 // to StartUpdating. | 1067 // to StartUpdating. |
1063 update_requests_--; | 1068 update_requests_--; |
1064 if (update_requests_ > 0) | 1069 if (update_requests_ > 0) |
1065 return; | 1070 return; |
1066 // Make sure that update_requests_ cannot go negative. | 1071 // Make sure that update_requests_ cannot go negative. |
1067 CHECK_EQ(0, update_requests_); | 1072 CHECK_EQ(0, update_requests_); |
1068 DCHECK_EQ(TASK_PENDING, update_state_); | 1073 DCHECK_EQ(TASK_PENDING, update_state_); |
1069 update_state_ = STOPPING; | 1074 update_state_ = STOPPING; |
1070 | 1075 |
1071 // Notify resource providers that we are done updating. | 1076 // Notify resource providers that we are done updating. |
1072 StopListening(); | 1077 StopListening(); |
1078 | |
1079 BrowserThread::PostTask( | |
1080 BrowserThread::IO, FROM_HERE, | |
1081 base::Bind(&TaskManagerModel::StopUpdatingByteCount, this)); | |
1073 } | 1082 } |
1074 | 1083 |
1075 void TaskManagerModel::StartListening() { | 1084 void TaskManagerModel::StartListening() { |
1076 // Multiple StartListening requests may come in and we only need to take | 1085 // Multiple StartListening requests may come in and we only need to take |
1077 // action the first time. | 1086 // action the first time. |
1078 listen_requests_++; | 1087 listen_requests_++; |
1079 if (listen_requests_ > 1) | 1088 if (listen_requests_ > 1) |
1080 return; | 1089 return; |
1081 DCHECK_EQ(1, listen_requests_); | 1090 DCHECK_EQ(1, listen_requests_); |
1082 | 1091 |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1237 it != resources_.end(); ++it) { | 1246 it != resources_.end(); ++it) { |
1238 if (base::GetProcId((*it)->GetProcess()) == renderer_id) { | 1247 if (base::GetProcId((*it)->GetProcess()) == renderer_id) { |
1239 (*it)->NotifyV8HeapStats(v8_memory_allocated, v8_memory_used); | 1248 (*it)->NotifyV8HeapStats(v8_memory_allocated, v8_memory_used); |
1240 } | 1249 } |
1241 } | 1250 } |
1242 } | 1251 } |
1243 | 1252 |
1244 void TaskManagerModel::NotifyBytesRead(const net::URLRequest& request, | 1253 void TaskManagerModel::NotifyBytesRead(const net::URLRequest& request, |
1245 int byte_count) { | 1254 int byte_count) { |
1246 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1255 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
1256 if (!is_updating_byte_count_) { | |
Lei Zhang
2014/09/06 06:17:46
nit: no need for braces
tonyg
2014/09/08 18:59:38
Done.
| |
1257 return; | |
1258 } | |
1247 | 1259 |
1248 // Only net::URLRequestJob instances created by the ResourceDispatcherHost | 1260 // Only net::URLRequestJob instances created by the ResourceDispatcherHost |
1249 // have an associated ResourceRequestInfo and a render frame associated. | 1261 // have an associated ResourceRequestInfo and a render frame associated. |
1250 // All other jobs will have -1 returned for the render process child and | 1262 // All other jobs will have -1 returned for the render process child and |
1251 // routing ids - the jobs may still match a resource based on their origin id, | 1263 // routing ids - the jobs may still match a resource based on their origin id, |
1252 // otherwise BytesRead() will attribute the activity to the Browser resource. | 1264 // otherwise BytesRead() will attribute the activity to the Browser resource. |
1253 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(&request); | 1265 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(&request); |
1254 int child_id = -1, route_id = -1; | 1266 int child_id = -1, route_id = -1; |
1255 if (info) | 1267 if (info) |
1256 info->GetAssociatedRenderFrame(&child_id, &route_id); | 1268 info->GetAssociatedRenderFrame(&child_id, &route_id); |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1386 | 1398 |
1387 std::vector<BytesReadParam>* bytes_read_buffer = | 1399 std::vector<BytesReadParam>* bytes_read_buffer = |
1388 new std::vector<BytesReadParam>; | 1400 new std::vector<BytesReadParam>; |
1389 bytes_read_buffer_.swap(*bytes_read_buffer); | 1401 bytes_read_buffer_.swap(*bytes_read_buffer); |
1390 BrowserThread::PostTask( | 1402 BrowserThread::PostTask( |
1391 BrowserThread::UI, FROM_HERE, | 1403 BrowserThread::UI, FROM_HERE, |
1392 base::Bind(&TaskManagerModel::MultipleBytesRead, this, | 1404 base::Bind(&TaskManagerModel::MultipleBytesRead, this, |
1393 base::Owned(bytes_read_buffer))); | 1405 base::Owned(bytes_read_buffer))); |
1394 } | 1406 } |
1395 | 1407 |
1408 void TaskManagerModel::StartUpdatingByteCount() { | |
Lei Zhang
2014/09/06 06:17:47
maybe combine into SetUpdatingByteCount(bool is_up
tonyg
2014/09/08 18:59:38
Done.
| |
1409 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
1410 is_updating_byte_count_ = true; | |
1411 } | |
1412 | |
1413 void TaskManagerModel::StopUpdatingByteCount() { | |
1414 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
1415 is_updating_byte_count_ = false; | |
1416 } | |
1417 | |
1396 int64 TaskManagerModel::GetNetworkUsage(Resource* resource) const { | 1418 int64 TaskManagerModel::GetNetworkUsage(Resource* resource) const { |
1397 int64 net_usage = GetNetworkUsageForResource(resource); | 1419 int64 net_usage = GetNetworkUsageForResource(resource); |
1398 if (net_usage == 0 && !resource->SupportNetworkUsage()) | 1420 if (net_usage == 0 && !resource->SupportNetworkUsage()) |
1399 return -1; | 1421 return -1; |
1400 return net_usage; | 1422 return net_usage; |
1401 } | 1423 } |
1402 | 1424 |
1403 double TaskManagerModel::GetCPUUsage(Resource* resource) const { | 1425 double TaskManagerModel::GetCPUUsage(Resource* resource) const { |
1404 const PerProcessValues& values(per_process_cache_[resource->GetProcess()]); | 1426 const PerProcessValues& values(per_process_cache_[resource->GetProcess()]); |
1405 // Returns 0 if not valid, which is fine. | 1427 // Returns 0 if not valid, which is fine. |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1544 params.host_desktop_type = desktop_type; | 1566 params.host_desktop_type = desktop_type; |
1545 chrome::Navigate(¶ms); | 1567 chrome::Navigate(¶ms); |
1546 } | 1568 } |
1547 | 1569 |
1548 TaskManager::TaskManager() | 1570 TaskManager::TaskManager() |
1549 : model_(new TaskManagerModel(this)) { | 1571 : model_(new TaskManagerModel(this)) { |
1550 } | 1572 } |
1551 | 1573 |
1552 TaskManager::~TaskManager() { | 1574 TaskManager::~TaskManager() { |
1553 } | 1575 } |
OLD | NEW |