| Index: chrome/browser/task_manager/task_manager.cc
|
| ===================================================================
|
| --- chrome/browser/task_manager/task_manager.cc (revision 62984)
|
| +++ chrome/browser/task_manager/task_manager.cc (working copy)
|
| @@ -70,7 +70,8 @@
|
| ////////////////////////////////////////////////////////////////////////////////
|
|
|
| TaskManagerModel::TaskManagerModel(TaskManager* task_manager)
|
| - : update_state_(IDLE),
|
| + : update_requests_(0),
|
| + update_state_(IDLE),
|
| goat_salt_(rand()) {
|
|
|
| TaskManagerBrowserProcessResourceProvider* browser_provider =
|
| @@ -115,13 +116,17 @@
|
| }
|
|
|
| string16 TaskManagerModel::GetResourceTitle(int index) const {
|
| - DCHECK(index < ResourceCount());
|
| + CHECK(index < ResourceCount());
|
| return WideToUTF16Hack(resources_[index]->GetTitle());
|
| }
|
|
|
| +int64 TaskManagerModel::GetNetworkUsage(int index) const {
|
| + CHECK(index < ResourceCount());
|
| + return GetNetworkUsage(resources_[index]);
|
| +}
|
| +
|
| string16 TaskManagerModel::GetResourceNetworkUsage(int index) const {
|
| - DCHECK(index < ResourceCount());
|
| - int64 net_usage = GetNetworkUsage(resources_[index]);
|
| + int64 net_usage = GetNetworkUsage(index);
|
| if (net_usage == -1)
|
| return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT);
|
| if (net_usage == 0)
|
| @@ -132,8 +137,13 @@
|
| return base::i18n::GetDisplayStringInLTRDirectionality(net_byte);
|
| }
|
|
|
| +double TaskManagerModel::GetCPUUsage(int index) const {
|
| + CHECK(index < ResourceCount());
|
| + return GetCPUUsage(resources_[index]);
|
| +}
|
| +
|
| string16 TaskManagerModel::GetResourceCPUUsage(int index) const {
|
| - DCHECK(index < ResourceCount());
|
| + CHECK(index < ResourceCount());
|
| return WideToUTF16Hack(StringPrintf(
|
| #if defined(OS_MACOSX)
|
| // Activity Monitor shows %cpu with one decimal digit -- be
|
| @@ -165,19 +175,23 @@
|
| return GetMemCellText(phys_mem);
|
| }
|
|
|
| +int TaskManagerModel::GetProcessId(int index) const {
|
| + CHECK(index < ResourceCount());
|
| + return base::GetProcId(resources_[index]->GetProcess());
|
| +}
|
| +
|
| string16 TaskManagerModel::GetResourceProcessId(int index) const {
|
| - DCHECK(index < ResourceCount());
|
| - return base::IntToString16(base::GetProcId(resources_[index]->GetProcess()));
|
| + return base::IntToString16(GetProcessId(index));
|
| }
|
|
|
| string16 TaskManagerModel::GetResourceGoatsTeleported(int index) const {
|
| - DCHECK(index < ResourceCount());
|
| + CHECK(index < ResourceCount());
|
| return base::FormatNumber(GetGoatsTeleported(index));
|
| }
|
|
|
| string16 TaskManagerModel::GetResourceWebCoreImageCacheSize(
|
| int index) const {
|
| - DCHECK(index < ResourceCount());
|
| + CHECK(index < ResourceCount());
|
| if (!resources_[index]->ReportsCacheStats())
|
| return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT);
|
| const WebKit::WebCache::ResourceTypeStats stats(
|
| @@ -187,7 +201,7 @@
|
|
|
| string16 TaskManagerModel::GetResourceWebCoreScriptsCacheSize(
|
| int index) const {
|
| - DCHECK(index < ResourceCount());
|
| + CHECK(index < ResourceCount());
|
| if (!resources_[index]->ReportsCacheStats())
|
| return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT);
|
| const WebKit::WebCache::ResourceTypeStats stats(
|
| @@ -197,7 +211,7 @@
|
|
|
| string16 TaskManagerModel::GetResourceWebCoreCSSCacheSize(
|
| int index) const {
|
| - DCHECK(index < ResourceCount());
|
| + CHECK(index < ResourceCount());
|
| if (!resources_[index]->ReportsCacheStats())
|
| return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT);
|
| const WebKit::WebCache::ResourceTypeStats stats(
|
| @@ -206,7 +220,7 @@
|
| }
|
|
|
| string16 TaskManagerModel::GetResourceSqliteMemoryUsed(int index) const {
|
| - DCHECK(index < ResourceCount());
|
| + CHECK(index < ResourceCount());
|
| if (!resources_[index]->ReportsSqliteMemoryUsed())
|
| return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT);
|
| return GetMemCellText(resources_[index]->SqliteMemoryUsedBytes());
|
| @@ -226,7 +240,7 @@
|
| }
|
|
|
| bool TaskManagerModel::IsResourceFirstInGroup(int index) const {
|
| - DCHECK(index < ResourceCount());
|
| + CHECK(index < ResourceCount());
|
| TaskManager::Resource* resource = resources_[index];
|
| GroupMap::const_iterator iter = group_map_.find(resource->GetProcess());
|
| DCHECK(iter != group_map_.end());
|
| @@ -235,7 +249,7 @@
|
| }
|
|
|
| SkBitmap TaskManagerModel::GetResourceIcon(int index) const {
|
| - DCHECK(index < ResourceCount());
|
| + CHECK(index < ResourceCount());
|
| SkBitmap icon = resources_[index]->GetIcon();
|
| if (!icon.isNull())
|
| return icon;
|
| @@ -247,7 +261,7 @@
|
|
|
| std::pair<int, int> TaskManagerModel::GetGroupRangeForResource(int index)
|
| const {
|
| - DCHECK(index < ResourceCount());
|
| + CHECK(index < ResourceCount());
|
| TaskManager::Resource* resource = resources_[index];
|
| GroupMap::const_iterator group_iter =
|
| group_map_.find(resource->GetProcess());
|
| @@ -267,7 +281,7 @@
|
| }
|
|
|
| int TaskManagerModel::CompareValues(int row1, int row2, int col_id) const {
|
| - DCHECK(row1 < ResourceCount() && row2 < ResourceCount());
|
| + CHECK(row1 < ResourceCount() && row2 < ResourceCount());
|
| switch (col_id) {
|
| case IDS_TASK_MANAGER_PAGE_COLUMN: {
|
| // Let's do the default, string compare on the resource title.
|
| @@ -374,17 +388,22 @@
|
|
|
| base::ProcessHandle TaskManagerModel::GetResourceProcessHandle(int index)
|
| const {
|
| - DCHECK(index < ResourceCount());
|
| + CHECK(index < ResourceCount());
|
| return resources_[index]->GetProcess();
|
| }
|
|
|
| +TaskManager::Resource::Type TaskManagerModel::GetResourceType(int index) const {
|
| + CHECK(index < ResourceCount());
|
| + return resources_[index]->GetType();
|
| +}
|
| +
|
| TabContents* TaskManagerModel::GetResourceTabContents(int index) const {
|
| - DCHECK(index < ResourceCount());
|
| + CHECK(index < ResourceCount());
|
| return resources_[index]->GetTabContents();
|
| }
|
|
|
| const Extension* TaskManagerModel::GetResourceExtension(int index) const {
|
| - DCHECK(index < ResourceCount());
|
| + CHECK(index < ResourceCount());
|
| return resources_[index]->GetExtension();
|
| }
|
|
|
| @@ -482,6 +501,12 @@
|
| }
|
|
|
| void TaskManagerModel::StartUpdating() {
|
| + // Multiple StartUpdating requests may come in, and we only need to take
|
| + // action the first time.
|
| + update_requests_++;
|
| + if (update_requests_ > 1)
|
| + return;
|
| + DCHECK_EQ(1, update_requests_);
|
| DCHECK_NE(TASK_PENDING, update_state_);
|
|
|
| // If update_state_ is STOPPING, it means a task is still pending. Setting
|
| @@ -508,6 +533,13 @@
|
| }
|
|
|
| void TaskManagerModel::StopUpdating() {
|
| + // Don't actually stop updating until we have heard as many calls as those
|
| + // to StartUpdating.
|
| + update_requests_--;
|
| + if (update_requests_ > 0)
|
| + return;
|
| + // Make sure that update_requests_ cannot go negative.
|
| + CHECK_EQ(0, update_requests_);
|
| DCHECK_EQ(TASK_PENDING, update_state_);
|
| update_state_ = STOPPING;
|
|
|
| @@ -522,6 +554,9 @@
|
| BrowserThread::IO, FROM_HERE,
|
| NewRunnableMethod(
|
| this, &TaskManagerModel::UnregisterForJobDoneNotifications));
|
| +
|
| + // Must clear the resources before the next attempt to start updating.
|
| + Clear();
|
| }
|
|
|
| void TaskManagerModel::AddResourceProvider(
|
| @@ -925,7 +960,6 @@
|
|
|
| void TaskManager::OnWindowClosed() {
|
| model_->StopUpdating();
|
| - model_->Clear();
|
| }
|
|
|
| // static
|
|
|