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