diff options
author | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-03 02:35:08 +0000 |
---|---|---|
committer | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-03 02:35:08 +0000 |
commit | 4ef795df1f1a20a0aed61979fba034d4c7bcbd8d (patch) | |
tree | 0706238073f27beaed3b420d0cd9c13d28cdb56d /webkit/database/database_tracker.cc | |
parent | 43f28f83bc268dea720843a2616058b64b3e8810 (diff) | |
download | chromium_src-4ef795df1f1a20a0aed61979fba034d4c7bcbd8d.zip chromium_src-4ef795df1f1a20a0aed61979fba034d4c7bcbd8d.tar.gz chromium_src-4ef795df1f1a20a0aed61979fba034d4c7bcbd8d.tar.bz2 |
Reland 37913. Clear local state on exit.
BUG=32719
TEST=none
Review URL: http://codereview.chromium.org/560024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37936 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/database/database_tracker.cc')
-rw-r--r-- | webkit/database/database_tracker.cc | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/webkit/database/database_tracker.cc b/webkit/database/database_tracker.cc index 01c3052..489122e 100644 --- a/webkit/database/database_tracker.cc +++ b/webkit/database/database_tracker.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// 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. @@ -14,8 +14,11 @@ #include "base/file_path.h" #include "base/file_util.h" #include "base/string_util.h" +#include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h" +#include "third_party/WebKit/WebKit/chromium/public/WebString.h" #include "webkit/database/databases_table.h" #include "webkit/database/quota_table.h" +#include "webkit/glue/webkit_glue.h" namespace webkit_database { @@ -331,4 +334,45 @@ int64 DatabaseTracker::UpdateCachedDatabaseFileSize( return new_size; } +// static +void DatabaseTracker::ClearLocalState(const FilePath& profile_path, + const char* url_scheme_to_be_skipped) { + FilePath db_dir = profile_path.Append(FilePath(kDatabaseDirectoryName)); + FilePath db_tracker = db_dir.Append(FilePath(kTrackerDatabaseFileName)); + if (file_util::DirectoryExists(db_dir) && + file_util::PathExists(db_tracker)) { + scoped_ptr<sql::Connection> db_(new sql::Connection); + if (!db_->Open(db_tracker) || + !db_->DoesTableExist("Databases")) { + db_->Close(); + file_util::Delete(db_dir, true); + return; + } else { + sql::Statement delete_statement(db_->GetCachedStatement( + SQL_FROM_HERE, "DELETE FROM Databases WHERE origin NOT LIKE ?")); + std::string filter(url_scheme_to_be_skipped); + filter += "_%"; + delete_statement.BindString(0, filter); + if (!delete_statement.Run()) { + db_->Close(); + file_util::Delete(db_dir, true); + return; + } + } + } + file_util::FileEnumerator file_enumerator(db_dir, false, + file_util::FileEnumerator::DIRECTORIES); + for (FilePath file_path = file_enumerator.Next(); !file_path.empty(); + file_path = file_enumerator.Next()) { + if (file_path.BaseName() != FilePath(kTrackerDatabaseFileName)) { + scoped_ptr<WebKit::WebSecurityOrigin> web_security_origin( + WebKit::WebSecurityOrigin::createFromDatabaseIdentifier( + webkit_glue::FilePathToWebString(file_path.BaseName()))); + if (!EqualsASCII(web_security_origin->protocol(), + url_scheme_to_be_skipped)) + file_util::Delete(file_path, true); + } + } +} + } // namespace webkit_database |