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

Side by Side Diff: webkit/dom_storage/dom_storage_area.h

Issue 9963107: Persist sessionStorage on disk. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup. 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef WEBKIT_DOM_STORAGE_DOM_STORAGE_AREA_H_ 5 #ifndef WEBKIT_DOM_STORAGE_DOM_STORAGE_AREA_H_
6 #define WEBKIT_DOM_STORAGE_DOM_STORAGE_AREA_H_ 6 #define WEBKIT_DOM_STORAGE_DOM_STORAGE_AREA_H_
7 #pragma once 7 #pragma once
8 8
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/gtest_prod_util.h" 10 #include "base/gtest_prod_util.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
12 #include "base/nullable_string16.h" 13 #include "base/nullable_string16.h"
13 #include "base/string16.h" 14 #include "base/string16.h"
14 #include "googleurl/src/gurl.h" 15 #include "googleurl/src/gurl.h"
15 #include "webkit/dom_storage/dom_storage_database.h" 16 #include "webkit/dom_storage/dom_storage_database_adapter.h"
16 #include "webkit/dom_storage/dom_storage_types.h" 17 #include "webkit/dom_storage/dom_storage_types.h"
17 18
18 namespace dom_storage { 19 namespace dom_storage {
19 20
21 class DomStorageDatabaseAdapter;
20 class DomStorageMap; 22 class DomStorageMap;
21 class DomStorageTaskRunner; 23 class DomStorageTaskRunner;
24 class SessionStorageDatabase;
22 25
23 // Container for a per-origin Map of key/value pairs potentially 26 // Container for a per-origin Map of key/value pairs potentially
24 // backed by storage on disk and lazily commits changes to disk. 27 // backed by storage on disk and lazily commits changes to disk.
25 // See class comments for DomStorageContext for a larger overview. 28 // See class comments for DomStorageContext for a larger overview.
26 class DomStorageArea 29 class DomStorageArea
27 : public base::RefCountedThreadSafe<DomStorageArea> { 30 : public base::RefCountedThreadSafe<DomStorageArea> {
28 31
29 public: 32 public:
30 static const FilePath::CharType kDatabaseFileExtension[]; 33 static const FilePath::CharType kDatabaseFileExtension[];
31 static FilePath DatabaseFileNameFromOrigin(const GURL& origin); 34 static FilePath DatabaseFileNameFromOrigin(const GURL& origin);
32 static GURL OriginFromDatabaseFileName(const FilePath& file_name); 35 static GURL OriginFromDatabaseFileName(const FilePath& file_name);
33 36
37 // Local storage backed on disk.
34 DomStorageArea(int64 namespace_id, 38 DomStorageArea(int64 namespace_id,
35 const GURL& origin, 39 const GURL& origin,
36 const FilePath& directory, 40 const FilePath& directory,
37 DomStorageTaskRunner* task_runner); 41 DomStorageTaskRunner* task_runner);
38 42
43 // Session storage backed on disk.
44 DomStorageArea(int64 namespace_id,
45 const GURL& origin,
46 SessionStorageDatabase* session_storage_backing,
47 DomStorageTaskRunner* task_runner);
48
49 // Local storage or session storage in memory.
50 DomStorageArea(int64 namespace_id,
51 const GURL& origin,
52 DomStorageTaskRunner* task_runner);
53
39 const GURL& origin() const { return origin_; } 54 const GURL& origin() const { return origin_; }
40 int64 namespace_id() const { return namespace_id_; } 55 int64 namespace_id() const { return namespace_id_; }
41 56
42 unsigned Length(); 57 unsigned Length();
43 NullableString16 Key(unsigned index); 58 NullableString16 Key(unsigned index);
44 NullableString16 GetItem(const string16& key); 59 NullableString16 GetItem(const string16& key);
45 bool SetItem(const string16& key, const string16& value, 60 bool SetItem(const string16& key, const string16& value,
46 NullableString16* old_value); 61 NullableString16* old_value);
47 bool RemoveItem(const string16& key, string16* old_value); 62 bool RemoveItem(const string16& key, string16* old_value);
48 bool Clear(); 63 bool Clear();
(...skipping 21 matching lines...) Expand all
70 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, DomStorageAreaBasics); 85 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, DomStorageAreaBasics);
71 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, BackingDatabaseOpened); 86 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, BackingDatabaseOpened);
72 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, TestDatabaseFilePath); 87 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, TestDatabaseFilePath);
73 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, CommitTasks); 88 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, CommitTasks);
74 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, CommitChangesAtShutdown); 89 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, CommitChangesAtShutdown);
75 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, DeleteOrigin); 90 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, DeleteOrigin);
76 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, PurgeMemory); 91 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, PurgeMemory);
77 friend class base::RefCountedThreadSafe<DomStorageArea>; 92 friend class base::RefCountedThreadSafe<DomStorageArea>;
78 93
79 struct CommitBatch { 94 struct CommitBatch {
95 // When committed, Commitbatch will first commit changed_values. If
96 // changed_values_after_deep_copy is non-empty, it will deep cpoy the map,
97 // and commit changed_values_after_deep_copy.
michaeln 2012/04/22 21:43:35 see comments in the .cc file about simplifying thi
marja 2012/05/11 12:18:32 Done.
80 bool clear_all_first; 98 bool clear_all_first;
81 ValuesMap changed_values; 99 ValuesMap changed_values;
100 bool clear_all_after_deep_copy;
101 ValuesMap changed_values_after_deep_copy;
82 CommitBatch(); 102 CommitBatch();
83 ~CommitBatch(); 103 ~CommitBatch();
84 }; 104 };
85 105
86 ~DomStorageArea(); 106 ~DomStorageArea();
87 107
88 // If we haven't done so already and this is a local storage area, 108 // If we haven't done so already and this is a local storage area,
89 // will attempt to read any values for this origin currently 109 // will attempt to read any values for this origin currently
90 // stored on disk. 110 // stored on disk.
91 void InitialImportIfNeeded(); 111 void InitialImportIfNeeded();
92 112
93 // Post tasks to defer writing a batch of changed values to 113 // Post tasks to defer writing a batch of changed values to
94 // disk on the commit sequence, and to call back on the primary 114 // disk on the commit sequence, and to call back on the primary task
95 // task sequence when complete. 115 // sequence when complete.
96 CommitBatch* CreateCommitBatchIfNeeded(); 116 CommitBatch* CreateCommitBatchIfNeeded();
97 void OnCommitTimer(); 117 void OnCommitTimer();
98 void CommitChanges(); 118 void CommitChanges();
99 void OnCommitComplete(); 119 void OnCommitComplete();
100 120
101 void ShutdownInCommitSequence(); 121 void ShutdownInCommitSequence();
102 122
103 int64 namespace_id_; 123 int64 namespace_id_;
104 GURL origin_; 124 GURL origin_;
105 FilePath directory_; 125 FilePath directory_;
106 scoped_refptr<DomStorageTaskRunner> task_runner_; 126 scoped_refptr<DomStorageTaskRunner> task_runner_;
107 scoped_refptr<DomStorageMap> map_; 127 scoped_refptr<DomStorageMap> map_;
108 scoped_ptr<DomStorageDatabase> backing_; 128 scoped_ptr<DomStorageDatabaseAdapter> backing_;
129 scoped_refptr<SessionStorageDatabase> session_storage_backing_;
109 bool is_initial_import_done_; 130 bool is_initial_import_done_;
110 bool is_shutdown_; 131 bool is_shutdown_;
132 bool is_shallow_copy_;
michaeln 2012/04/22 21:43:35 not sure the is_shallow_copy_ data member is good
marja 2012/05/11 12:18:32 Gone.
111 scoped_ptr<CommitBatch> commit_batch_; 133 scoped_ptr<CommitBatch> commit_batch_;
112 scoped_ptr<CommitBatch> in_flight_commit_batch_; 134 scoped_ptr<CommitBatch> in_flight_commit_batch_;
113 }; 135 };
114 136
115 } // namespace dom_storage 137 } // namespace dom_storage
116 138
117 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_AREA_H_ 139 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_AREA_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698