diff options
author | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-18 17:55:19 +0000 |
---|---|---|
committer | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-18 17:55:19 +0000 |
commit | b42c296ca1a2847d66ee5b35ed7349a4bdef377f (patch) | |
tree | 00846452ad37cad5d387b8308e9b0c485cd09da9 | |
parent | f8294f38737749389e20e1b7a520fe55aa493951 (diff) | |
download | chromium_src-b42c296ca1a2847d66ee5b35ed7349a4bdef377f.zip chromium_src-b42c296ca1a2847d66ee5b35ed7349a4bdef377f.tar.gz chromium_src-b42c296ca1a2847d66ee5b35ed7349a4bdef377f.tar.bz2 |
Added a method to delete indexed databases on shutdown.
BUG=56249
TEST=IndexedDBBrowserTest.ClearLocalState
Review URL: http://codereview.chromium.org/5112001
Patch from Yulian Pastarmov <pastarmovj@google.com>.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66636 0039d316-1c4b-4281-b951-d872f2087c98
4 files changed, 61 insertions, 0 deletions
diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc index bf1a52f..33659d0 100644 --- a/chrome/browser/browser_process_impl.cc +++ b/chrome/browser/browser_process_impl.cc @@ -30,6 +30,7 @@ #include "chrome/browser/google/google_url_tracker.h" #include "chrome/browser/icon_manager.h" #include "chrome/browser/in_process_webkit/dom_storage_context.h" +#include "chrome/browser/in_process_webkit/indexed_db_context.h" #include "chrome/browser/intranet_redirect_detector.h" #include "chrome/browser/io_thread.h" #include "chrome/browser/metrics/metrics_service.h" @@ -505,6 +506,7 @@ void BrowserProcessImpl::ClearLocalState(const FilePath& profile_path) { SQLitePersistentCookieStore::ClearLocalState(profile_path.Append( chrome::kCookieFilename)); DOMStorageContext::ClearLocalState(profile_path, chrome::kExtensionScheme); + IndexedDBContext::ClearLocalState(profile_path, chrome::kExtensionScheme); webkit_database::DatabaseTracker::ClearLocalState(profile_path); ChromeAppCacheService::ClearLocalState(profile_path); } diff --git a/chrome/browser/in_process_webkit/indexed_db_browsertest.cc b/chrome/browser/in_process_webkit/indexed_db_browsertest.cc index 0292641..052b9e6 100644 --- a/chrome/browser/in_process_webkit/indexed_db_browsertest.cc +++ b/chrome/browser/in_process_webkit/indexed_db_browsertest.cc @@ -4,8 +4,11 @@ #include "base/command_line.h" #include "base/file_path.h" +#include "base/file_util.h" #include "base/ref_counted.h" +#include "base/scoped_temp_dir.h" #include "base/utf_string_conversions.h" +#include "chrome/browser/in_process_webkit/indexed_db_context.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/ui/browser.h" #include "chrome/common/chrome_switches.h" @@ -68,3 +71,31 @@ IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, DatabaseTest) { IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, TransactionTest) { SimpleTest(testUrl(FilePath(FILE_PATH_LITERAL("transaction_test.html")))); } + +// In proc browser test is needed here because ClearLocalState indirectly calls +// WebKit's isMainThread through WebSecurityOrigin->SecurityOrigin. +IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, ClearLocalState) { + // Create test files. + ScopedTempDir temp_dir; + ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); + FilePath indexeddb_dir = temp_dir.path().Append( + IndexedDBContext::kIndexedDBDirectory); + ASSERT_TRUE(file_util::CreateDirectory(indexeddb_dir)); + + FilePath::StringType file_name_1(FILE_PATH_LITERAL("http_www.google.com_0")); + file_name_1.append(IndexedDBContext::kIndexedDBExtension); + FilePath::StringType file_name_2(FILE_PATH_LITERAL("https_www.google.com_0")); + file_name_2.append(IndexedDBContext::kIndexedDBExtension); + FilePath temp_file_path_1 = indexeddb_dir.Append(file_name_1); + FilePath temp_file_path_2 = indexeddb_dir.Append(file_name_2); + + ASSERT_EQ(1, file_util::WriteFile(temp_file_path_1, ".", 1)); + ASSERT_EQ(1, file_util::WriteFile(temp_file_path_2, "o", 1)); + + IndexedDBContext::ClearLocalState(temp_dir.path(), "https"); + + // Because we specified https for scheme to be skipped the second file + // should survive and the first go into vanity. + ASSERT_FALSE(file_util::PathExists(temp_file_path_1)); + ASSERT_TRUE(file_util::PathExists(temp_file_path_2)); +} diff --git a/chrome/browser/in_process_webkit/indexed_db_context.cc b/chrome/browser/in_process_webkit/indexed_db_context.cc index 50dcd35..8caf3be 100644 --- a/chrome/browser/in_process_webkit/indexed_db_context.cc +++ b/chrome/browser/in_process_webkit/indexed_db_context.cc @@ -4,17 +4,21 @@ #include "chrome/browser/in_process_webkit/indexed_db_context.h" +#include "base/file_util.h" #include "base/logging.h" +#include "base/string_util.h" #include "base/utf_string_conversions.h" #include "chrome/browser/in_process_webkit/webkit_context.h" #include "third_party/WebKit/WebKit/chromium/public/WebCString.h" #include "third_party/WebKit/WebKit/chromium/public/WebIDBDatabase.h" #include "third_party/WebKit/WebKit/chromium/public/WebIDBFactory.h" +#include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h" #include "third_party/WebKit/WebKit/chromium/public/WebString.h" #include "webkit/glue/webkit_glue.h" using WebKit::WebIDBDatabase; using WebKit::WebIDBFactory; +using WebKit::WebSecurityOrigin; const FilePath::CharType IndexedDBContext::kIndexedDBDirectory[] = FILE_PATH_LITERAL("IndexedDB"); @@ -43,3 +47,22 @@ FilePath IndexedDBContext::GetIndexedDBFilePath( FilePath::StringType id = webkit_glue::WebStringToFilePathString(origin_id); return storage_dir.Append(id.append(kIndexedDBExtension)); } + +// static +void IndexedDBContext::ClearLocalState(const FilePath& profile_path, + const char* url_scheme_to_be_skipped) { + file_util::FileEnumerator file_enumerator(profile_path.Append( + kIndexedDBDirectory), false, file_util::FileEnumerator::FILES); + // TODO(pastarmovj): We might need to consider exchanging this loop for + // something more efficient in the future. + for (FilePath file_path = file_enumerator.Next(); !file_path.empty(); + file_path = file_enumerator.Next()) { + if (file_path.Extension() != IndexedDBContext::kIndexedDBExtension) + continue; + WebSecurityOrigin origin = + WebSecurityOrigin::createFromDatabaseIdentifier( + webkit_glue::FilePathToWebString(file_path.BaseName())); + if (!EqualsASCII(origin.protocol(), url_scheme_to_be_skipped)) + file_util::Delete(file_path, false); + } +} diff --git a/chrome/browser/in_process_webkit/indexed_db_context.h b/chrome/browser/in_process_webkit/indexed_db_context.h index 6112d94..ca6471e 100644 --- a/chrome/browser/in_process_webkit/indexed_db_context.h +++ b/chrome/browser/in_process_webkit/indexed_db_context.h @@ -33,6 +33,11 @@ class IndexedDBContext { // Get the file name of the indexed db file for the given origin. FilePath GetIndexedDBFilePath(const string16& origin_id) const; + // Deletes all idb files except for those on the url scheme + // |url_scheme_to_be_skipped|. + static void ClearLocalState(const FilePath& profile_path, + const char* url_scheme_to_be_skipped); + private: scoped_ptr<WebKit::WebIDBFactory> idb_factory_; |