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::SetUpdatingByteCount, this, true)); |
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::SetUpdatingByteCount, this, false)); |
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_) |
| 1257 return; |
1247 | 1258 |
1248 // Only net::URLRequestJob instances created by the ResourceDispatcherHost | 1259 // Only net::URLRequestJob instances created by the ResourceDispatcherHost |
1249 // have an associated ResourceRequestInfo and a render frame associated. | 1260 // have an associated ResourceRequestInfo and a render frame associated. |
1250 // All other jobs will have -1 returned for the render process child and | 1261 // 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, | 1262 // 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. | 1263 // otherwise BytesRead() will attribute the activity to the Browser resource. |
1253 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(&request); | 1264 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(&request); |
1254 int child_id = -1, route_id = -1; | 1265 int child_id = -1, route_id = -1; |
1255 if (info) | 1266 if (info) |
1256 info->GetAssociatedRenderFrame(&child_id, &route_id); | 1267 info->GetAssociatedRenderFrame(&child_id, &route_id); |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1386 | 1397 |
1387 std::vector<BytesReadParam>* bytes_read_buffer = | 1398 std::vector<BytesReadParam>* bytes_read_buffer = |
1388 new std::vector<BytesReadParam>; | 1399 new std::vector<BytesReadParam>; |
1389 bytes_read_buffer_.swap(*bytes_read_buffer); | 1400 bytes_read_buffer_.swap(*bytes_read_buffer); |
1390 BrowserThread::PostTask( | 1401 BrowserThread::PostTask( |
1391 BrowserThread::UI, FROM_HERE, | 1402 BrowserThread::UI, FROM_HERE, |
1392 base::Bind(&TaskManagerModel::MultipleBytesRead, this, | 1403 base::Bind(&TaskManagerModel::MultipleBytesRead, this, |
1393 base::Owned(bytes_read_buffer))); | 1404 base::Owned(bytes_read_buffer))); |
1394 } | 1405 } |
1395 | 1406 |
| 1407 void TaskManagerModel::SetUpdatingByteCount(bool is_updating) { |
| 1408 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 1409 is_updating_byte_count_ = is_updating; |
| 1410 } |
| 1411 |
1396 int64 TaskManagerModel::GetNetworkUsage(Resource* resource) const { | 1412 int64 TaskManagerModel::GetNetworkUsage(Resource* resource) const { |
1397 int64 net_usage = GetNetworkUsageForResource(resource); | 1413 int64 net_usage = GetNetworkUsageForResource(resource); |
1398 if (net_usage == 0 && !resource->SupportNetworkUsage()) | 1414 if (net_usage == 0 && !resource->SupportNetworkUsage()) |
1399 return -1; | 1415 return -1; |
1400 return net_usage; | 1416 return net_usage; |
1401 } | 1417 } |
1402 | 1418 |
1403 double TaskManagerModel::GetCPUUsage(Resource* resource) const { | 1419 double TaskManagerModel::GetCPUUsage(Resource* resource) const { |
1404 const PerProcessValues& values(per_process_cache_[resource->GetProcess()]); | 1420 const PerProcessValues& values(per_process_cache_[resource->GetProcess()]); |
1405 // Returns 0 if not valid, which is fine. | 1421 // 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; | 1560 params.host_desktop_type = desktop_type; |
1545 chrome::Navigate(¶ms); | 1561 chrome::Navigate(¶ms); |
1546 } | 1562 } |
1547 | 1563 |
1548 TaskManager::TaskManager() | 1564 TaskManager::TaskManager() |
1549 : model_(new TaskManagerModel(this)) { | 1565 : model_(new TaskManagerModel(this)) { |
1550 } | 1566 } |
1551 | 1567 |
1552 TaskManager::~TaskManager() { | 1568 TaskManager::~TaskManager() { |
1553 } | 1569 } |
OLD | NEW |