Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Unified Diff: webkit/dom_storage/dom_storage_database.cc

Issue 9817011: DomStorage data deletion and memory purging. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webkit/dom_storage/dom_storage_database.h ('k') | webkit/dom_storage/dom_storage_database_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/dom_storage/dom_storage_database.cc
===================================================================
--- webkit/dom_storage/dom_storage_database.cc (revision 127981)
+++ webkit/dom_storage/dom_storage_database.cc (working copy)
@@ -13,6 +13,8 @@
namespace {
+const FilePath::CharType kJournal[] = FILE_PATH_LITERAL("-journal");
+
class HistogramUniquifier {
public:
static const char* name() { return "Sqlite.DomStorageDatabase.Error"; }
@@ -26,14 +28,19 @@
namespace dom_storage {
+// static
+FilePath DomStorageDatabase::GetJournalFilePath(
+ const FilePath& database_path) {
+ FilePath::StringType journal_file_name =
+ database_path.BaseName().value() + kJournal;
+ return database_path.DirName().Append(journal_file_name);
+}
+
DomStorageDatabase::DomStorageDatabase(const FilePath& file_path)
: file_path_(file_path) {
// Note: in normal use we should never get an empty backing path here.
- // However, the unit test for this class defines another constructor
- // that will bypass this check to allow an empty path that signifies
- // we should operate on an in-memory database for performance/reliability
- // reasons.
- DCHECK(!file_path_.empty());
+ // However, the unit test for this class can contruct an instance
+ // with an empty path.
Init();
}
@@ -49,9 +56,10 @@
DomStorageDatabase::~DomStorageDatabase() {
if (known_to_be_empty_ && !file_path_.empty()) {
- // Delete the db from disk, it's empty.
+ // Delete the db and any lingering journal file from disk.
Close();
file_util::Delete(file_path_, false);
+ file_util::Delete(GetJournalFilePath(file_path_), false);
}
}
@@ -74,8 +82,12 @@
bool DomStorageDatabase::CommitChanges(bool clear_all_first,
const ValuesMap& changes) {
- if (!LazyOpen(!changes.empty()))
- return false;
+ if (!LazyOpen(!changes.empty())) {
+ // If we're being asked to commit changes that will result in an
+ // empty database, we return true if the database file doesn't exist.
+ return clear_all_first && changes.empty() &&
+ !file_util::PathExists(file_path_);
+ }
bool old_known_to_be_empty = known_to_be_empty_;
sql::Transaction transaction(db_.get());
« no previous file with comments | « webkit/dom_storage/dom_storage_database.h ('k') | webkit/dom_storage/dom_storage_database_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698