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/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 29 matching lines...) Expand all Loading... | |
40 #include "grit/ui_resources.h" | 40 #include "grit/ui_resources.h" |
41 #include "ui/base/l10n/l10n_util.h" | 41 #include "ui/base/l10n/l10n_util.h" |
42 #include "ui/base/resource/resource_bundle.h" | 42 #include "ui/base/resource/resource_bundle.h" |
43 #include "ui/base/text/bytes_formatting.h" | 43 #include "ui/base/text/bytes_formatting.h" |
44 #include "unicode/coll.h" | 44 #include "unicode/coll.h" |
45 | 45 |
46 #if defined(OS_MACOSX) | 46 #if defined(OS_MACOSX) |
47 #include "content/browser/mach_broker_mac.h" | 47 #include "content/browser/mach_broker_mac.h" |
48 #endif | 48 #endif |
49 | 49 |
50 using base::TimeDelta; | |
brettw
2012/01/15 17:28:15
It's not clear why you did this here when most of
| |
50 using content::BrowserThread; | 51 using content::BrowserThread; |
51 using content::OpenURLParams; | 52 using content::OpenURLParams; |
52 using content::Referrer; | 53 using content::Referrer; |
53 | 54 |
54 namespace { | 55 namespace { |
55 | 56 |
56 // The delay between updates of the information (in ms). | 57 // The delay between updates of the information (in ms). |
57 #if defined(OS_MACOSX) | 58 #if defined(OS_MACOSX) |
58 // Match Activity Monitor's default refresh rate. | 59 // Match Activity Monitor's default refresh rate. |
59 const int kUpdateTimeMs = 2000; | 60 const int kUpdateTimeMs = 2000; |
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
620 update_requests_++; | 621 update_requests_++; |
621 if (update_requests_ > 1) | 622 if (update_requests_ > 1) |
622 return; | 623 return; |
623 DCHECK_EQ(1, update_requests_); | 624 DCHECK_EQ(1, update_requests_); |
624 DCHECK_NE(TASK_PENDING, update_state_); | 625 DCHECK_NE(TASK_PENDING, update_state_); |
625 | 626 |
626 // If update_state_ is STOPPING, it means a task is still pending. Setting | 627 // 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()). | 628 // it to TASK_PENDING ensures the tasks keep being posted (by Refresh()). |
628 if (update_state_ == IDLE) { | 629 if (update_state_ == IDLE) { |
629 MessageLoop::current()->PostDelayedTask( | 630 MessageLoop::current()->PostDelayedTask( |
630 FROM_HERE, base::Bind(&TaskManagerModel::Refresh, this), | 631 FROM_HERE, |
631 kUpdateTimeMs); | 632 base::Bind(&TaskManagerModel::Refresh, this), |
633 base::TimeDelta::FromMilliseconds(kUpdateTimeMs)); | |
632 } | 634 } |
633 update_state_ = TASK_PENDING; | 635 update_state_ = TASK_PENDING; |
634 | 636 |
635 // Notify resource providers that we are updating. | 637 // Notify resource providers that we are updating. |
636 for (ResourceProviderList::iterator iter = providers_.begin(); | 638 for (ResourceProviderList::iterator iter = providers_.begin(); |
637 iter != providers_.end(); ++iter) { | 639 iter != providers_.end(); ++iter) { |
638 (*iter)->StartUpdating(); | 640 (*iter)->StartUpdating(); |
639 } | 641 } |
640 } | 642 } |
641 | 643 |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
863 MetricsMap::iterator metrics_iter = metrics_map_.find(process); | 865 MetricsMap::iterator metrics_iter = metrics_map_.find(process); |
864 DCHECK(metrics_iter != metrics_map_.end()); | 866 DCHECK(metrics_iter != metrics_map_.end()); |
865 cpu_usage_map_[process] = metrics_iter->second->GetCPUUsage(); | 867 cpu_usage_map_[process] = metrics_iter->second->GetCPUUsage(); |
866 } | 868 } |
867 | 869 |
868 // Clear the memory values so they can be querried lazily. | 870 // Clear the memory values so they can be querried lazily. |
869 memory_usage_map_.clear(); | 871 memory_usage_map_.clear(); |
870 | 872 |
871 // Compute the new network usage values. | 873 // Compute the new network usage values. |
872 displayed_network_usage_map_.clear(); | 874 displayed_network_usage_map_.clear(); |
875 TimeDelta update_time = 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 > 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 |