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/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/i18n/number_formatting.h" | 9 #include "base/i18n/number_formatting.h" |
10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
620 update_requests_++; | 620 update_requests_++; |
621 if (update_requests_ > 1) | 621 if (update_requests_ > 1) |
622 return; | 622 return; |
623 DCHECK_EQ(1, update_requests_); | 623 DCHECK_EQ(1, update_requests_); |
624 DCHECK_NE(TASK_PENDING, update_state_); | 624 DCHECK_NE(TASK_PENDING, update_state_); |
625 | 625 |
626 // If update_state_ is STOPPING, it means a task is still pending. Setting | 626 // If update_state_ is STOPPING, it means a task is still pending. Setting |
627 // it to TASK_PENDING ensures the tasks keep being posted (by Refresh()). | 627 // it to TASK_PENDING ensures the tasks keep being posted (by Refresh()). |
628 if (update_state_ == IDLE) { | 628 if (update_state_ == IDLE) { |
629 MessageLoop::current()->PostDelayedTask( | 629 MessageLoop::current()->PostDelayedTask( |
630 FROM_HERE, base::Bind(&TaskManagerModel::Refresh, this), | 630 FROM_HERE, |
631 kUpdateTimeMs); | 631 base::Bind(&TaskManagerModel::Refresh, this), |
| 632 base::TimeDelta::FromMilliseconds(kUpdateTimeMs)); |
632 } | 633 } |
633 update_state_ = TASK_PENDING; | 634 update_state_ = TASK_PENDING; |
634 | 635 |
635 // Notify resource providers that we are updating. | 636 // Notify resource providers that we are updating. |
636 for (ResourceProviderList::iterator iter = providers_.begin(); | 637 for (ResourceProviderList::iterator iter = providers_.begin(); |
637 iter != providers_.end(); ++iter) { | 638 iter != providers_.end(); ++iter) { |
638 (*iter)->StartUpdating(); | 639 (*iter)->StartUpdating(); |
639 } | 640 } |
640 } | 641 } |
641 | 642 |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
863 MetricsMap::iterator metrics_iter = metrics_map_.find(process); | 864 MetricsMap::iterator metrics_iter = metrics_map_.find(process); |
864 DCHECK(metrics_iter != metrics_map_.end()); | 865 DCHECK(metrics_iter != metrics_map_.end()); |
865 cpu_usage_map_[process] = metrics_iter->second->GetCPUUsage(); | 866 cpu_usage_map_[process] = metrics_iter->second->GetCPUUsage(); |
866 } | 867 } |
867 | 868 |
868 // Clear the memory values so they can be querried lazily. | 869 // Clear the memory values so they can be querried lazily. |
869 memory_usage_map_.clear(); | 870 memory_usage_map_.clear(); |
870 | 871 |
871 // Compute the new network usage values. | 872 // Compute the new network usage values. |
872 displayed_network_usage_map_.clear(); | 873 displayed_network_usage_map_.clear(); |
| 874 base::TimeDelta update_time = |
| 875 base::TimeDelta::FromMilliseconds(kUpdateTimeMs); |
873 for (ResourceValueMap::iterator iter = current_byte_count_map_.begin(); | 876 for (ResourceValueMap::iterator iter = current_byte_count_map_.begin(); |
874 iter != current_byte_count_map_.end(); ++iter) { | 877 iter != current_byte_count_map_.end(); ++iter) { |
875 if (kUpdateTimeMs > 1000) { | 878 if (update_time > base::TimeDelta::FromSeconds(1)) { |
876 int divider = (kUpdateTimeMs / 1000); | 879 int divider = update_time.InSeconds(); |
877 displayed_network_usage_map_[iter->first] = iter->second / divider; | 880 displayed_network_usage_map_[iter->first] = iter->second / divider; |
878 } else { | 881 } else { |
879 displayed_network_usage_map_[iter->first] = iter->second * | 882 displayed_network_usage_map_[iter->first] = iter->second * |
880 (1000 / kUpdateTimeMs); | 883 (1 / update_time.InSeconds()); |
881 } | 884 } |
882 | 885 |
883 // Then we reset the current byte count. | 886 // Then we reset the current byte count. |
884 iter->second = 0; | 887 iter->second = 0; |
885 } | 888 } |
886 | 889 |
887 // Let resources update themselves if they need to. | 890 // Let resources update themselves if they need to. |
888 for (ResourceList::iterator iter = resources_.begin(); | 891 for (ResourceList::iterator iter = resources_.begin(); |
889 iter != resources_.end(); ++iter) { | 892 iter != resources_.end(); ++iter) { |
890 (*iter)->Refresh(); | 893 (*iter)->Refresh(); |
891 } | 894 } |
892 | 895 |
893 if (!resources_.empty()) { | 896 if (!resources_.empty()) { |
894 FOR_EACH_OBSERVER(TaskManagerModelObserver, observer_list_, | 897 FOR_EACH_OBSERVER(TaskManagerModelObserver, observer_list_, |
895 OnItemsChanged(0, ResourceCount())); | 898 OnItemsChanged(0, ResourceCount())); |
896 } | 899 } |
897 | 900 |
898 // Schedule the next update. | 901 // Schedule the next update. |
899 MessageLoop::current()->PostDelayedTask( | 902 MessageLoop::current()->PostDelayedTask( |
900 FROM_HERE, base::Bind(&TaskManagerModel::Refresh, this), kUpdateTimeMs); | 903 FROM_HERE, |
| 904 base::Bind(&TaskManagerModel::Refresh, this), |
| 905 base::TimeDelta::FromMilliseconds(kUpdateTimeMs)); |
901 } | 906 } |
902 | 907 |
903 int64 TaskManagerModel::GetNetworkUsageForResource( | 908 int64 TaskManagerModel::GetNetworkUsageForResource( |
904 TaskManager::Resource* resource) const { | 909 TaskManager::Resource* resource) const { |
905 ResourceValueMap::const_iterator iter = | 910 ResourceValueMap::const_iterator iter = |
906 displayed_network_usage_map_.find(resource); | 911 displayed_network_usage_map_.find(resource); |
907 if (iter == displayed_network_usage_map_.end()) | 912 if (iter == displayed_network_usage_map_.end()) |
908 return 0; | 913 return 0; |
909 return iter->second; | 914 return iter->second; |
910 } | 915 } |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1152 // Count the number of extensions with background pages (including | 1157 // Count the number of extensions with background pages (including |
1153 // incognito). | 1158 // incognito). |
1154 count += CountExtensionBackgroundPagesForProfile(profile); | 1159 count += CountExtensionBackgroundPagesForProfile(profile); |
1155 if (profile->HasOffTheRecordProfile()) { | 1160 if (profile->HasOffTheRecordProfile()) { |
1156 count += CountExtensionBackgroundPagesForProfile( | 1161 count += CountExtensionBackgroundPagesForProfile( |
1157 profile->GetOffTheRecordProfile()); | 1162 profile->GetOffTheRecordProfile()); |
1158 } | 1163 } |
1159 } | 1164 } |
1160 return count; | 1165 return count; |
1161 } | 1166 } |
OLD | NEW |