Commit abd81a52 authored by thestig@chromium.org's avatar thestig@chromium.org

Cleanup: Typedef std::pairs in TaskManager code. Also making goat teleporting thread safe!

BUG=none
TEST=none

Review URL: http://codereview.chromium.org/9565041

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124662 0039d316-1c4b-4281-b951-d872f2087c98
parent 41247fdc
......@@ -9,6 +9,7 @@
#include "base/i18n/number_formatting.h"
#include "base/i18n/rtl.h"
#include "base/process_util.h"
#include "base/rand_util.h"
#include "base/string_number_conversions.h"
#include "base/stringprintf.h"
#include "base/threading/thread.h"
......@@ -83,7 +84,7 @@ string16 FormatStatsSize(const WebKit::WebCache::ResourceTypeStat& stat) {
TaskManagerModel::TaskManagerModel(TaskManager* task_manager)
: update_requests_(0),
update_state_(IDLE),
goat_salt_(rand()),
goat_salt_(base::RandUint64()),
last_unique_id_(0) {
AddResourceProvider(
new TaskManagerBrowserProcessResourceProvider(task_manager));
......@@ -309,8 +310,8 @@ SkBitmap TaskManagerModel::GetResourceIcon(int index) const {
return *default_icon;
}
std::pair<int, int> TaskManagerModel::GetGroupRangeForResource(int index)
const {
TaskManagerModel::GroupRange
TaskManagerModel::GetGroupRangeForResource(int index) const {
CHECK_LT(index, ResourceCount());
TaskManager::Resource* resource = resources_[index];
GroupMap::const_iterator group_iter =
......@@ -337,7 +338,7 @@ int TaskManagerModel::GetGroupIndexForResource(int index) const {
group_index++;
}
DCHECK(group_index != -1);
DCHECK_NE(group_index, -1);
return group_index;
}
......@@ -498,7 +499,7 @@ bool TaskManagerModel::GetPrivateMemory(int index, size_t* result) const {
base::ProcessHandle handle = resources_[index]->GetProcess();
MemoryUsageMap::const_iterator iter = memory_usage_map_.find(handle);
if (iter == memory_usage_map_.end()) {
std::pair<size_t, size_t> usage;
MemoryUsageEntry usage;
if (!GetAndCacheMemoryMetrics(handle, &usage))
return false;
......@@ -514,7 +515,7 @@ bool TaskManagerModel::GetSharedMemory(int index, size_t* result) const {
base::ProcessHandle handle = resources_[index]->GetProcess();
MemoryUsageMap::const_iterator iter = memory_usage_map_.find(handle);
if (iter == memory_usage_map_.end()) {
std::pair<size_t, size_t> usage;
MemoryUsageEntry usage;
if (!GetAndCacheMemoryMetrics(handle, &usage))
return false;
......@@ -850,7 +851,7 @@ void TaskManagerModel::Refresh() {
return;
}
goat_salt_ = rand();
goat_salt_ = base::RandUint64();
// Compute the CPU usage values.
// Note that we compute the CPU usage for all resources (instead of doing it
......@@ -1104,9 +1105,8 @@ void TaskManager::OpenAboutMemory() {
browser->window()->Show();
}
bool TaskManagerModel::GetAndCacheMemoryMetrics(
base::ProcessHandle handle,
std::pair<size_t, size_t>* usage) const {
bool TaskManagerModel::GetAndCacheMemoryMetrics(base::ProcessHandle handle,
MemoryUsageEntry* usage) const {
MetricsMap::const_iterator iter = metrics_map_.find(handle);
if (iter == metrics_map_.end())
return false;
......
......@@ -7,7 +7,6 @@
#pragma once
#include <map>
#include <string>
#include <utility>
#include <vector>
......@@ -136,6 +135,7 @@ class TaskManager {
// Returns resource identifier that is unique within single task manager
// session (between StartUpdating and StopUpdating).
int get_unique_id() { return unique_id_; }
protected:
Resource() : unique_id_(0) {}
......@@ -263,6 +263,9 @@ class TaskManagerModelObserver {
// The model that the TaskManager is using.
class TaskManagerModel : public base::RefCountedThreadSafe<TaskManagerModel> {
public:
// (start, length)
typedef std::pair<int, int> GroupRange;
explicit TaskManagerModel(TaskManager* task_manager);
void AddObserver(TaskManagerModelObserver* observer);
......@@ -355,8 +358,8 @@ class TaskManagerModel : public base::RefCountedThreadSafe<TaskManagerModel> {
// Returns icon to be used for resource (for example a favicon).
SkBitmap GetResourceIcon(int index) const;
// Returns a pair (start, length) of the group range of resource.
std::pair<int, int> GetGroupRangeForResource(int index) const;
// Returns the group range of resource.
GroupRange GetGroupRangeForResource(int index) const;
// Returns an index of groups to which the resource belongs.
int GetGroupIndexForResource(int index) const;
......@@ -450,8 +453,9 @@ class TaskManagerModel : public base::RefCountedThreadSafe<TaskManagerModel> {
typedef std::map<base::ProcessHandle, base::ProcessMetrics*> MetricsMap;
typedef std::map<base::ProcessHandle, double> CPUUsageMap;
typedef std::map<TaskManager::Resource*, int64> ResourceValueMap;
typedef std::map<base::ProcessHandle,
std::pair<size_t, size_t> > MemoryUsageMap;
// Private memory in bytes, shared memory in bytes.
typedef std::pair<size_t, size_t> MemoryUsageEntry;
typedef std::map<base::ProcessHandle, MemoryUsageEntry> MemoryUsageMap;
// Updates the values for all rows.
void Refresh();
......@@ -487,7 +491,7 @@ class TaskManagerModel : public base::RefCountedThreadSafe<TaskManagerModel> {
// Looks up the data for |handle| and puts it in the mutable cache
// |memory_usage_map_|.
bool GetAndCacheMemoryMetrics(base::ProcessHandle handle,
std::pair<size_t, size_t>* usage) const;
MemoryUsageEntry* usage) const;
// Adds a resource provider to be managed.
void AddResourceProvider(TaskManager::ResourceProvider* provider);
......@@ -536,7 +540,7 @@ class TaskManagerModel : public base::RefCountedThreadSafe<TaskManagerModel> {
UpdateState update_state_;
// A salt lick for the goats.
int goat_salt_;
uint64 goat_salt_;
// Resource identifier that is unique within single session.
int last_unique_id_;
......
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
......@@ -69,8 +69,10 @@ class SortHelper {
model_(model) {}
bool operator()(int a, int b) {
std::pair<int, int> group_range1 = model_->GetGroupRangeForResource(a);
std::pair<int, int> group_range2 = model_->GetGroupRangeForResource(b);
TaskManagerModel::GroupRange group_range1 =
model_->GetGroupRangeForResource(a);
TaskManagerModel::GroupRange group_range2 =
model_->GetGroupRangeForResource(b);
if (group_range1 == group_range2) {
// The two rows are in the same group, sort so that items in the same
// group always appear in the same order. |ascending_| is intentionally
......@@ -359,7 +361,7 @@ class SortHelper {
if (taskManager_->IsBrowserProcess(modelIndex))
selectionContainsBrowserProcess = true;
std::pair<int, int> rangePair =
TaskManagerModel::GroupRange rangePair =
model_->GetGroupRangeForResource(modelIndex);
NSMutableIndexSet* indexSet = [NSMutableIndexSet indexSet];
for (int j = 0; j < rangePair.second; ++j)
......
......@@ -866,8 +866,10 @@ gint TaskManagerGtk::CompareImpl(GtkTreeModel* model, GtkTreeIter* a,
return model_->CompareValues(row1, row2, id);
// Otherwise, make sure grouped resources are shown together.
std::pair<int, int> group_range1 = model_->GetGroupRangeForResource(row1);
std::pair<int, int> group_range2 = model_->GetGroupRangeForResource(row2);
TaskManagerModel::GroupRange group_range1 =
model_->GetGroupRangeForResource(row1);
TaskManagerModel::GroupRange group_range2 =
model_->GetGroupRangeForResource(row2);
if (group_range1 == group_range2) {
// Sort within groups.
......@@ -929,7 +931,7 @@ void TaskManagerGtk::OnSelectionChanged(GtkTreeSelection* selection) {
AutoReset<bool> autoreset(&ignore_selection_changed_, true);
// The set of groups that should be selected.
std::set<std::pair<int, int> > ranges;
std::set<TaskManagerModel::GroupRange> ranges;
bool selection_contains_browser_process = false;
GtkTreeModel* model;
......@@ -947,7 +949,7 @@ void TaskManagerGtk::OnSelectionChanged(GtkTreeSelection* selection) {
g_list_foreach(paths, reinterpret_cast<GFunc>(gtk_tree_path_free), NULL);
g_list_free(paths);
for (std::set<std::pair<int, int> >::iterator iter = ranges.begin();
for (std::set<TaskManagerModel::GroupRange>::iterator iter = ranges.begin();
iter != ranges.end(); ++iter) {
for (int i = 0; i < iter->second; ++i) {
GtkTreePath* child_path = gtk_tree_path_new_from_indices(iter->first + i,
......
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
......@@ -170,7 +170,8 @@ SkBitmap TaskManagerTableModel::GetIcon(int row) {
void TaskManagerTableModel::GetGroupRangeForItem(int item,
views::GroupRange* range) {
std::pair<int, int> range_pair = model_->GetGroupRangeForResource(item);
TaskManagerModel::GroupRange range_pair =
model_->GetGroupRangeForResource(item);
range->start = range_pair.first;
range->length = range_pair.second;
}
......
......@@ -6,6 +6,7 @@
#include <algorithm>
#include <functional>
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/string_number_conversions.h"
......@@ -26,7 +27,7 @@
namespace {
Value* CreateColumnValue(const TaskManagerModel* tm,
const std::string column_name,
const std::string& column_name,
const int i) {
if (column_name == "uniqueId")
return Value::CreateIntegerValue(tm->GetResourceUniqueId(i));
......@@ -134,7 +135,7 @@ void CreateGroupColumnList(const TaskManagerModel* tm,
const int index,
const int length,
DictionaryValue* val) {
ListValue *list = new ListValue();
ListValue* list = new ListValue();
for (int i = index; i < (index + length); ++i) {
list->Append(CreateColumnValue(tm, column_name, i));
}
......@@ -184,9 +185,7 @@ DictionaryValue* CreateTaskGroupValue(
return val;
int index = tm->GetResourceIndexForGroup(group_index, 0);
std::pair<int, int> group_range;
group_range = tm->GetGroupRangeForResource(index);
int length = group_range.second;
int length = tm->GetGroupRangeForResource(index).second;
// Forces to set following 3 columns regardless of |enable_columns|.
val->SetInteger("index", index);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment