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

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

Issue 10546167: Create and store persistent unique ids for sessionStorage. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: code review Created 8 years, 6 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"
(...skipping 13 matching lines...) Expand all
24 // backed by storage on disk and lazily commits changes to disk. 24 // backed by storage on disk and lazily commits changes to disk.
25 // See class comments for DomStorageContext for a larger overview. 25 // See class comments for DomStorageContext for a larger overview.
26 class DomStorageArea 26 class DomStorageArea
27 : public base::RefCountedThreadSafe<DomStorageArea> { 27 : public base::RefCountedThreadSafe<DomStorageArea> {
28 28
29 public: 29 public:
30 static const FilePath::CharType kDatabaseFileExtension[]; 30 static const FilePath::CharType kDatabaseFileExtension[];
31 static FilePath DatabaseFileNameFromOrigin(const GURL& origin); 31 static FilePath DatabaseFileNameFromOrigin(const GURL& origin);
32 static GURL OriginFromDatabaseFileName(const FilePath& file_name); 32 static GURL OriginFromDatabaseFileName(const FilePath& file_name);
33 33
34 DomStorageArea(int64 namespace_id, 34 // Local storage. Backed on disk if directory is nonempty.
35 const GURL& origin, 35 DomStorageArea(const GURL& origin,
36 const FilePath& directory, 36 const FilePath& directory,
37 DomStorageTaskRunner* task_runner); 37 DomStorageTaskRunner* task_runner);
38 38
39 // Session storage.
40 DomStorageArea(int64 namespace_id,
41 const std::string& persistent_namespace_id,
42 const GURL& origin,
43 DomStorageTaskRunner* task_runner);
44
39 const GURL& origin() const { return origin_; } 45 const GURL& origin() const { return origin_; }
40 int64 namespace_id() const { return namespace_id_; } 46 int64 namespace_id() const { return namespace_id_; }
41 47
42 // Writes a copy of the current set of values in the area to the |map|. 48 // Writes a copy of the current set of values in the area to the |map|.
43 void ExtractValues(ValuesMap* map); 49 void ExtractValues(ValuesMap* map);
44 50
45 unsigned Length(); 51 unsigned Length();
46 NullableString16 Key(unsigned index); 52 NullableString16 Key(unsigned index);
47 NullableString16 GetItem(const string16& key); 53 NullableString16 GetItem(const string16& key);
48 bool SetItem(const string16& key, const string16& value, 54 bool SetItem(const string16& key, const string16& value,
49 NullableString16* old_value); 55 NullableString16* old_value);
50 bool RemoveItem(const string16& key, string16* old_value); 56 bool RemoveItem(const string16& key, string16* old_value);
51 bool Clear(); 57 bool Clear();
52 58
53 DomStorageArea* ShallowCopy(int64 destination_namespace_id); 59 DomStorageArea* ShallowCopy(
60 int64 destination_namespace_id,
61 const std::string& destination_persistent_namespace_id);
54 62
55 bool HasUncommittedChanges() const; 63 bool HasUncommittedChanges() const;
56 64
57 // Similar to Clear() but more optimized for just deleting 65 // Similar to Clear() but more optimized for just deleting
58 // without raising events. 66 // without raising events.
59 void DeleteOrigin(); 67 void DeleteOrigin();
60 68
61 // Frees up memory when possible. Typically, this method returns 69 // Frees up memory when possible. Typically, this method returns
62 // the object to its just constructed state, however if uncommitted 70 // the object to its just constructed state, however if uncommitted
63 // changes are pending, it does nothing. 71 // changes are pending, it does nothing.
64 void PurgeMemory(); 72 void PurgeMemory();
65 73
66 // Schedules the commit of any unsaved changes and enters a 74 // Schedules the commit of any unsaved changes and enters a
67 // shutdown state such that the value getters and setters will 75 // shutdown state such that the value getters and setters will
68 // no longer do anything. 76 // no longer do anything.
69 void Shutdown(); 77 void Shutdown();
70 78
71 private: 79 private:
72 friend class DomStorageAreaTest; 80 friend class DomStorageAreaTest;
73 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, DomStorageAreaBasics); 81 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, DomStorageAreaBasics);
74 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, BackingDatabaseOpened); 82 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, BackingDatabaseOpened);
75 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, TestDatabaseFilePath); 83 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, TestDatabaseFilePath);
76 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, CommitTasks); 84 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, CommitTasks);
77 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, CommitChangesAtShutdown); 85 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, CommitChangesAtShutdown);
78 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, DeleteOrigin); 86 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, DeleteOrigin);
79 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, PurgeMemory); 87 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, PurgeMemory);
88 FRIEND_TEST_ALL_PREFIXES(DomStorageContextTest, PersistentIds);
80 friend class base::RefCountedThreadSafe<DomStorageArea>; 89 friend class base::RefCountedThreadSafe<DomStorageArea>;
81 90
82 struct CommitBatch { 91 struct CommitBatch {
83 bool clear_all_first; 92 bool clear_all_first;
84 ValuesMap changed_values; 93 ValuesMap changed_values;
85 CommitBatch(); 94 CommitBatch();
86 ~CommitBatch(); 95 ~CommitBatch();
87 }; 96 };
88 97
89 ~DomStorageArea(); 98 ~DomStorageArea();
90 99
91 // If we haven't done so already and this is a local storage area, 100 // If we haven't done so already and this is a local storage area,
92 // will attempt to read any values for this origin currently 101 // will attempt to read any values for this origin currently
93 // stored on disk. 102 // stored on disk.
94 void InitialImportIfNeeded(); 103 void InitialImportIfNeeded();
95 104
96 // Post tasks to defer writing a batch of changed values to 105 // Post tasks to defer writing a batch of changed values to
97 // disk on the commit sequence, and to call back on the primary 106 // disk on the commit sequence, and to call back on the primary
98 // task sequence when complete. 107 // task sequence when complete.
99 CommitBatch* CreateCommitBatchIfNeeded(); 108 CommitBatch* CreateCommitBatchIfNeeded();
100 void OnCommitTimer(); 109 void OnCommitTimer();
101 void CommitChanges(const CommitBatch* commit_batch); 110 void CommitChanges(const CommitBatch* commit_batch);
102 void OnCommitComplete(); 111 void OnCommitComplete();
103 112
104 void ShutdownInCommitSequence(); 113 void ShutdownInCommitSequence();
105 114
106 int64 namespace_id_; 115 int64 namespace_id_;
116 std::string persistent_namespace_id_;
107 GURL origin_; 117 GURL origin_;
108 FilePath directory_; 118 FilePath directory_;
109 scoped_refptr<DomStorageTaskRunner> task_runner_; 119 scoped_refptr<DomStorageTaskRunner> task_runner_;
110 scoped_refptr<DomStorageMap> map_; 120 scoped_refptr<DomStorageMap> map_;
111 scoped_ptr<DomStorageDatabase> backing_; 121 scoped_ptr<DomStorageDatabase> backing_;
112 bool is_initial_import_done_; 122 bool is_initial_import_done_;
113 bool is_shutdown_; 123 bool is_shutdown_;
114 scoped_ptr<CommitBatch> commit_batch_; 124 scoped_ptr<CommitBatch> commit_batch_;
115 int commit_batches_in_flight_; 125 int commit_batches_in_flight_;
116 }; 126 };
117 127
118 } // namespace dom_storage 128 } // namespace dom_storage
119 129
120 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_AREA_H_ 130 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_AREA_H_
OLDNEW
« no previous file with comments | « content/public/browser/session_storage_namespace.h ('k') | webkit/dom_storage/dom_storage_area.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698