summaryrefslogtreecommitdiffstats
path: root/webkit/database
diff options
context:
space:
mode:
authorjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-06 03:08:04 +0000
committerjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-06 03:08:04 +0000
commit72cfd90fdb683cf513e2f50db4ec0488729ed0a3 (patch)
tree35cc742f0d79cd9070e003c0be0eed61304af248 /webkit/database
parent0ecf8bd18d15550e2dc744a38d1665ffc2b958bd (diff)
downloadchromium_src-72cfd90fdb683cf513e2f50db4ec0488729ed0a3.zip
chromium_src-72cfd90fdb683cf513e2f50db4ec0488729ed0a3.tar.gz
chromium_src-72cfd90fdb683cf513e2f50db4ec0488729ed0a3.tar.bz2
Delete HTML5 database in BrowsingDataRemover, part 1.
This part deletes databases except for when they're currently used by a renderer. BUG=34633 TEST=open the webkit html5 database demo, create some notes. close the tab. clear browsing data. open the demo again. notes should be gone. Review URL: http://codereview.chromium.org/570032 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38296 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/database')
-rw-r--r--webkit/database/database_tracker.cc56
-rw-r--r--webkit/database/database_tracker.h12
2 files changed, 55 insertions, 13 deletions
diff --git a/webkit/database/database_tracker.cc b/webkit/database/database_tracker.cc
index 489122e..34b2204 100644
--- a/webkit/database/database_tracker.cc
+++ b/webkit/database/database_tracker.cc
@@ -14,8 +14,7 @@
#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 "net/base/net_errors.h"
#include "webkit/database/databases_table.h"
#include "webkit/database/quota_table.h"
#include "webkit/glue/webkit_glue.h"
@@ -163,6 +162,8 @@ bool DatabaseTracker::DeleteDatabase(const string16& origin_identifier,
return false;
// Try to delete the file on the hard drive.
+ // TODO(jochen): Delete directory if this was the last database.
+ // TODO(jochen): Delete journal files associated with this database.
FilePath db_file = GetFullDBFilePath(origin_identifier, database_name);
if (file_util::PathExists(db_file) && !file_util::Delete(db_file, false))
return false;
@@ -334,9 +335,45 @@ int64 DatabaseTracker::UpdateCachedDatabaseFileSize(
return new_size;
}
+int DatabaseTracker::DeleteDataModifiedSince(
+ const base::Time& cutoff,
+ net::CompletionCallback* callback) {
+ if (!LazyInit())
+ return net::ERR_FAILED;
+
+ std::vector<string16> origins;
+ if (!databases_table_->GetAllOrigins(&origins))
+ return net::ERR_FAILED;
+ int rv = net::OK;
+ for (std::vector<string16>::const_iterator ori = origins.begin();
+ ori != origins.end(); ++ori) {
+ if (StartsWith(*ori, ASCIIToUTF16(kExtensionOriginIdentifierPrefix), true))
+ continue;
+ std::vector<DatabaseDetails> details;
+ if (!databases_table_->GetAllDatabaseDetailsForOrigin(*ori, &details)) {
+ rv = net::ERR_FAILED;
+ continue;
+ }
+ for (std::vector<DatabaseDetails>::const_iterator db = details.begin();
+ db != details.end(); ++db) {
+ // Check if the database is opened by any renderer.
+ if (database_connections_.IsDatabaseOpened(*ori, db->database_name)) {
+ // TODO(jochen): make renderer close the database.
+ rv = net::ERR_FAILED;
+ continue;
+ }
+ FilePath db_file = GetFullDBFilePath(*ori, db->database_name);
+ file_util::FileInfo file_info;
+ file_util::GetFileInfo(db_file, &file_info);
+ if (file_info.last_modified >= cutoff)
+ DeleteDatabase(*ori, db->database_name);
+ }
+ }
+ return rv;
+}
+
// static
-void DatabaseTracker::ClearLocalState(const FilePath& profile_path,
- const char* url_scheme_to_be_skipped) {
+void DatabaseTracker::ClearLocalState(const FilePath& profile_path) {
FilePath db_dir = profile_path.Append(FilePath(kDatabaseDirectoryName));
FilePath db_tracker = db_dir.Append(FilePath(kTrackerDatabaseFileName));
if (file_util::DirectoryExists(db_dir) &&
@@ -350,8 +387,8 @@ void DatabaseTracker::ClearLocalState(const FilePath& profile_path,
} 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 += "_%";
+ std::string filter(kExtensionOriginIdentifierPrefix);
+ filter += "%";
delete_statement.BindString(0, filter);
if (!delete_statement.Run()) {
db_->Close();
@@ -365,11 +402,8 @@ void DatabaseTracker::ClearLocalState(const FilePath& profile_path,
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))
+ if (!StartsWith(file_path.BaseName().ToWStringHack(),
+ ASCIIToWide(kExtensionOriginIdentifierPrefix), true))
file_util::Delete(file_path, true);
}
}
diff --git a/webkit/database/database_tracker.h b/webkit/database/database_tracker.h
index 4375a35..a64add3e 100644
--- a/webkit/database/database_tracker.h
+++ b/webkit/database/database_tracker.h
@@ -13,6 +13,8 @@
#include "base/scoped_ptr.h"
#include "base/string16.h"
#include "base/string_util.h"
+#include "base/time.h"
+#include "net/base/completion_callback.h"
#include "testing/gtest/include/gtest/gtest_prod.h"
#include "webkit/database/database_connections.h"
@@ -116,8 +118,14 @@ class DatabaseTracker
const string16& database_name);
bool DeleteOrigin(const string16& origin_identifier);
- static void ClearLocalState(const FilePath& profile_path,
- const char* url_scheme_to_be_skipped);
+ // Delete any databases that have been touched since the cutoff date that's
+ // supplied. Returns net::OK on success, net::FAILED if not all databases
+ // could be deleted, and net::ERR_IO_PENDING and |callback| is invoked upon
+ // completion.
+ int DeleteDataModifiedSince(const base::Time& cutoff,
+ net::CompletionCallback* callback);
+
+ static void ClearLocalState(const FilePath& profile_path);
private:
// Need this here to allow RefCountedThreadSafe to call ~DatabaseTracker().