Commit ef72ae07 authored by pfeldman@chromium.org's avatar pfeldman@chromium.org

TaskManager: allows referencing task resources from the web ui.

BUG=102075


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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@107740 0039d316-1c4b-4281-b951-d872f2087c98
parent bb6434a0
......@@ -93,9 +93,8 @@ TaskManager.prototype = {
* Sends command to initiate resource inspection.
* @public
*/
inspect: function (resourceIndex, event) {
event.stopPropagation();
chrome.send('inspect', [resourceIndex]);
inspect: function (uniqueId) {
chrome.send('inspect', [uniqueId]);
},
/**
......
......@@ -78,7 +78,8 @@ string16 FormatStatsSize(const WebKit::WebCache::ResourceTypeStat& stat) {
TaskManagerModel::TaskManagerModel(TaskManager* task_manager)
: update_requests_(0),
update_state_(IDLE),
goat_salt_(rand()) {
goat_salt_(rand()),
last_unique_id_(0) {
AddResourceProvider(
new TaskManagerBrowserProcessResourceProvider(task_manager));
AddResourceProvider(
......@@ -118,6 +119,11 @@ void TaskManagerModel::RemoveObserver(TaskManagerModelObserver* observer) {
observer_list_.RemoveObserver(observer);
}
int TaskManagerModel::GetResourceUniqueId(int index) const {
CHECK_LT(index, ResourceCount());
return resources_[index]->get_unique_id();
}
string16 TaskManagerModel::GetResourceTitle(int index) const {
CHECK_LT(index, ResourceCount());
return resources_[index]->GetTitle();
......@@ -561,10 +567,12 @@ bool TaskManagerModel::GetV8Memory(int index, size_t* result) const {
}
bool TaskManagerModel::CanInspect(int index) const {
CHECK_LT(index, ResourceCount());
return resources_[index]->CanInspect();
}
void TaskManagerModel::Inspect(int index) const {
CHECK_LT(index, ResourceCount());
resources_[index]->Inspect();
}
......@@ -642,6 +650,8 @@ void TaskManagerModel::AddResourceProvider(
}
void TaskManagerModel::AddResource(TaskManager::Resource* resource) {
resource->unique_id_ = ++last_unique_id_;
base::ProcessHandle process = resource->GetProcess();
ResourceList* group_entries = NULL;
......@@ -767,6 +777,7 @@ void TaskManagerModel::Clear() {
FOR_EACH_OBSERVER(TaskManagerModelObserver, observer_list_,
OnItemsRemoved(0, size));
}
last_unique_id_ = 0;
}
void TaskManagerModel::ModelChanged() {
......
......@@ -131,7 +131,17 @@ class TaskManager {
TASKMANAGER_RESOURCE_TYPE_LIST(TASKMANAGER_RESOURCE_TYPE_LIST_AS_STRING)
default: return "UNKNOWN";
}
};
}
// 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) {}
private:
friend class TaskManagerModel;
int unique_id_;
};
// ResourceProviders are responsible for adding/removing resources to the task
......@@ -262,6 +272,7 @@ class TaskManagerModel : public base::RefCountedThreadSafe<TaskManagerModel> {
int64 GetNetworkUsage(int index) const;
double GetCPUUsage(int index) const;
int GetProcessId(int index) const;
int GetResourceUniqueId(int index) const;
// Methods to return formatted resource information.
string16 GetResourceTitle(int index) const;
......@@ -515,6 +526,9 @@ class TaskManagerModel : public base::RefCountedThreadSafe<TaskManagerModel> {
// A salt lick for the goats.
int goat_salt_;
// Resource identifier that is unique within single session.
int last_unique_id_;
DISALLOW_COPY_AND_ASSIGN(TaskManagerModel);
};
......
......@@ -26,8 +26,8 @@ namespace {
static Value* CreateColumnValue(const TaskManagerModel* tm,
const std::string column_name,
const int i) {
if (column_name == "resourceIndex")
return Value::CreateIntegerValue(i);
if (column_name == "uniqueId")
return Value::CreateIntegerValue(tm->GetResourceUniqueId(i));
if (column_name == "type")
return Value::CreateStringValue(
TaskManager::Resource::GetResourceTypeAsString(
......@@ -178,7 +178,7 @@ static DictionaryValue* CreateTaskGroupValue(const TaskManagerModel* tm,
CreateGroupColumnList(tm, "v8MemoryAllocatedSizeValue", index, 1, val);
// Columns which have some data in each group.
CreateGroupColumnList(tm, "resourceIndex", index, length, val);
CreateGroupColumnList(tm, "uniqueId", index, length, val);
CreateGroupColumnList(tm, "icon", index, length, val);
CreateGroupColumnList(tm, "title", index, length, val);
CreateGroupColumnList(tm, "profileName", index, length, val);
......@@ -354,11 +354,19 @@ void TaskManagerHandler::HandleKillProcess(const ListValue* indexes) {
void TaskManagerHandler::HandleInspect(const ListValue* resource_index) {
for (ListValue::const_iterator i = resource_index->begin();
i != resource_index->end(); ++i) {
int resource_index = parseIndex(*i);
if (resource_index == -1)
int unique_id = parseIndex(*i);
if (unique_id == -1)
continue;
if (model_->CanInspect(resource_index))
model_->Inspect(resource_index);
for (int resource_index = 0; resource_index < model_->ResourceCount();
++resource_index) {
if (model_->GetResourceUniqueId(resource_index) == unique_id) {
if (model_->CanInspect(resource_index))
model_->Inspect(resource_index);
break;
}
}
break;
}
}
......
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