diff options
-rw-r--r-- | chrome/browser/extensions/extension_browsertest.cc | 12 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_browsertest.h | 2 | ||||
-rw-r--r-- | chrome/browser/task_manager.cc | 5 | ||||
-rw-r--r-- | chrome/browser/task_manager.h | 10 | ||||
-rw-r--r-- | chrome/browser/task_manager_browsertest.cc | 33 | ||||
-rw-r--r-- | chrome/browser/task_manager_resource_providers.cc | 9 | ||||
-rw-r--r-- | chrome/browser/task_manager_resource_providers.h | 3 |
7 files changed, 69 insertions, 5 deletions
diff --git a/chrome/browser/extensions/extension_browsertest.cc b/chrome/browser/extensions/extension_browsertest.cc index 22e7829..7045cfa 100644 --- a/chrome/browser/extensions/extension_browsertest.cc +++ b/chrome/browser/extensions/extension_browsertest.cc @@ -115,6 +115,18 @@ bool ExtensionBrowserTest::InstallOrUpdateExtension( return WaitForExtensionHostsToLoad(); } +void ExtensionBrowserTest::ReloadExtension(const std::string& extension_id) { + NotificationRegistrar registrar; + registrar.Add(this, NotificationType::EXTENSION_LOADED, + NotificationService::AllSources()); + + ExtensionsService* service = browser()->profile()->GetExtensionsService(); + service->ReloadExtension(extension_id); + MessageLoop::current()->PostDelayedTask( + FROM_HERE, new MessageLoop::QuitTask, kTimeoutMs); + ui_test_utils::RunMessageLoop(); +} + void ExtensionBrowserTest::UnloadExtension(const std::string& extension_id) { ExtensionsService* service = browser()->profile()->GetExtensionsService(); service->UnloadExtension(extension_id); diff --git a/chrome/browser/extensions/extension_browsertest.h b/chrome/browser/extensions/extension_browsertest.h index 938ffe1..a79883a 100644 --- a/chrome/browser/extensions/extension_browsertest.h +++ b/chrome/browser/extensions/extension_browsertest.h @@ -38,6 +38,8 @@ class ExtensionBrowserTest return InstallOrUpdateExtension(id, path, expected_change); } + void ReloadExtension(const std::string& extension_id); + void UnloadExtension(const std::string& extension_id); void UninstallExtension(const std::string& extension_id); diff --git a/chrome/browser/task_manager.cc b/chrome/browser/task_manager.cc index daf1f30..01f0f1b 100644 --- a/chrome/browser/task_manager.cc +++ b/chrome/browser/task_manager.cc @@ -337,6 +337,11 @@ TabContents* TaskManagerModel::GetResourceTabContents(int index) const { return resources_[index]->GetTabContents(); } +const Extension* TaskManagerModel::GetResourceExtension(int index) const { + DCHECK(index < ResourceCount()); + return resources_[index]->GetExtension(); +} + int64 TaskManagerModel::GetNetworkUsage(TaskManager::Resource* resource) const { int64 net_usage = GetNetworkUsageForResource(resource); diff --git a/chrome/browser/task_manager.h b/chrome/browser/task_manager.h index a667a78..0425c11 100644 --- a/chrome/browser/task_manager.h +++ b/chrome/browser/task_manager.h @@ -23,6 +23,7 @@ #include "testing/gtest/include/gtest/gtest_prod.h" #include "webkit/api/public/WebCache.h" +class Extension; class MessageLoop; class SkBitmap; class TaskManager; @@ -55,8 +56,12 @@ class TaskManager { virtual bool ReportsSqliteMemoryUsed() const { return false; } virtual size_t SqliteMemoryUsedBytes() const { return 0; } + // Return extension associated with the resource, or NULL + // if not applicable. + virtual const Extension* GetExtension() const { return NULL; } + // A helper function for ActivateFocusedTab. Returns NULL by default - // because not all resources have an assoiciated tab. + // because not all resources have an associated tab. virtual TabContents* GetTabContents() const { return NULL; } // Whether this resource does report the network usage accurately. @@ -218,6 +223,9 @@ class TaskManagerModel : public URLRequestJobTracker::JobObserver, // Returns TabContents of given resource or NULL if not applicable. TabContents* GetResourceTabContents(int index) const; + // Returns Extension of given resource or NULL if not applicable. + const Extension* GetResourceExtension(int index) const; + // JobObserver methods: void OnJobAdded(URLRequestJob* job); void OnJobRemoved(URLRequestJob* job); diff --git a/chrome/browser/task_manager_browsertest.cc b/chrome/browser/task_manager_browsertest.cc index 77a79e7..cedcc84 100644 --- a/chrome/browser/task_manager_browsertest.cc +++ b/chrome/browser/task_manager_browsertest.cc @@ -118,6 +118,39 @@ IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeExtensionChanges) { WaitForResourceChange(4); } +// Regression test for http://crbug.com/18693. +IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, ReloadExtension) { + // Show the task manager. This populates the model, and helps with debugging + // (you see the task manager). + browser()->window()->ShowTaskManager(); + + ASSERT_TRUE(LoadExtension( + test_data_dir_.AppendASCII("common").AppendASCII("background_page"))); + + // Wait until we see the loaded extension in the task manager (the three + // resources are: the browser process, New Tab Page, and the extension). + WaitForResourceChange(3); + + EXPECT_TRUE(model()->GetResourceExtension(0) == NULL); + EXPECT_TRUE(model()->GetResourceExtension(1) == NULL); + ASSERT_TRUE(model()->GetResourceExtension(2) != NULL); + + const Extension* extension = model()->GetResourceExtension(2); + + // Reload the extension a few times and make sure our resource count + // doesn't increase. + ReloadExtension(extension->id()); + EXPECT_EQ(3, model()->ResourceCount()); + extension = model()->GetResourceExtension(2); + + ReloadExtension(extension->id()); + EXPECT_EQ(3, model()->ResourceCount()); + extension = model()->GetResourceExtension(2); + + ReloadExtension(extension->id()); + EXPECT_EQ(3, model()->ResourceCount()); +} + IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, PopulateWebCacheFields) { EXPECT_EQ(0, model()->ResourceCount()); diff --git a/chrome/browser/task_manager_resource_providers.cc b/chrome/browser/task_manager_resource_providers.cc index 931d325..b9fe366 100644 --- a/chrome/browser/task_manager_resource_providers.cc +++ b/chrome/browser/task_manager_resource_providers.cc @@ -493,7 +493,7 @@ TaskManagerExtensionProcessResource::TaskManagerExtensionProcessResource( base::Process process(extension_host_->render_process_host()->process()); process_handle_ = process.handle(); pid_ = process.pid(); - std::wstring extension_name(UTF8ToWide(extension()->name())); + std::wstring extension_name(UTF8ToWide(GetExtension()->name())); DCHECK(!extension_name.empty()); // Since the extension_name will be concatenated with a prefix, we need // to explicitly set the extension_name to be LTR format if there is no @@ -522,7 +522,7 @@ base::ProcessHandle TaskManagerExtensionProcessResource::GetProcess() const { return process_handle_; } -Extension* TaskManagerExtensionProcessResource::extension() const { +const Extension* TaskManagerExtensionProcessResource::GetExtension() const { return extension_host_->extension(); } @@ -572,6 +572,8 @@ void TaskManagerExtensionProcessResourceProvider::StartUpdating() { NotificationService::AllSources()); registrar_.Add(this, NotificationType::EXTENSION_PROCESS_CRASHED, NotificationService::AllSources()); + registrar_.Add(this, NotificationType::EXTENSION_HOST_DESTROYED, + NotificationService::AllSources()); } void TaskManagerExtensionProcessResourceProvider::StopUpdating() { @@ -583,6 +585,8 @@ void TaskManagerExtensionProcessResourceProvider::StopUpdating() { NotificationService::AllSources()); registrar_.Remove(this, NotificationType::EXTENSION_PROCESS_CRASHED, NotificationService::AllSources()); + registrar_.Remove(this, NotificationType::EXTENSION_HOST_DESTROYED, + NotificationService::AllSources()); // Delete all the resources. STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end()); @@ -600,6 +604,7 @@ void TaskManagerExtensionProcessResourceProvider::Observe( AddToTaskManager(Details<ExtensionHost>(details).ptr()); break; case NotificationType::EXTENSION_PROCESS_CRASHED: + case NotificationType::EXTENSION_HOST_DESTROYED: RemoveFromTaskManager(Details<ExtensionHost>(details).ptr()); break; default: diff --git a/chrome/browser/task_manager_resource_providers.h b/chrome/browser/task_manager_resource_providers.h index df84472..fe96c9d 100644 --- a/chrome/browser/task_manager_resource_providers.h +++ b/chrome/browser/task_manager_resource_providers.h @@ -200,13 +200,12 @@ class TaskManagerExtensionProcessResource : public TaskManager::Resource { base::ProcessHandle GetProcess() const; bool SupportNetworkUsage() const { return true; } void SetSupportNetworkUsage() { NOTREACHED(); } + const Extension* GetExtension() const; // Returns the pid of the extension process. int process_id() const { return pid_; } private: - Extension* extension() const; - // The icon painted for the extension process. static SkBitmap* default_icon_; |