diff options
Diffstat (limited to 'chrome/browser/extensions/extension_data_deleter.cc')
-rw-r--r-- | chrome/browser/extensions/extension_data_deleter.cc | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/chrome/browser/extensions/extension_data_deleter.cc b/chrome/browser/extensions/extension_data_deleter.cc new file mode 100644 index 0000000..98cf433 --- /dev/null +++ b/chrome/browser/extensions/extension_data_deleter.cc @@ -0,0 +1,50 @@ +// 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_); +} |