summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/task_manager.cc7
-rw-r--r--chrome/browser/task_manager.h7
-rw-r--r--chrome/browser/task_manager_resource_providers.cc7
-rw-r--r--chrome/browser/task_manager_resource_providers.h4
-rw-r--r--chrome/browser/task_manager_unittest.cc24
5 files changed, 46 insertions, 3 deletions
diff --git a/chrome/browser/task_manager.cc b/chrome/browser/task_manager.cc
index bbc77da..5e019b8 100644
--- a/chrome/browser/task_manager.cc
+++ b/chrome/browser/task_manager.cc
@@ -635,6 +635,13 @@ void TaskManagerModel::Refresh() {
// Then we reset the current byte count.
iter->second = 0;
}
+
+ // Let resources update themselves if they need to.
+ for (ResourceList::iterator iter = resources_.begin();
+ iter != resources_.end(); ++iter) {
+ (*iter)->Refresh();
+ }
+
if (!resources_.empty()) {
FOR_EACH_OBSERVER(TaskManagerModelObserver, observer_list_,
OnItemsChanged(0, ResourceCount()));
diff --git a/chrome/browser/task_manager.h b/chrome/browser/task_manager.h
index 70c2644..0bba99e 100644
--- a/chrome/browser/task_manager.h
+++ b/chrome/browser/task_manager.h
@@ -67,6 +67,10 @@ class TaskManager {
// false (meaning we do have network usage support).
virtual void SetSupportNetworkUsage() = 0;
+ // The TaskManagerModel periodically refreshes its data and call this
+ // on all live resources.
+ virtual void Refresh() {}
+
virtual void NotifyResourceTypeStats(
const WebKit::WebCache::ResourceTypeStats& stats) {}
};
@@ -130,6 +134,7 @@ class TaskManager {
private:
FRIEND_TEST(TaskManagerTest, Basic);
FRIEND_TEST(TaskManagerTest, Resources);
+ FRIEND_TEST(TaskManagerTest, RefreshCalled);
// Obtain an instance via GetInstance().
TaskManager();
@@ -232,6 +237,8 @@ class TaskManagerModel : public URLRequestJobTracker::JobObserver,
const WebKit::WebCache::ResourceTypeStats& stats);
private:
+ FRIEND_TEST(TaskManagerTest, RefreshCalled);
+
enum UpdateState {
IDLE = 0, // Currently not updating.
TASK_PENDING, // An update task is pending.
diff --git a/chrome/browser/task_manager_resource_providers.cc b/chrome/browser/task_manager_resource_providers.cc
index 09c03e9..62af8fa 100644
--- a/chrome/browser/task_manager_resource_providers.cc
+++ b/chrome/browser/task_manager_resource_providers.cc
@@ -85,12 +85,15 @@ std::wstring TaskManagerTabContentsResource::GetTitle() const {
return l10n_util::GetStringF(IDS_TASK_MANAGER_TAB_PREFIX, tab_title);
}
-WebKit::WebCache::ResourceTypeStats
- TaskManagerTabContentsResource::GetWebCoreCacheStats() const {
+void TaskManagerTabContentsResource::Refresh() {
if (!pending_stats_update_) {
tab_contents_->render_view_host()->Send(new ViewMsg_GetCacheResourceStats);
pending_stats_update_ = true;
}
+}
+
+WebKit::WebCache::ResourceTypeStats
+ TaskManagerTabContentsResource::GetWebCoreCacheStats() const {
return stats_;
}
diff --git a/chrome/browser/task_manager_resource_providers.h b/chrome/browser/task_manager_resource_providers.h
index 3253d869..39613fd 100644
--- a/chrome/browser/task_manager_resource_providers.h
+++ b/chrome/browser/task_manager_resource_providers.h
@@ -39,6 +39,8 @@ class TaskManagerTabContentsResource : public TaskManager::Resource {
bool SupportNetworkUsage() const { return true; }
void SetSupportNetworkUsage() { }
+ virtual void Refresh();
+
virtual void NotifyResourceTypeStats(
const WebKit::WebCache::ResourceTypeStats& stats);
@@ -52,7 +54,7 @@ class TaskManagerTabContentsResource : public TaskManager::Resource {
// for an update unless a query is already outstanding.
WebKit::WebCache::ResourceTypeStats stats_;
// This flag is true if we are waiting for the renderer to report its stats.
- mutable bool pending_stats_update_;
+ bool pending_stats_update_;
DISALLOW_COPY_AND_ASSIGN(TaskManagerTabContentsResource);
};
diff --git a/chrome/browser/task_manager_unittest.cc b/chrome/browser/task_manager_unittest.cc
index 1ce3e55..f97879ea 100644
--- a/chrome/browser/task_manager_unittest.cc
+++ b/chrome/browser/task_manager_unittest.cc
@@ -16,6 +16,8 @@ namespace {
class TestResource : public TaskManager::Resource {
public:
+ TestResource() : refresh_called_(false) {}
+
virtual std::wstring GetTitle() const { return L"test title"; }
virtual SkBitmap GetIcon() const { return SkBitmap(); }
virtual base::ProcessHandle GetProcess() const {
@@ -23,6 +25,14 @@ class TestResource : public TaskManager::Resource {
}
virtual bool SupportNetworkUsage() const { return false; }
virtual void SetSupportNetworkUsage() { NOTREACHED(); }
+ virtual void Refresh() { refresh_called_ = true; }
+ bool refresh_called() const { return refresh_called_; }
+ void set_refresh_called(bool refresh_called) {
+ refresh_called_ = refresh_called;
+ }
+
+ private:
+ bool refresh_called_;
};
} // namespace
@@ -71,3 +81,17 @@ TEST_F(TaskManagerTest, Resources) {
task_manager.RemoveResource(&resource2);
EXPECT_EQ(0, model->ResourceCount());
}
+
+// Tests that the model is calling Refresh() on its resources.
+TEST_F(TaskManagerTest, RefreshCalled) {
+ MessageLoop loop;
+ TaskManager task_manager;
+ TaskManagerModel* model = task_manager.model_;
+ TestResource resource;
+
+ task_manager.AddResource(&resource);
+ ASSERT_FALSE(resource.refresh_called());
+ model->update_state_ = TaskManagerModel::TASK_PENDING;
+ model->Refresh();
+ ASSERT_TRUE(resource.refresh_called());
+}