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

Unified Diff: webkit/dom_storage/session_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/session_storage_database.h
diff --git a/webkit/dom_storage/session_storage_database.h b/webkit/dom_storage/session_storage_database.h
new file mode 100644
index 0000000000000000000000000000000000000000..8bee92cbf019ab69316d5cdbc41066087caa5e43
--- /dev/null
+++ b/webkit/dom_storage/session_storage_database.h
@@ -0,0 +1,109 @@
+// Copyright (c) 2012 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.
+
+#ifndef WEBKIT_DOM_STORAGE_SESSION_STORAGE_DATABASE_H_
+#define WEBKIT_DOM_STORAGE_SESSION_STORAGE_DATABASE_H_
+#pragma once
+
+#include "webkit/dom_storage/dom_storage_database.h"
+
+namespace leveldb {
+
+struct DB;
+struct WriteBatch;
+
+} // namespace leveldb
+
+namespace dom_storage {
+
+// All DomStorageAreas for session storage share the same
+// SessionStorageDatabase.
michaeln 2012/04/12 01:48:46 It'd be great if you carved this class out of the
marja 2012/04/19 10:20:50 I'll do that next...
+class SessionStorageDatabase :
+ public DomStorageDatabase,
+ public base::RefCountedThreadSafe<SessionStorageDatabase> {
+ public:
+ explicit SessionStorageDatabase(const FilePath& file_path);
+ virtual ~SessionStorageDatabase();
+
+ // 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.
+ 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.
+ virtual bool CommitChanges(int64 namespace_id,
+ const GURL& origin,
+ bool clear_all_first,
+ const ValuesMap& changes) OVERRIDE;
+
+ // Creates a shallow copy of the map for the data associated with |origin| in
+ // |namespace_id| and associates it with |new_namespace_id|.
+ bool ShallowCopy(int64 namespace_id,
michaeln 2012/04/12 01:48:46 See comment elsewhere about having CloneNamespace
marja 2012/04/19 10:20:50 Done.
+ const GURL& origin,
+ int64 new_namespace_id);
+
+ // Creates a deep copy of the map for the data associated with |origin| in
+ // |namespace_id|.
+ bool DeepCopy(int64 namespace_id, const GURL& origin);
+
+ // Deletes the data for |namespace_id| and |origin|.
+ void DeleteOrigin(int64 namespace_id, const GURL& origin);
+
+ // Deletes the data for |namespace_id|.
+ void DeleteNamespace(int64 namespace_id);
+
+ // Deletes possible leftover data from the previous run.
+ void DeleteLeftoverData();
+
+ private:
+ virtual bool LazyOpen(bool create_if_needed);
+ virtual bool IsOpen() const;
+
+ // Helper for reading all values belonging to the map |map_id| into |result|.
+ void ReadValuesInMap(const std::string& map_id, ValuesMap* result);
+
+ // Helper for creating a new map for |area_key|. |map_id| will hold the id of
+ // the created map. Retuns true if the creation succeeded, false otherwise.
+ bool CreateNewMap(const std::string& area_key,
+ leveldb::WriteBatch* batch,
+ std::string* map_id);
+
+ // Helper for writing values into a map.
+ void WriteValuesToMap(const std::string& map_id,
+ const ValuesMap& values,
+ leveldb::WriteBatch* batch);
+
+ // Helper for decreasing the ref count of a map.
+ void DecreaseRefCount(const std::string& map_id,
+ leveldb::WriteBatch* batch);
+
+ // Helper for deleting all values in a map.
+ void DeleteValuesInMap(const std::string& map_id,
+ leveldb::WriteBatch* batch);
+
+ // Helper for deleting data for |namespace_id| and |origin|.
+ void DeleteOrigin(const std::string& namespace_id,
+ const std::string& origin,
+ leveldb::WriteBatch* batch);
+
+ // Helper for deleting data for |namespace_id|.
+ void DeleteNamespace(const std::string& namespace_id,
+ leveldb::WriteBatch* batch);
+
+ // Helper for debugging
+ void DumpData() const;
+
+ scoped_ptr<leveldb::DB> db_;
+};
+
+} // namespace dom_storage
+
+#endif // WEBKIT_DOM_STORAGE_SESSION_STORAGE_DATABASE_H_

Powered by Google App Engine
This is Rietveld 408576698