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

Unified Diff: webkit/dom_storage/dom_storage_database.h

Issue 9963107: Persist sessionStorage on disk. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 8 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
Index: webkit/dom_storage/dom_storage_database.h
diff --git a/webkit/dom_storage/dom_storage_database.h b/webkit/dom_storage/dom_storage_database.h
index 5d0d9ed8d4431b9ddde9c0a1d1cb6dc46c6cc9f3..d0dbddf5a1daff2747a98eeb958938428d82481d 100644
--- a/webkit/dom_storage/dom_storage_database.h
+++ b/webkit/dom_storage/dom_storage_database.h
@@ -13,39 +13,81 @@
#include "base/memory/scoped_ptr.h"
#include "base/nullable_string16.h"
#include "base/string16.h"
+#include "googleurl/src/gurl.h"
#include "sql/connection.h"
#include "webkit/dom_storage/dom_storage_types.h"
namespace dom_storage {
-// Represents a SQLite based backing for DOM storage data. This
-// class is designed to be used on a single thread.
class DomStorageDatabase {
public:
+ DomStorageDatabase(const FilePath& file_path);
+ virtual ~DomStorageDatabase();
+
+ // Reads all the key, value pairs stored for |namespace_id| and |origin| in
+ // the database and returns them. |result| is assumed to be empty and any
+ // duplicate keys will be overwritten. If the database exists on disk then it
+ // will be opened. If it does not exist then it will not be created and
+ // |result| will be unmodified.
+ virtual void ReadAllValues(int64 namespace_id,
michaeln 2012/04/12 01:48:46 I think this existing class for localstorage backe
marja 2012/04/19 10:20:50 Done. Though, the DomStorageArea still has 2 point
+ const GURL& origin,
+ ValuesMap* result) = 0;
+
+ // Updates the backing database. Will remove all keys before updating
+ // the database if |clear_all_first| is set. Then all entries in
+ // |changes| will be examined - keys mapped to a null NullableString16
+ // will be removed and all others will be inserted/updated as appropriate.
+ virtual bool CommitChanges(int64 namespace_id,
+ const GURL& origin,
+ bool clear_all_first,
+ const ValuesMap& changes) = 0;
+
+ // Simple getter for the path we were constructed with.
+ const FilePath& file_path() const { return file_path_; }
+
+ protected:
+ // Open the database at file_path_ if it exists already and creates it if
+ // |create_if_needed| is true.
+ // Ensures we are at the correct database version and creates or updates
+ // tables as necessary. Returns false on failure.
+ virtual bool LazyOpen(bool create_if_needed) = 0;
+
+ virtual bool IsOpen() const = 0;
+
+ FilePath file_path_;
+ bool failed_to_open_;
+};
+
+// Represents a SQLite based backing for localStorage data. This
+// class is designed to be used on a single thread.
+class LocalStorageDatabase : public DomStorageDatabase {
+ public:
static FilePath GetJournalFilePath(const FilePath& database_path);
- explicit DomStorageDatabase(const FilePath& file_path);
- virtual ~DomStorageDatabase(); // virtual for unit testing
+ explicit LocalStorageDatabase(const FilePath& file_path);
+ virtual ~LocalStorageDatabase();
// Reads all the key, value pairs stored in the database and returns
// them. |result| is assumed to be empty and any duplicate keys will
// be overwritten. If the database exists on disk then it will be
// opened. If it does not exist then it will not be created and
// |result| will be unmodified.
- void ReadAllValues(ValuesMap* result);
+ virtual void ReadAllValues(int64 namespace_id,
+ const GURL& origin,
+ ValuesMap* result) OVERRIDE;
// Updates the backing database. Will remove all keys before updating
// the database if |clear_all_first| is set. Then all entries in
// |changes| will be examined - keys mapped to a null NullableString16
// will be removed and all others will be inserted/updated as appropriate.
- bool CommitChanges(bool clear_all_first, const ValuesMap& changes);
-
- // Simple getter for the path we were constructed with.
- const FilePath& file_path() const { return file_path_; }
+ virtual bool CommitChanges(int64 namespace_id,
+ const GURL& origin,
+ bool clear_all_first,
+ const ValuesMap& changes) OVERRIDE;
protected:
// Constructor that uses an in-memory sqlite database, for testing.
- DomStorageDatabase();
+ LocalStorageDatabase();
private:
FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, SimpleOpenAndClose);
@@ -71,12 +113,11 @@ class DomStorageDatabase {
V1,
V2
};
-
// Open the database at file_path_ if it exists already and creates it if
// |create_if_needed| is true.
// Ensures we are at the correct database version and creates or updates
// tables as necessary. Returns false on failure.
- bool LazyOpen(bool create_if_needed);
+ virtual bool LazyOpen(bool create_if_needed) OVERRIDE;
// Analyses the database to verify that the connection that is open is indeed
// a valid database and works out the schema version.
@@ -100,15 +141,12 @@ class DomStorageDatabase {
bool UpgradeVersion1To2();
void Close();
- bool IsOpen() const { return db_.get() ? db_->is_open() : false; }
+ virtual bool IsOpen() const;
// Initialization code shared between the two constructors of this class.
void Init();
- // Path to the database on disk.
- const FilePath file_path_;
scoped_ptr<sql::Connection> db_;
- bool failed_to_open_;
bool tried_to_recreate_;
bool known_to_be_empty_;
};

Powered by Google App Engine
This is Rietveld 408576698