| 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/task_manager.h" | 5 #include "chrome/browser/task_manager/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" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 FormatBytes(stat.liveSize, DATA_UNITS_KIBIBYTE, false)); | 63 FormatBytes(stat.liveSize, DATA_UNITS_KIBIBYTE, false)); |
| 64 } | 64 } |
| 65 | 65 |
| 66 } // namespace | 66 } // namespace |
| 67 | 67 |
| 68 //////////////////////////////////////////////////////////////////////////////// | 68 //////////////////////////////////////////////////////////////////////////////// |
| 69 // TaskManagerModel class | 69 // TaskManagerModel class |
| 70 //////////////////////////////////////////////////////////////////////////////// | 70 //////////////////////////////////////////////////////////////////////////////// |
| 71 | 71 |
| 72 TaskManagerModel::TaskManagerModel(TaskManager* task_manager) | 72 TaskManagerModel::TaskManagerModel(TaskManager* task_manager) |
| 73 : update_state_(IDLE), | 73 : update_requests_(0), |
| 74 update_state_(IDLE), |
| 74 goat_salt_(rand()) { | 75 goat_salt_(rand()) { |
| 75 | 76 |
| 76 TaskManagerBrowserProcessResourceProvider* browser_provider = | 77 TaskManagerBrowserProcessResourceProvider* browser_provider = |
| 77 new TaskManagerBrowserProcessResourceProvider(task_manager); | 78 new TaskManagerBrowserProcessResourceProvider(task_manager); |
| 78 browser_provider->AddRef(); | 79 browser_provider->AddRef(); |
| 79 providers_.push_back(browser_provider); | 80 providers_.push_back(browser_provider); |
| 80 TaskManagerTabContentsResourceProvider* wc_provider = | 81 TaskManagerTabContentsResourceProvider* wc_provider = |
| 81 new TaskManagerTabContentsResourceProvider(task_manager); | 82 new TaskManagerTabContentsResourceProvider(task_manager); |
| 82 wc_provider->AddRef(); | 83 wc_provider->AddRef(); |
| 83 providers_.push_back(wc_provider); | 84 providers_.push_back(wc_provider); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 108 | 109 |
| 109 void TaskManagerModel::AddObserver(TaskManagerModelObserver* observer) { | 110 void TaskManagerModel::AddObserver(TaskManagerModelObserver* observer) { |
| 110 observer_list_.AddObserver(observer); | 111 observer_list_.AddObserver(observer); |
| 111 } | 112 } |
| 112 | 113 |
| 113 void TaskManagerModel::RemoveObserver(TaskManagerModelObserver* observer) { | 114 void TaskManagerModel::RemoveObserver(TaskManagerModelObserver* observer) { |
| 114 observer_list_.RemoveObserver(observer); | 115 observer_list_.RemoveObserver(observer); |
| 115 } | 116 } |
| 116 | 117 |
| 117 string16 TaskManagerModel::GetResourceTitle(int index) const { | 118 string16 TaskManagerModel::GetResourceTitle(int index) const { |
| 118 DCHECK(index < ResourceCount()); | 119 CHECK(index < ResourceCount()); |
| 119 return WideToUTF16Hack(resources_[index]->GetTitle()); | 120 return WideToUTF16Hack(resources_[index]->GetTitle()); |
| 120 } | 121 } |
| 121 | 122 |
| 123 int64 TaskManagerModel::GetNetworkUsage(int index) const { |
| 124 CHECK(index < ResourceCount()); |
| 125 return GetNetworkUsage(resources_[index]); |
| 126 } |
| 127 |
| 122 string16 TaskManagerModel::GetResourceNetworkUsage(int index) const { | 128 string16 TaskManagerModel::GetResourceNetworkUsage(int index) const { |
| 123 DCHECK(index < ResourceCount()); | 129 int64 net_usage = GetNetworkUsage(index); |
| 124 int64 net_usage = GetNetworkUsage(resources_[index]); | |
| 125 if (net_usage == -1) | 130 if (net_usage == -1) |
| 126 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT); | 131 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT); |
| 127 if (net_usage == 0) | 132 if (net_usage == 0) |
| 128 return ASCIIToUTF16("0"); | 133 return ASCIIToUTF16("0"); |
| 129 string16 net_byte = FormatSpeed(net_usage, GetByteDisplayUnits(net_usage), | 134 string16 net_byte = FormatSpeed(net_usage, GetByteDisplayUnits(net_usage), |
| 130 true); | 135 true); |
| 131 // Force number string to have LTR directionality. | 136 // Force number string to have LTR directionality. |
| 132 return base::i18n::GetDisplayStringInLTRDirectionality(net_byte); | 137 return base::i18n::GetDisplayStringInLTRDirectionality(net_byte); |
| 133 } | 138 } |
| 134 | 139 |
| 140 double TaskManagerModel::GetCPUUsage(int index) const { |
| 141 CHECK(index < ResourceCount()); |
| 142 return GetCPUUsage(resources_[index]); |
| 143 } |
| 144 |
| 135 string16 TaskManagerModel::GetResourceCPUUsage(int index) const { | 145 string16 TaskManagerModel::GetResourceCPUUsage(int index) const { |
| 136 DCHECK(index < ResourceCount()); | 146 CHECK(index < ResourceCount()); |
| 137 return WideToUTF16Hack(StringPrintf( | 147 return WideToUTF16Hack(StringPrintf( |
| 138 #if defined(OS_MACOSX) | 148 #if defined(OS_MACOSX) |
| 139 // Activity Monitor shows %cpu with one decimal digit -- be | 149 // Activity Monitor shows %cpu with one decimal digit -- be |
| 140 // consistent with that. | 150 // consistent with that. |
| 141 L"%.1f", | 151 L"%.1f", |
| 142 #else | 152 #else |
| 143 L"%.0f", | 153 L"%.0f", |
| 144 #endif | 154 #endif |
| 145 GetCPUUsage(resources_[index]))); | 155 GetCPUUsage(resources_[index]))); |
| 146 } | 156 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 158 return ASCIIToUTF16("N/A"); | 168 return ASCIIToUTF16("N/A"); |
| 159 return GetMemCellText(shared_mem); | 169 return GetMemCellText(shared_mem); |
| 160 } | 170 } |
| 161 | 171 |
| 162 string16 TaskManagerModel::GetResourcePhysicalMemory(int index) const { | 172 string16 TaskManagerModel::GetResourcePhysicalMemory(int index) const { |
| 163 size_t phys_mem; | 173 size_t phys_mem; |
| 164 GetPhysicalMemory(index, &phys_mem); | 174 GetPhysicalMemory(index, &phys_mem); |
| 165 return GetMemCellText(phys_mem); | 175 return GetMemCellText(phys_mem); |
| 166 } | 176 } |
| 167 | 177 |
| 178 int TaskManagerModel::GetProcessId(int index) const { |
| 179 CHECK(index < ResourceCount()); |
| 180 return base::GetProcId(resources_[index]->GetProcess()); |
| 181 } |
| 182 |
| 168 string16 TaskManagerModel::GetResourceProcessId(int index) const { | 183 string16 TaskManagerModel::GetResourceProcessId(int index) const { |
| 169 DCHECK(index < ResourceCount()); | 184 return base::IntToString16(GetProcessId(index)); |
| 170 return base::IntToString16(base::GetProcId(resources_[index]->GetProcess())); | |
| 171 } | 185 } |
| 172 | 186 |
| 173 string16 TaskManagerModel::GetResourceGoatsTeleported(int index) const { | 187 string16 TaskManagerModel::GetResourceGoatsTeleported(int index) const { |
| 174 DCHECK(index < ResourceCount()); | 188 CHECK(index < ResourceCount()); |
| 175 return base::FormatNumber(GetGoatsTeleported(index)); | 189 return base::FormatNumber(GetGoatsTeleported(index)); |
| 176 } | 190 } |
| 177 | 191 |
| 178 string16 TaskManagerModel::GetResourceWebCoreImageCacheSize( | 192 string16 TaskManagerModel::GetResourceWebCoreImageCacheSize( |
| 179 int index) const { | 193 int index) const { |
| 180 DCHECK(index < ResourceCount()); | 194 CHECK(index < ResourceCount()); |
| 181 if (!resources_[index]->ReportsCacheStats()) | 195 if (!resources_[index]->ReportsCacheStats()) |
| 182 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT); | 196 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT); |
| 183 const WebKit::WebCache::ResourceTypeStats stats( | 197 const WebKit::WebCache::ResourceTypeStats stats( |
| 184 resources_[index]->GetWebCoreCacheStats()); | 198 resources_[index]->GetWebCoreCacheStats()); |
| 185 return FormatStatsSize(stats.images); | 199 return FormatStatsSize(stats.images); |
| 186 } | 200 } |
| 187 | 201 |
| 188 string16 TaskManagerModel::GetResourceWebCoreScriptsCacheSize( | 202 string16 TaskManagerModel::GetResourceWebCoreScriptsCacheSize( |
| 189 int index) const { | 203 int index) const { |
| 190 DCHECK(index < ResourceCount()); | 204 CHECK(index < ResourceCount()); |
| 191 if (!resources_[index]->ReportsCacheStats()) | 205 if (!resources_[index]->ReportsCacheStats()) |
| 192 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT); | 206 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT); |
| 193 const WebKit::WebCache::ResourceTypeStats stats( | 207 const WebKit::WebCache::ResourceTypeStats stats( |
| 194 resources_[index]->GetWebCoreCacheStats()); | 208 resources_[index]->GetWebCoreCacheStats()); |
| 195 return FormatStatsSize(stats.scripts); | 209 return FormatStatsSize(stats.scripts); |
| 196 } | 210 } |
| 197 | 211 |
| 198 string16 TaskManagerModel::GetResourceWebCoreCSSCacheSize( | 212 string16 TaskManagerModel::GetResourceWebCoreCSSCacheSize( |
| 199 int index) const { | 213 int index) const { |
| 200 DCHECK(index < ResourceCount()); | 214 CHECK(index < ResourceCount()); |
| 201 if (!resources_[index]->ReportsCacheStats()) | 215 if (!resources_[index]->ReportsCacheStats()) |
| 202 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT); | 216 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT); |
| 203 const WebKit::WebCache::ResourceTypeStats stats( | 217 const WebKit::WebCache::ResourceTypeStats stats( |
| 204 resources_[index]->GetWebCoreCacheStats()); | 218 resources_[index]->GetWebCoreCacheStats()); |
| 205 return FormatStatsSize(stats.cssStyleSheets); | 219 return FormatStatsSize(stats.cssStyleSheets); |
| 206 } | 220 } |
| 207 | 221 |
| 208 string16 TaskManagerModel::GetResourceSqliteMemoryUsed(int index) const { | 222 string16 TaskManagerModel::GetResourceSqliteMemoryUsed(int index) const { |
| 209 DCHECK(index < ResourceCount()); | 223 CHECK(index < ResourceCount()); |
| 210 if (!resources_[index]->ReportsSqliteMemoryUsed()) | 224 if (!resources_[index]->ReportsSqliteMemoryUsed()) |
| 211 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT); | 225 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT); |
| 212 return GetMemCellText(resources_[index]->SqliteMemoryUsedBytes()); | 226 return GetMemCellText(resources_[index]->SqliteMemoryUsedBytes()); |
| 213 } | 227 } |
| 214 | 228 |
| 215 string16 TaskManagerModel::GetResourceV8MemoryAllocatedSize( | 229 string16 TaskManagerModel::GetResourceV8MemoryAllocatedSize( |
| 216 int index) const { | 230 int index) const { |
| 217 if (!resources_[index]->ReportsV8MemoryStats()) | 231 if (!resources_[index]->ReportsV8MemoryStats()) |
| 218 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT); | 232 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT); |
| 219 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_CACHE_SIZE_CELL_TEXT, | 233 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_CACHE_SIZE_CELL_TEXT, |
| 220 FormatBytes(resources_[index]->GetV8MemoryAllocated(), | 234 FormatBytes(resources_[index]->GetV8MemoryAllocated(), |
| 221 DATA_UNITS_KIBIBYTE, | 235 DATA_UNITS_KIBIBYTE, |
| 222 false), | 236 false), |
| 223 FormatBytes(resources_[index]->GetV8MemoryUsed(), | 237 FormatBytes(resources_[index]->GetV8MemoryUsed(), |
| 224 DATA_UNITS_KIBIBYTE, | 238 DATA_UNITS_KIBIBYTE, |
| 225 false)); | 239 false)); |
| 226 } | 240 } |
| 227 | 241 |
| 228 bool TaskManagerModel::IsResourceFirstInGroup(int index) const { | 242 bool TaskManagerModel::IsResourceFirstInGroup(int index) const { |
| 229 DCHECK(index < ResourceCount()); | 243 CHECK(index < ResourceCount()); |
| 230 TaskManager::Resource* resource = resources_[index]; | 244 TaskManager::Resource* resource = resources_[index]; |
| 231 GroupMap::const_iterator iter = group_map_.find(resource->GetProcess()); | 245 GroupMap::const_iterator iter = group_map_.find(resource->GetProcess()); |
| 232 DCHECK(iter != group_map_.end()); | 246 DCHECK(iter != group_map_.end()); |
| 233 const ResourceList* group = iter->second; | 247 const ResourceList* group = iter->second; |
| 234 return ((*group)[0] == resource); | 248 return ((*group)[0] == resource); |
| 235 } | 249 } |
| 236 | 250 |
| 237 SkBitmap TaskManagerModel::GetResourceIcon(int index) const { | 251 SkBitmap TaskManagerModel::GetResourceIcon(int index) const { |
| 238 DCHECK(index < ResourceCount()); | 252 CHECK(index < ResourceCount()); |
| 239 SkBitmap icon = resources_[index]->GetIcon(); | 253 SkBitmap icon = resources_[index]->GetIcon(); |
| 240 if (!icon.isNull()) | 254 if (!icon.isNull()) |
| 241 return icon; | 255 return icon; |
| 242 | 256 |
| 243 static SkBitmap* default_icon = ResourceBundle::GetSharedInstance(). | 257 static SkBitmap* default_icon = ResourceBundle::GetSharedInstance(). |
| 244 GetBitmapNamed(IDR_DEFAULT_FAVICON); | 258 GetBitmapNamed(IDR_DEFAULT_FAVICON); |
| 245 return *default_icon; | 259 return *default_icon; |
| 246 } | 260 } |
| 247 | 261 |
| 248 std::pair<int, int> TaskManagerModel::GetGroupRangeForResource(int index) | 262 std::pair<int, int> TaskManagerModel::GetGroupRangeForResource(int index) |
| 249 const { | 263 const { |
| 250 DCHECK(index < ResourceCount()); | 264 CHECK(index < ResourceCount()); |
| 251 TaskManager::Resource* resource = resources_[index]; | 265 TaskManager::Resource* resource = resources_[index]; |
| 252 GroupMap::const_iterator group_iter = | 266 GroupMap::const_iterator group_iter = |
| 253 group_map_.find(resource->GetProcess()); | 267 group_map_.find(resource->GetProcess()); |
| 254 DCHECK(group_iter != group_map_.end()); | 268 DCHECK(group_iter != group_map_.end()); |
| 255 ResourceList* group = group_iter->second; | 269 ResourceList* group = group_iter->second; |
| 256 DCHECK(group); | 270 DCHECK(group); |
| 257 if (group->size() == 1) { | 271 if (group->size() == 1) { |
| 258 return std::make_pair(index, 1); | 272 return std::make_pair(index, 1); |
| 259 } else { | 273 } else { |
| 260 for (int i = index; i >= 0; --i) { | 274 for (int i = index; i >= 0; --i) { |
| 261 if (resources_[i] == (*group)[0]) | 275 if (resources_[i] == (*group)[0]) |
| 262 return std::make_pair(i, group->size()); | 276 return std::make_pair(i, group->size()); |
| 263 } | 277 } |
| 264 NOTREACHED(); | 278 NOTREACHED(); |
| 265 return std::make_pair(-1, -1); | 279 return std::make_pair(-1, -1); |
| 266 } | 280 } |
| 267 } | 281 } |
| 268 | 282 |
| 269 int TaskManagerModel::CompareValues(int row1, int row2, int col_id) const { | 283 int TaskManagerModel::CompareValues(int row1, int row2, int col_id) const { |
| 270 DCHECK(row1 < ResourceCount() && row2 < ResourceCount()); | 284 CHECK(row1 < ResourceCount() && row2 < ResourceCount()); |
| 271 switch (col_id) { | 285 switch (col_id) { |
| 272 case IDS_TASK_MANAGER_PAGE_COLUMN: { | 286 case IDS_TASK_MANAGER_PAGE_COLUMN: { |
| 273 // Let's do the default, string compare on the resource title. | 287 // Let's do the default, string compare on the resource title. |
| 274 static icu::Collator* collator = NULL; | 288 static icu::Collator* collator = NULL; |
| 275 if (!collator) { | 289 if (!collator) { |
| 276 UErrorCode create_status = U_ZERO_ERROR; | 290 UErrorCode create_status = U_ZERO_ERROR; |
| 277 collator = icu::Collator::createInstance(create_status); | 291 collator = icu::Collator::createInstance(create_status); |
| 278 if (!U_SUCCESS(create_status)) { | 292 if (!U_SUCCESS(create_status)) { |
| 279 collator = NULL; | 293 collator = NULL; |
| 280 NOTREACHED(); | 294 NOTREACHED(); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 } | 381 } |
| 368 | 382 |
| 369 default: | 383 default: |
| 370 NOTREACHED(); | 384 NOTREACHED(); |
| 371 return 0; | 385 return 0; |
| 372 } | 386 } |
| 373 } | 387 } |
| 374 | 388 |
| 375 base::ProcessHandle TaskManagerModel::GetResourceProcessHandle(int index) | 389 base::ProcessHandle TaskManagerModel::GetResourceProcessHandle(int index) |
| 376 const { | 390 const { |
| 377 DCHECK(index < ResourceCount()); | 391 CHECK(index < ResourceCount()); |
| 378 return resources_[index]->GetProcess(); | 392 return resources_[index]->GetProcess(); |
| 379 } | 393 } |
| 380 | 394 |
| 395 TaskManager::Resource::Type TaskManagerModel::GetResourceType(int index) const { |
| 396 CHECK(index < ResourceCount()); |
| 397 return resources_[index]->GetType(); |
| 398 } |
| 399 |
| 381 TabContents* TaskManagerModel::GetResourceTabContents(int index) const { | 400 TabContents* TaskManagerModel::GetResourceTabContents(int index) const { |
| 382 DCHECK(index < ResourceCount()); | 401 CHECK(index < ResourceCount()); |
| 383 return resources_[index]->GetTabContents(); | 402 return resources_[index]->GetTabContents(); |
| 384 } | 403 } |
| 385 | 404 |
| 386 const Extension* TaskManagerModel::GetResourceExtension(int index) const { | 405 const Extension* TaskManagerModel::GetResourceExtension(int index) const { |
| 387 DCHECK(index < ResourceCount()); | 406 CHECK(index < ResourceCount()); |
| 388 return resources_[index]->GetExtension(); | 407 return resources_[index]->GetExtension(); |
| 389 } | 408 } |
| 390 | 409 |
| 391 int64 TaskManagerModel::GetNetworkUsage(TaskManager::Resource* resource) | 410 int64 TaskManagerModel::GetNetworkUsage(TaskManager::Resource* resource) |
| 392 const { | 411 const { |
| 393 int64 net_usage = GetNetworkUsageForResource(resource); | 412 int64 net_usage = GetNetworkUsageForResource(resource); |
| 394 if (net_usage == 0 && !resource->SupportNetworkUsage()) | 413 if (net_usage == 0 && !resource->SupportNetworkUsage()) |
| 395 return -1; | 414 return -1; |
| 396 return net_usage; | 415 return net_usage; |
| 397 } | 416 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 base::i18n::AdjustStringForLocaleDirection(str, &str); | 494 base::i18n::AdjustStringForLocaleDirection(str, &str); |
| 476 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_MEM_CELL_TEXT, str); | 495 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_MEM_CELL_TEXT, str); |
| 477 #else | 496 #else |
| 478 // System expectation is to show "100 KB", "200 MB", etc. | 497 // System expectation is to show "100 KB", "200 MB", etc. |
| 479 // TODO(thakis): Switch to metric units (as opposed to powers of two). | 498 // TODO(thakis): Switch to metric units (as opposed to powers of two). |
| 480 return FormatBytes(number, GetByteDisplayUnits(number), /*show_units=*/true); | 499 return FormatBytes(number, GetByteDisplayUnits(number), /*show_units=*/true); |
| 481 #endif | 500 #endif |
| 482 } | 501 } |
| 483 | 502 |
| 484 void TaskManagerModel::StartUpdating() { | 503 void TaskManagerModel::StartUpdating() { |
| 504 // Multiple StartUpdating requests may come in, and we only need to take |
| 505 // action the first time. |
| 506 update_requests_++; |
| 507 if (update_requests_ > 1) |
| 508 return; |
| 509 DCHECK_EQ(1, update_requests_); |
| 485 DCHECK_NE(TASK_PENDING, update_state_); | 510 DCHECK_NE(TASK_PENDING, update_state_); |
| 486 | 511 |
| 487 // If update_state_ is STOPPING, it means a task is still pending. Setting | 512 // If update_state_ is STOPPING, it means a task is still pending. Setting |
| 488 // it to TASK_PENDING ensures the tasks keep being posted (by Refresh()). | 513 // it to TASK_PENDING ensures the tasks keep being posted (by Refresh()). |
| 489 if (update_state_ == IDLE) { | 514 if (update_state_ == IDLE) { |
| 490 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 515 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 491 NewRunnableMethod(this, &TaskManagerModel::Refresh), | 516 NewRunnableMethod(this, &TaskManagerModel::Refresh), |
| 492 kUpdateTimeMs); | 517 kUpdateTimeMs); |
| 493 } | 518 } |
| 494 update_state_ = TASK_PENDING; | 519 update_state_ = TASK_PENDING; |
| 495 | 520 |
| 496 // Register jobs notifications so we can compute network usage (it must be | 521 // Register jobs notifications so we can compute network usage (it must be |
| 497 // done from the IO thread). | 522 // done from the IO thread). |
| 498 BrowserThread::PostTask( | 523 BrowserThread::PostTask( |
| 499 BrowserThread::IO, FROM_HERE, | 524 BrowserThread::IO, FROM_HERE, |
| 500 NewRunnableMethod( | 525 NewRunnableMethod( |
| 501 this, &TaskManagerModel::RegisterForJobDoneNotifications)); | 526 this, &TaskManagerModel::RegisterForJobDoneNotifications)); |
| 502 | 527 |
| 503 // Notify resource providers that we are updating. | 528 // Notify resource providers that we are updating. |
| 504 for (ResourceProviderList::iterator iter = providers_.begin(); | 529 for (ResourceProviderList::iterator iter = providers_.begin(); |
| 505 iter != providers_.end(); ++iter) { | 530 iter != providers_.end(); ++iter) { |
| 506 (*iter)->StartUpdating(); | 531 (*iter)->StartUpdating(); |
| 507 } | 532 } |
| 508 } | 533 } |
| 509 | 534 |
| 510 void TaskManagerModel::StopUpdating() { | 535 void TaskManagerModel::StopUpdating() { |
| 536 // Don't actually stop updating until we have heard as many calls as those |
| 537 // to StartUpdating. |
| 538 update_requests_--; |
| 539 if (update_requests_ > 0) |
| 540 return; |
| 541 // Make sure that update_requests_ cannot go negative. |
| 542 CHECK_EQ(0, update_requests_); |
| 511 DCHECK_EQ(TASK_PENDING, update_state_); | 543 DCHECK_EQ(TASK_PENDING, update_state_); |
| 512 update_state_ = STOPPING; | 544 update_state_ = STOPPING; |
| 513 | 545 |
| 514 // Notify resource providers that we are done updating. | 546 // Notify resource providers that we are done updating. |
| 515 for (ResourceProviderList::const_iterator iter = providers_.begin(); | 547 for (ResourceProviderList::const_iterator iter = providers_.begin(); |
| 516 iter != providers_.end(); ++iter) { | 548 iter != providers_.end(); ++iter) { |
| 517 (*iter)->StopUpdating(); | 549 (*iter)->StopUpdating(); |
| 518 } | 550 } |
| 519 | 551 |
| 520 // Unregister jobs notification (must be done from the IO thread). | 552 // Unregister jobs notification (must be done from the IO thread). |
| 521 BrowserThread::PostTask( | 553 BrowserThread::PostTask( |
| 522 BrowserThread::IO, FROM_HERE, | 554 BrowserThread::IO, FROM_HERE, |
| 523 NewRunnableMethod( | 555 NewRunnableMethod( |
| 524 this, &TaskManagerModel::UnregisterForJobDoneNotifications)); | 556 this, &TaskManagerModel::UnregisterForJobDoneNotifications)); |
| 557 |
| 558 // Must clear the resources before the next attempt to start updating. |
| 559 Clear(); |
| 525 } | 560 } |
| 526 | 561 |
| 527 void TaskManagerModel::AddResourceProvider( | 562 void TaskManagerModel::AddResourceProvider( |
| 528 TaskManager::ResourceProvider* provider) { | 563 TaskManager::ResourceProvider* provider) { |
| 529 DCHECK(provider); | 564 DCHECK(provider); |
| 530 providers_.push_back(provider); | 565 providers_.push_back(provider); |
| 531 } | 566 } |
| 532 | 567 |
| 533 void TaskManagerModel::RemoveResourceProvider( | 568 void TaskManagerModel::RemoveResourceProvider( |
| 534 TaskManager::ResourceProvider* provider) { | 569 TaskManager::ResourceProvider* provider) { |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 918 void TaskManager::AddResource(Resource* resource) { | 953 void TaskManager::AddResource(Resource* resource) { |
| 919 model_->AddResource(resource); | 954 model_->AddResource(resource); |
| 920 } | 955 } |
| 921 | 956 |
| 922 void TaskManager::RemoveResource(Resource* resource) { | 957 void TaskManager::RemoveResource(Resource* resource) { |
| 923 model_->RemoveResource(resource); | 958 model_->RemoveResource(resource); |
| 924 } | 959 } |
| 925 | 960 |
| 926 void TaskManager::OnWindowClosed() { | 961 void TaskManager::OnWindowClosed() { |
| 927 model_->StopUpdating(); | 962 model_->StopUpdating(); |
| 928 model_->Clear(); | |
| 929 } | 963 } |
| 930 | 964 |
| 931 // static | 965 // static |
| 932 TaskManager* TaskManager::GetInstance() { | 966 TaskManager* TaskManager::GetInstance() { |
| 933 return Singleton<TaskManager>::get(); | 967 return Singleton<TaskManager>::get(); |
| 934 } | 968 } |
| 935 | 969 |
| 936 void TaskManager::OpenAboutMemory() { | 970 void TaskManager::OpenAboutMemory() { |
| 937 Browser* browser = BrowserList::GetLastActive(); | 971 Browser* browser = BrowserList::GetLastActive(); |
| 938 | 972 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 972 MetricsMap::const_iterator iter = metrics_map_.find(handle); | 1006 MetricsMap::const_iterator iter = metrics_map_.find(handle); |
| 973 if (iter == metrics_map_.end()) | 1007 if (iter == metrics_map_.end()) |
| 974 return false; | 1008 return false; |
| 975 | 1009 |
| 976 if (!iter->second->GetMemoryBytes(&usage->first, &usage->second)) | 1010 if (!iter->second->GetMemoryBytes(&usage->first, &usage->second)) |
| 977 return false; | 1011 return false; |
| 978 | 1012 |
| 979 memory_usage_map_.insert(std::make_pair(handle, *usage)); | 1013 memory_usage_map_.insert(std::make_pair(handle, *usage)); |
| 980 return true; | 1014 return true; |
| 981 } | 1015 } |
| OLD | NEW |