diff options
author | maruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-24 18:45:45 +0000 |
---|---|---|
committer | maruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-24 18:45:45 +0000 |
commit | 44d6da87c14860edf8350b4af5d66a3cf59dfda5 (patch) | |
tree | dff42211837600c4eb0af2eeecce02f278b4909a /chrome/browser/extensions | |
parent | 84e8bdeaaf5c35c0e55dd9eca21422e7bfdc588f (diff) | |
download | chromium_src-44d6da87c14860edf8350b4af5d66a3cf59dfda5.zip chromium_src-44d6da87c14860edf8350b4af5d66a3cf59dfda5.tar.gz chromium_src-44d6da87c14860edf8350b4af5d66a3cf59dfda5.tar.bz2 |
Revert r42467: "Clear cookies, local storage and databases when an extension gets uninstalled."
It introduced a memory leak, causing a regression on valgrind test: unit.
TBR=jochen
Review URL: http://codereview.chromium.org/1295001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42499 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions')
6 files changed, 0 insertions, 198 deletions
diff --git a/chrome/browser/extensions/extension_data_deleter.cc b/chrome/browser/extensions/extension_data_deleter.cc deleted file mode 100644 index 98cf433..0000000 --- a/chrome/browser/extensions/extension_data_deleter.cc +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) 2010 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. - -#include "chrome/browser/extensions/extension_data_deleter.h" - -#include "chrome/browser/profile.h" -#include "chrome/common/extensions/extension.h" -#include "net/base/cookie_monster.h" -#include "net/base/net_errors.h" -#include "webkit/database/database_util.h" - -ExtensionDataDeleter::ExtensionDataDeleter(Profile* profile, - const GURL& extension_url) { - DCHECK(profile); - webkit_context_ = profile->GetWebKitContext(); - database_tracker_ = profile->GetDatabaseTracker(); - extension_request_context_ = profile->GetRequestContextForExtensions(); - extension_url_ = extension_url; - origin_id_ = - webkit_database::DatabaseUtil::GetOriginIdentifier(extension_url_); -} - -void ExtensionDataDeleter::StartDeleting() { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); - net::CookieMonster* cookie_monster = - extension_request_context_->GetCookieStore()->GetCookieMonster(); - if (cookie_monster) - cookie_monster->DeleteAllForURL(extension_url_, true); - - ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, - NewRunnableMethod(this, - &ExtensionDataDeleter::DeleteLocalStorageOnWebkitThread)); - - ChromeThread::PostTask(ChromeThread::FILE, FROM_HERE, - NewRunnableMethod(this, - &ExtensionDataDeleter::DeleteDatabaseOnFileThread)); -} - -void ExtensionDataDeleter::DeleteDatabaseOnFileThread() { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); - int rv = database_tracker_->DeleteDataForOrigin(origin_id_, NULL); - DCHECK(rv == net::OK || rv == net::ERR_IO_PENDING); -} - -void ExtensionDataDeleter::DeleteLocalStorageOnWebkitThread() { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); - webkit_context_->dom_storage_context()->DeleteLocalStorageForOrigin( - origin_id_); -} diff --git a/chrome/browser/extensions/extension_data_deleter.h b/chrome/browser/extensions/extension_data_deleter.h deleted file mode 100644 index a886833..0000000 --- a/chrome/browser/extensions/extension_data_deleter.h +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (c) 2010 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. - -#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_DATA_DELETER_H_ -#define CHROME_BROWSER_EXTENSIONS_EXTENSION_DATA_DELETER_H_ - -#include <string> - -#include "base/ref_counted.h" -#include "chrome/browser/chrome_thread.h" -#include "chrome/browser/in_process_webkit/webkit_context.h" -#include "chrome/browser/net/url_request_context_getter.h" -#include "googleurl/src/gurl.h" -#include "webkit/database/database_tracker.h" - -class Extension; -class Profile; - -// A helper class that takes care of removing local storage, databases and -// cookies for a given extension. This is used by -// ExtensionsService::ClearExtensionData() upon uninstalling an extension. -class ExtensionDataDeleter - : public base::RefCountedThreadSafe<ExtensionDataDeleter, - ChromeThread::DeleteOnUIThread> { - public: - ExtensionDataDeleter(Profile* profile, const GURL& extension_url); - - // Start removing data. The extension should not be running when this is - // called. Cookies are deleted on the current thread, local storage and - // databases are deleted asynchronously on the webkit and file threads, - // respectively. This function must be called from the UI thread. - void StartDeleting(); - - private: - // Deletes the database for the extension. May only be called on the file - // thread. - void DeleteDatabaseOnFileThread(); - - // Deletes local storage for the extension. May only be called on the webkit - // thread. - void DeleteLocalStorageOnWebkitThread(); - - // The database context for deleting the database. - scoped_refptr<webkit_database::DatabaseTracker> database_tracker_; - - // Provides access to the extension request context. - scoped_refptr<URLRequestContextGetter> extension_request_context_; - - // The URL of the extension we're removing data for. - GURL extension_url_; - - // The security origin identifier for which we're deleting stuff. - string16 origin_id_; - - // Webkit context for accessing the DOM storage helper. - scoped_refptr<WebKitContext> webkit_context_; - - DISALLOW_COPY_AND_ASSIGN(ExtensionDataDeleter); -}; - -#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_DATA_DELETER_H_ diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc index 28ba10c..4c3e039 100644 --- a/chrome/browser/extensions/extensions_service.cc +++ b/chrome/browser/extensions/extensions_service.cc @@ -19,7 +19,6 @@ #include "chrome/browser/extensions/extension_accessibility_api.h" #include "chrome/browser/extensions/extension_bookmarks_module.h" #include "chrome/browser/extensions/extension_browser_event_router.h" -#include "chrome/browser/extensions/extension_data_deleter.h" #include "chrome/browser/extensions/extension_dom_ui.h" #include "chrome/browser/extensions/extension_history_api.h" #include "chrome/browser/extensions/extension_host.h" @@ -42,7 +41,6 @@ #include "chrome/common/json_value_serializer.h" #include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" -#include "googleurl/src/gurl.h" #include "webkit/database/database_tracker.h" #include "webkit/database/database_util.h" @@ -270,7 +268,6 @@ void ExtensionsService::UninstallExtension(const std::string& extension_id, // Callers should not send us nonexistant extensions. DCHECK(extension); - GURL extension_url(extension->url()); extension_prefs_->OnExtensionUninstalled(extension, external_uninstall); @@ -286,17 +283,7 @@ void ExtensionsService::UninstallExtension(const std::string& extension_id, ExtensionDOMUI::UnregisterChromeURLOverrides(profile_, extension->GetChromeURLOverrides()); - // TODO(mnissler, erikkay) Check whether we should really unload the extension - // first, so we we're sure it's not running while we clean up. UnloadExtension(extension_id); - - ClearExtensionData(extension_url); -} - -void ExtensionsService::ClearExtensionData(const GURL& extension_url) { - scoped_refptr<ExtensionDataDeleter> deleter( - new ExtensionDataDeleter(profile_, extension_url)); - deleter->StartDeleting(); } void ExtensionsService::EnableExtension(const std::string& extension_id) { diff --git a/chrome/browser/extensions/extensions_service.h b/chrome/browser/extensions/extensions_service.h index 413454c..86737f0 100644 --- a/chrome/browser/extensions/extensions_service.h +++ b/chrome/browser/extensions/extensions_service.h @@ -293,9 +293,6 @@ class ExtensionsService friend class ChromeThread; friend class DeleteTask<ExtensionsService>; - // Clear all persistent data that may have been stored by the extension. - void ClearExtensionData(const GURL& extension_url); - // Look up an extension by ID, optionally including either or both of enabled // and disabled extensions. Extension* GetExtensionByIdInternal(const std::string& id, diff --git a/chrome/browser/extensions/extensions_service_unittest.cc b/chrome/browser/extensions/extensions_service_unittest.cc index 7041f9a..a142ca4 100644 --- a/chrome/browser/extensions/extensions_service_unittest.cc +++ b/chrome/browser/extensions/extensions_service_unittest.cc @@ -39,8 +39,6 @@ #include "testing/platform_test.h" #include "webkit/database/database_tracker.h" #include "webkit/database/database_util.h" -#include "net/base/cookie_monster.h" -#include "net/base/cookie_options.h" namespace keys = extension_manifest_keys; @@ -223,7 +221,6 @@ class ExtensionTestingProfile : public TestingProfile { ExtensionsServiceTestBase::ExtensionsServiceTestBase() : loop_(MessageLoop::TYPE_IO), ui_thread_(ChromeThread::UI, &loop_), - webkit_thread_(ChromeThread::WEBKIT, &loop_), file_thread_(ChromeThread::FILE, &loop_) { } @@ -1263,72 +1260,6 @@ TEST_F(ExtensionsServiceTest, UninstallExtension) { EXPECT_FALSE(file_util::PathExists(extension_path)); } -// Verifies extension state is removed upon uninstall -TEST_F(ExtensionsServiceTest, ClearExtensionData) { - InitializeEmptyExtensionsService(); - - // Load a test extension. - FilePath path; - ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path)); - path = path.AppendASCII("extensions"); - path = path.AppendASCII("good.crx"); - InstallExtension(path, true); - Extension* extension = service_->GetExtensionById(good_crx, false); - ASSERT_TRUE(extension); - GURL ext_url(extension->url()); - string16 origin_id = - webkit_database::DatabaseUtil::GetOriginIdentifier(ext_url); - - // Set a cookie for the extension. - net::CookieMonster* cookie_monster = profile_ - ->GetRequestContextForExtensions()->GetCookieStore()->GetCookieMonster(); - ASSERT_TRUE(cookie_monster); - net::CookieOptions options; - cookie_monster->SetCookieWithOptions(ext_url, "dummy=value", options); - net::CookieMonster::CookieList list = - cookie_monster->GetAllCookiesForURL(ext_url); - EXPECT_EQ(1U, list.size()); - - // Open a database. - webkit_database::DatabaseTracker* db_tracker = profile_->GetDatabaseTracker(); - string16 db_name = UTF8ToUTF16("db"); - string16 description = UTF8ToUTF16("db_description"); - int64 size; - int64 available; - db_tracker->DatabaseOpened(origin_id, db_name, description, 1, &size, - &available); - db_tracker->DatabaseClosed(origin_id, db_name); - std::vector<webkit_database::OriginInfo> origins; - db_tracker->GetAllOriginsInfo(&origins); - EXPECT_EQ(1U, origins.size()); - EXPECT_EQ(origin_id, origins[0].GetOrigin()); - - // Create local storage. We only simulate this by creating the backing file - // since webkit is not initialized. - DOMStorageContext* context = - profile_->GetWebKitContext()->dom_storage_context(); - FilePath lso_path = context->GetLocalStorageFilePath(origin_id); - EXPECT_TRUE(file_util::CreateDirectory(lso_path.DirName())); - EXPECT_EQ(0, file_util::WriteFile(lso_path, NULL, 0)); - EXPECT_TRUE(file_util::PathExists(lso_path)); - - // Uninstall the extension. - service_->UninstallExtension(good_crx, false); - loop_.RunAllPending(); - - // Check that the cookie is gone. - list = cookie_monster->GetAllCookiesForURL(ext_url); - EXPECT_EQ(0U, list.size()); - - // The database should have vanished as well. - origins.clear(); - db_tracker->GetAllOriginsInfo(&origins); - EXPECT_EQ(0U, origins.size()); - - // Check that the LSO file has been removed. - EXPECT_FALSE(file_util::PathExists(lso_path)); -} - // Tests loading single extensions (like --load-extension) TEST_F(ExtensionsServiceTest, LoadExtension) { InitializeEmptyExtensionsService(); diff --git a/chrome/browser/extensions/extensions_service_unittest.h b/chrome/browser/extensions/extensions_service_unittest.h index 63bad1c..1f24fed 100644 --- a/chrome/browser/extensions/extensions_service_unittest.h +++ b/chrome/browser/extensions/extensions_service_unittest.h @@ -44,7 +44,6 @@ class ExtensionsServiceTestBase : public testing::Test { size_t total_successes_; MessageLoop loop_; ChromeThread ui_thread_; - ChromeThread webkit_thread_; ChromeThread file_thread_; }; |