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