| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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.h" | 5 #include "chrome/browser/task_manager.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/i18n/number_formatting.h" | 10 #include "base/i18n/number_formatting.h" |
| 11 #include "base/i18n/rtl.h" | 11 #include "base/i18n/rtl.h" |
| 12 #include "base/process_util.h" | 12 #include "base/process_util.h" |
| 13 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
| 14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "base/thread.h" | 15 #include "base/thread.h" |
| 16 #include "chrome/browser/browser_list.h" | 16 #include "chrome/browser/browser_list.h" |
| 17 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
| 18 #include "chrome/browser/browser_window.h" | 18 #include "chrome/browser/browser_window.h" |
| 19 #include "chrome/browser/chrome_thread.h" | 19 #include "chrome/browser/chrome_thread.h" |
| 20 #include "chrome/browser/net/url_request_tracking.h" | 20 #include "chrome/browser/net/url_request_tracking.h" |
| 21 #include "chrome/browser/pref_service.h" | 21 #include "chrome/browser/pref_service.h" |
| 22 #include "chrome/browser/profile_manager.h" | 22 #include "chrome/browser/profile_manager.h" |
| 23 #include "chrome/browser/renderer_host/render_process_host.h" | 23 #include "chrome/browser/renderer_host/render_process_host.h" |
| 24 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" | 24 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" |
| 25 #include "chrome/browser/tab_contents/tab_contents.h" | 25 #include "chrome/browser/tab_contents/tab_contents.h" |
| 26 #include "chrome/browser/task_manager_resource_providers.h" | 26 #include "chrome/browser/task_manager_resource_providers.h" |
| 27 #include "chrome/common/notification_service.h" |
| 27 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
| 28 #include "chrome/common/url_constants.h" | 29 #include "chrome/common/url_constants.h" |
| 29 #include "grit/app_resources.h" | 30 #include "grit/app_resources.h" |
| 30 #include "grit/chromium_strings.h" | 31 #include "grit/chromium_strings.h" |
| 31 #include "grit/generated_resources.h" | 32 #include "grit/generated_resources.h" |
| 32 #include "net/url_request/url_request.h" | 33 #include "net/url_request/url_request.h" |
| 33 #include "net/url_request/url_request_job.h" | 34 #include "net/url_request/url_request_job.h" |
| 34 #include "unicode/coll.h" | 35 #include "unicode/coll.h" |
| 35 | 36 |
| 36 #if defined(OS_MACOSX) | 37 #if defined(OS_MACOSX) |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 } | 173 } |
| 173 | 174 |
| 174 std::wstring TaskManagerModel::GetResourceGoatsTeleported(int index) const { | 175 std::wstring TaskManagerModel::GetResourceGoatsTeleported(int index) const { |
| 175 DCHECK(index < ResourceCount()); | 176 DCHECK(index < ResourceCount()); |
| 176 return UTF16ToWide(base::FormatNumber(GetGoatsTeleported(index))); | 177 return UTF16ToWide(base::FormatNumber(GetGoatsTeleported(index))); |
| 177 } | 178 } |
| 178 | 179 |
| 179 std::wstring TaskManagerModel::GetResourceWebCoreImageCacheSize( | 180 std::wstring TaskManagerModel::GetResourceWebCoreImageCacheSize( |
| 180 int index) const { | 181 int index) const { |
| 181 DCHECK(index < ResourceCount()); | 182 DCHECK(index < ResourceCount()); |
| 182 if (!resources_[index]->ReportsCacheStats()) | 183 if (!resources_[index]->HasCacheStats()) |
| 183 return l10n_util::GetString(IDS_TASK_MANAGER_NA_CELL_TEXT); | 184 return l10n_util::GetString(IDS_TASK_MANAGER_NA_CELL_TEXT); |
| 184 const WebKit::WebCache::ResourceTypeStats stats( | 185 const WebKit::WebCache::ResourceTypeStats stats( |
| 185 resources_[index]->GetWebCoreCacheStats()); | 186 resources_[index]->GetWebCoreCacheStats()); |
| 186 return FormatStatsSize(stats.images); | 187 return FormatStatsSize(stats.images); |
| 187 } | 188 } |
| 188 | 189 |
| 189 std::wstring TaskManagerModel::GetResourceWebCoreScriptsCacheSize( | 190 std::wstring TaskManagerModel::GetResourceWebCoreScriptsCacheSize( |
| 190 int index) const { | 191 int index) const { |
| 191 DCHECK(index < ResourceCount()); | 192 DCHECK(index < ResourceCount()); |
| 192 if (!resources_[index]->ReportsCacheStats()) | 193 if (!resources_[index]->HasCacheStats()) |
| 193 return l10n_util::GetString(IDS_TASK_MANAGER_NA_CELL_TEXT); | 194 return l10n_util::GetString(IDS_TASK_MANAGER_NA_CELL_TEXT); |
| 194 const WebKit::WebCache::ResourceTypeStats stats( | 195 const WebKit::WebCache::ResourceTypeStats stats( |
| 195 resources_[index]->GetWebCoreCacheStats()); | 196 resources_[index]->GetWebCoreCacheStats()); |
| 196 return FormatStatsSize(stats.scripts); | 197 return FormatStatsSize(stats.scripts); |
| 197 } | 198 } |
| 198 | 199 |
| 199 std::wstring TaskManagerModel::GetResourceWebCoreCSSCacheSize( | 200 std::wstring TaskManagerModel::GetResourceWebCoreCSSCacheSize( |
| 200 int index) const { | 201 int index) const { |
| 201 DCHECK(index < ResourceCount()); | 202 DCHECK(index < ResourceCount()); |
| 202 if (!resources_[index]->ReportsCacheStats()) | 203 if (!resources_[index]->HasCacheStats()) |
| 203 return l10n_util::GetString(IDS_TASK_MANAGER_NA_CELL_TEXT); | 204 return l10n_util::GetString(IDS_TASK_MANAGER_NA_CELL_TEXT); |
| 204 const WebKit::WebCache::ResourceTypeStats stats( | 205 const WebKit::WebCache::ResourceTypeStats stats( |
| 205 resources_[index]->GetWebCoreCacheStats()); | 206 resources_[index]->GetWebCoreCacheStats()); |
| 206 return FormatStatsSize(stats.cssStyleSheets); | 207 return FormatStatsSize(stats.cssStyleSheets); |
| 207 } | 208 } |
| 208 | 209 |
| 209 std::wstring TaskManagerModel::GetResourceSqliteMemoryUsed(int index) const { | 210 std::wstring TaskManagerModel::GetResourceSqliteMemoryUsed(int index) const { |
| 210 DCHECK(index < ResourceCount()); | 211 DCHECK(index < ResourceCount()); |
| 211 if (!resources_[index]->ReportsSqliteMemoryUsed()) | 212 if (!resources_[index]->ReportsSqliteMemoryUsed()) |
| 212 return l10n_util::GetString(IDS_TASK_MANAGER_NA_CELL_TEXT); | 213 return l10n_util::GetString(IDS_TASK_MANAGER_NA_CELL_TEXT); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 int proc1_id = base::GetProcId(resources_[row1]->GetProcess()); | 332 int proc1_id = base::GetProcId(resources_[row1]->GetProcess()); |
| 332 int proc2_id = base::GetProcId(resources_[row2]->GetProcess()); | 333 int proc2_id = base::GetProcId(resources_[row2]->GetProcess()); |
| 333 return ValueCompare<int>(proc1_id, proc2_id); | 334 return ValueCompare<int>(proc1_id, proc2_id); |
| 334 } | 335 } |
| 335 | 336 |
| 336 case IDS_TASK_MANAGER_WEBCORE_IMAGE_CACHE_COLUMN: | 337 case IDS_TASK_MANAGER_WEBCORE_IMAGE_CACHE_COLUMN: |
| 337 case IDS_TASK_MANAGER_WEBCORE_SCRIPTS_CACHE_COLUMN: | 338 case IDS_TASK_MANAGER_WEBCORE_SCRIPTS_CACHE_COLUMN: |
| 338 case IDS_TASK_MANAGER_WEBCORE_CSS_CACHE_COLUMN: { | 339 case IDS_TASK_MANAGER_WEBCORE_CSS_CACHE_COLUMN: { |
| 339 WebKit::WebCache::ResourceTypeStats stats1 = { { 0 } }; | 340 WebKit::WebCache::ResourceTypeStats stats1 = { { 0 } }; |
| 340 WebKit::WebCache::ResourceTypeStats stats2 = { { 0 } }; | 341 WebKit::WebCache::ResourceTypeStats stats2 = { { 0 } }; |
| 341 if (resources_[row1]->ReportsCacheStats()) | 342 if (resources_[row1]->HasCacheStats()) |
| 342 stats1 = resources_[row1]->GetWebCoreCacheStats(); | 343 stats1 = resources_[row1]->GetWebCoreCacheStats(); |
| 343 if (resources_[row2]->ReportsCacheStats()) | 344 if (resources_[row2]->HasCacheStats()) |
| 344 stats2 = resources_[row2]->GetWebCoreCacheStats(); | 345 stats2 = resources_[row2]->GetWebCoreCacheStats(); |
| 345 if (IDS_TASK_MANAGER_WEBCORE_IMAGE_CACHE_COLUMN == col_id) | 346 if (IDS_TASK_MANAGER_WEBCORE_IMAGE_CACHE_COLUMN == col_id) |
| 346 return ValueCompare<size_t>(stats1.images.size, stats2.images.size); | 347 return ValueCompare<size_t>(stats1.images.size, stats2.images.size); |
| 347 if (IDS_TASK_MANAGER_WEBCORE_SCRIPTS_CACHE_COLUMN == col_id) | 348 if (IDS_TASK_MANAGER_WEBCORE_SCRIPTS_CACHE_COLUMN == col_id) |
| 348 return ValueCompare<size_t>(stats1.scripts.size, stats2.scripts.size); | 349 return ValueCompare<size_t>(stats1.scripts.size, stats2.scripts.size); |
| 349 DCHECK_EQ(IDS_TASK_MANAGER_WEBCORE_CSS_CACHE_COLUMN, col_id); | 350 DCHECK_EQ(IDS_TASK_MANAGER_WEBCORE_CSS_CACHE_COLUMN, col_id); |
| 350 return ValueCompare<size_t>(stats1.cssStyleSheets.size, | 351 return ValueCompare<size_t>(stats1.cssStyleSheets.size, |
| 351 stats2.cssStyleSheets.size); | 352 stats2.cssStyleSheets.size); |
| 352 } | 353 } |
| 353 | 354 |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 | 681 |
| 681 void TaskManagerModel::NotifyResourceTypeStats( | 682 void TaskManagerModel::NotifyResourceTypeStats( |
| 682 base::ProcessId renderer_id, | 683 base::ProcessId renderer_id, |
| 683 const WebKit::WebCache::ResourceTypeStats& stats) { | 684 const WebKit::WebCache::ResourceTypeStats& stats) { |
| 684 for (ResourceList::iterator it = resources_.begin(); | 685 for (ResourceList::iterator it = resources_.begin(); |
| 685 it != resources_.end(); ++it) { | 686 it != resources_.end(); ++it) { |
| 686 if (base::GetProcId((*it)->GetProcess()) == renderer_id) { | 687 if (base::GetProcId((*it)->GetProcess()) == renderer_id) { |
| 687 (*it)->NotifyResourceTypeStats(stats); | 688 (*it)->NotifyResourceTypeStats(stats); |
| 688 } | 689 } |
| 689 } | 690 } |
| 691 NotificationService::current()->Notify( |
| 692 NotificationType::TASK_MANAGER_RESOURCE_TYPE_STATS_UPDATED, |
| 693 Source<TaskManagerModel>(this), |
| 694 NotificationService::NoDetails()); |
| 690 } | 695 } |
| 691 | 696 |
| 692 void TaskManagerModel::NotifyV8HeapStats(base::ProcessId renderer_id, | 697 void TaskManagerModel::NotifyV8HeapStats(base::ProcessId renderer_id, |
| 693 size_t v8_memory_allocated, | 698 size_t v8_memory_allocated, |
| 694 size_t v8_memory_used) { | 699 size_t v8_memory_used) { |
| 695 for (ResourceList::iterator it = resources_.begin(); | 700 for (ResourceList::iterator it = resources_.begin(); |
| 696 it != resources_.end(); ++it) { | 701 it != resources_.end(); ++it) { |
| 697 if (base::GetProcId((*it)->GetProcess()) == renderer_id) { | 702 if (base::GetProcId((*it)->GetProcess()) == renderer_id) { |
| 698 (*it)->NotifyV8HeapStats(v8_memory_allocated, v8_memory_used); | 703 (*it)->NotifyV8HeapStats(v8_memory_allocated, v8_memory_used); |
| 699 } | 704 } |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 974 MetricsMap::const_iterator iter = metrics_map_.find(handle); | 979 MetricsMap::const_iterator iter = metrics_map_.find(handle); |
| 975 if (iter == metrics_map_.end()) | 980 if (iter == metrics_map_.end()) |
| 976 return false; | 981 return false; |
| 977 | 982 |
| 978 if (!iter->second->GetMemoryBytes(&usage->first, &usage->second)) | 983 if (!iter->second->GetMemoryBytes(&usage->first, &usage->second)) |
| 979 return false; | 984 return false; |
| 980 | 985 |
| 981 memory_usage_map_.insert(std::make_pair(handle, *usage)); | 986 memory_usage_map_.insert(std::make_pair(handle, *usage)); |
| 982 return true; | 987 return true; |
| 983 } | 988 } |
| OLD | NEW |