| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 8 #include "base/i18n/number_formatting.h" | 9 #include "base/i18n/number_formatting.h" |
| 9 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
| 10 #include "base/process_util.h" | 11 #include "base/process_util.h" |
| 11 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
| 12 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
| 13 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
| 14 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 15 #include "chrome/browser/background/background_contents_service.h" | 16 #include "chrome/browser/background/background_contents_service.h" |
| 16 #include "chrome/browser/background/background_contents_service_factory.h" | 17 #include "chrome/browser/background/background_contents_service_factory.h" |
| (...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 // action the first time. | 606 // action the first time. |
| 606 update_requests_++; | 607 update_requests_++; |
| 607 if (update_requests_ > 1) | 608 if (update_requests_ > 1) |
| 608 return; | 609 return; |
| 609 DCHECK_EQ(1, update_requests_); | 610 DCHECK_EQ(1, update_requests_); |
| 610 DCHECK_NE(TASK_PENDING, update_state_); | 611 DCHECK_NE(TASK_PENDING, update_state_); |
| 611 | 612 |
| 612 // If update_state_ is STOPPING, it means a task is still pending. Setting | 613 // If update_state_ is STOPPING, it means a task is still pending. Setting |
| 613 // it to TASK_PENDING ensures the tasks keep being posted (by Refresh()). | 614 // it to TASK_PENDING ensures the tasks keep being posted (by Refresh()). |
| 614 if (update_state_ == IDLE) { | 615 if (update_state_ == IDLE) { |
| 615 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 616 MessageLoop::current()->PostDelayedTask( |
| 616 NewRunnableMethod(this, &TaskManagerModel::Refresh), | 617 FROM_HERE, base::Bind(&TaskManagerModel::Refresh, this), |
| 617 kUpdateTimeMs); | 618 kUpdateTimeMs); |
| 618 } | 619 } |
| 619 update_state_ = TASK_PENDING; | 620 update_state_ = TASK_PENDING; |
| 620 | 621 |
| 621 // Notify resource providers that we are updating. | 622 // Notify resource providers that we are updating. |
| 622 for (ResourceProviderList::iterator iter = providers_.begin(); | 623 for (ResourceProviderList::iterator iter = providers_.begin(); |
| 623 iter != providers_.end(); ++iter) { | 624 iter != providers_.end(); ++iter) { |
| 624 (*iter)->StartUpdating(); | 625 (*iter)->StartUpdating(); |
| 625 } | 626 } |
| 626 } | 627 } |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 875 iter != resources_.end(); ++iter) { | 876 iter != resources_.end(); ++iter) { |
| 876 (*iter)->Refresh(); | 877 (*iter)->Refresh(); |
| 877 } | 878 } |
| 878 | 879 |
| 879 if (!resources_.empty()) { | 880 if (!resources_.empty()) { |
| 880 FOR_EACH_OBSERVER(TaskManagerModelObserver, observer_list_, | 881 FOR_EACH_OBSERVER(TaskManagerModelObserver, observer_list_, |
| 881 OnItemsChanged(0, ResourceCount())); | 882 OnItemsChanged(0, ResourceCount())); |
| 882 } | 883 } |
| 883 | 884 |
| 884 // Schedule the next update. | 885 // Schedule the next update. |
| 885 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 886 MessageLoop::current()->PostDelayedTask( |
| 886 NewRunnableMethod(this, &TaskManagerModel::Refresh), | 887 FROM_HERE, base::Bind(&TaskManagerModel::Refresh, this), kUpdateTimeMs); |
| 887 kUpdateTimeMs); | |
| 888 } | 888 } |
| 889 | 889 |
| 890 int64 TaskManagerModel::GetNetworkUsageForResource( | 890 int64 TaskManagerModel::GetNetworkUsageForResource( |
| 891 TaskManager::Resource* resource) const { | 891 TaskManager::Resource* resource) const { |
| 892 ResourceValueMap::const_iterator iter = | 892 ResourceValueMap::const_iterator iter = |
| 893 displayed_network_usage_map_.find(resource); | 893 displayed_network_usage_map_.find(resource); |
| 894 if (iter == displayed_network_usage_map_.end()) | 894 if (iter == displayed_network_usage_map_.end()) |
| 895 return 0; | 895 return 0; |
| 896 return iter->second; | 896 return iter->second; |
| 897 } | 897 } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 962 // plugins - for renderer or browser initiated requests it will be zero. | 962 // plugins - for renderer or browser initiated requests it will be zero. |
| 963 int origin_pid = 0; | 963 int origin_pid = 0; |
| 964 const ResourceDispatcherHostRequestInfo* info = | 964 const ResourceDispatcherHostRequestInfo* info = |
| 965 ResourceDispatcherHost::InfoForRequest(&request); | 965 ResourceDispatcherHost::InfoForRequest(&request); |
| 966 if (info) | 966 if (info) |
| 967 origin_pid = info->origin_pid(); | 967 origin_pid = info->origin_pid(); |
| 968 | 968 |
| 969 // This happens in the IO thread, post it to the UI thread. | 969 // This happens in the IO thread, post it to the UI thread. |
| 970 BrowserThread::PostTask( | 970 BrowserThread::PostTask( |
| 971 BrowserThread::UI, FROM_HERE, | 971 BrowserThread::UI, FROM_HERE, |
| 972 NewRunnableMethod( | 972 base::Bind(&TaskManagerModel::BytesRead, this, |
| 973 this, | 973 BytesReadParam(origin_pid, render_process_host_child_id, |
| 974 &TaskManagerModel::BytesRead, | 974 routing_id, byte_count))); |
| 975 BytesReadParam(origin_pid, | |
| 976 render_process_host_child_id, | |
| 977 routing_id, byte_count))); | |
| 978 } | 975 } |
| 979 | 976 |
| 980 bool TaskManagerModel::GetProcessMetricsForRow( | 977 bool TaskManagerModel::GetProcessMetricsForRow( |
| 981 int row, base::ProcessMetrics** proc_metrics) const { | 978 int row, base::ProcessMetrics** proc_metrics) const { |
| 982 DCHECK(row < ResourceCount()); | 979 DCHECK(row < ResourceCount()); |
| 983 *proc_metrics = NULL; | 980 *proc_metrics = NULL; |
| 984 | 981 |
| 985 MetricsMap::const_iterator iter = | 982 MetricsMap::const_iterator iter = |
| 986 metrics_map_.find(resources_[row]->GetProcess()); | 983 metrics_map_.find(resources_[row]->GetProcess()); |
| 987 if (iter == metrics_map_.end()) | 984 if (iter == metrics_map_.end()) |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1141 // Count the number of extensions with background pages (including | 1138 // Count the number of extensions with background pages (including |
| 1142 // incognito). | 1139 // incognito). |
| 1143 count += CountExtensionBackgroundPagesForProfile(profile); | 1140 count += CountExtensionBackgroundPagesForProfile(profile); |
| 1144 if (profile->HasOffTheRecordProfile()) { | 1141 if (profile->HasOffTheRecordProfile()) { |
| 1145 count += CountExtensionBackgroundPagesForProfile( | 1142 count += CountExtensionBackgroundPagesForProfile( |
| 1146 profile->GetOffTheRecordProfile()); | 1143 profile->GetOffTheRecordProfile()); |
| 1147 } | 1144 } |
| 1148 } | 1145 } |
| 1149 return count; | 1146 return count; |
| 1150 } | 1147 } |
| OLD | NEW |