Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 // Local storage. Backed on disk if directory is nonempty. | |
| 34 DomStorageArea(int64 namespace_id, | 35 DomStorageArea(int64 namespace_id, |
|
michaeln
2012/06/14 22:53:48
Can we remove the namespace_id param from this cto
marja
2012/06/15 09:17:42
Done.
| |
| 35 const GURL& origin, | 36 const GURL& origin, |
| 36 const FilePath& directory, | 37 const FilePath& directory, |
| 37 DomStorageTaskRunner* task_runner); | 38 DomStorageTaskRunner* task_runner); |
| 38 | 39 |
| 40 // Session storage. | |
| 41 DomStorageArea(int64 namespace_id, | |
| 42 const std::string& persistent_namespace_id, | |
| 43 const GURL& origin, | |
| 44 DomStorageTaskRunner* task_runner); | |
| 45 | |
| 39 const GURL& origin() const { return origin_; } | 46 const GURL& origin() const { return origin_; } |
| 40 int64 namespace_id() const { return namespace_id_; } | 47 int64 namespace_id() const { return namespace_id_; } |
| 41 | 48 |
| 42 // Writes a copy of the current set of values in the area to the |map|. | 49 // Writes a copy of the current set of values in the area to the |map|. |
| 43 void ExtractValues(ValuesMap* map); | 50 void ExtractValues(ValuesMap* map); |
| 44 | 51 |
| 45 unsigned Length(); | 52 unsigned Length(); |
| 46 NullableString16 Key(unsigned index); | 53 NullableString16 Key(unsigned index); |
| 47 NullableString16 GetItem(const string16& key); | 54 NullableString16 GetItem(const string16& key); |
| 48 bool SetItem(const string16& key, const string16& value, | 55 bool SetItem(const string16& key, const string16& value, |
| 49 NullableString16* old_value); | 56 NullableString16* old_value); |
| 50 bool RemoveItem(const string16& key, string16* old_value); | 57 bool RemoveItem(const string16& key, string16* old_value); |
| 51 bool Clear(); | 58 bool Clear(); |
| 52 | 59 |
| 53 DomStorageArea* ShallowCopy(int64 destination_namespace_id); | 60 DomStorageArea* ShallowCopy( |
| 61 int64 destination_namespace_id, | |
| 62 const std::string& destination_persistent_namespace_id); | |
| 54 | 63 |
| 55 bool HasUncommittedChanges() const; | 64 bool HasUncommittedChanges() const; |
| 56 | 65 |
| 57 // Similar to Clear() but more optimized for just deleting | 66 // Similar to Clear() but more optimized for just deleting |
| 58 // without raising events. | 67 // without raising events. |
| 59 void DeleteOrigin(); | 68 void DeleteOrigin(); |
| 60 | 69 |
| 61 // Frees up memory when possible. Typically, this method returns | 70 // Frees up memory when possible. Typically, this method returns |
| 62 // the object to its just constructed state, however if uncommitted | 71 // the object to its just constructed state, however if uncommitted |
| 63 // changes are pending, it does nothing. | 72 // changes are pending, it does nothing. |
| 64 void PurgeMemory(); | 73 void PurgeMemory(); |
| 65 | 74 |
| 66 // Schedules the commit of any unsaved changes and enters a | 75 // Schedules the commit of any unsaved changes and enters a |
| 67 // shutdown state such that the value getters and setters will | 76 // shutdown state such that the value getters and setters will |
| 68 // no longer do anything. | 77 // no longer do anything. |
| 69 void Shutdown(); | 78 void Shutdown(); |
| 70 | 79 |
| 71 private: | 80 private: |
| 72 friend class DomStorageAreaTest; | 81 friend class DomStorageAreaTest; |
| 73 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, DomStorageAreaBasics); | 82 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, DomStorageAreaBasics); |
| 74 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, BackingDatabaseOpened); | 83 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, BackingDatabaseOpened); |
| 75 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, TestDatabaseFilePath); | 84 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, TestDatabaseFilePath); |
| 76 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, CommitTasks); | 85 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, CommitTasks); |
| 77 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, CommitChangesAtShutdown); | 86 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, CommitChangesAtShutdown); |
| 78 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, DeleteOrigin); | 87 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, DeleteOrigin); |
| 79 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, PurgeMemory); | 88 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, PurgeMemory); |
| 89 FRIEND_TEST_ALL_PREFIXES(DomStorageContextTest, PersistentIds); | |
| 80 friend class base::RefCountedThreadSafe<DomStorageArea>; | 90 friend class base::RefCountedThreadSafe<DomStorageArea>; |
| 81 | 91 |
| 82 struct CommitBatch { | 92 struct CommitBatch { |
| 83 bool clear_all_first; | 93 bool clear_all_first; |
| 84 ValuesMap changed_values; | 94 ValuesMap changed_values; |
| 85 CommitBatch(); | 95 CommitBatch(); |
| 86 ~CommitBatch(); | 96 ~CommitBatch(); |
| 87 }; | 97 }; |
| 88 | 98 |
| 89 ~DomStorageArea(); | 99 ~DomStorageArea(); |
| 90 | 100 |
| 91 // If we haven't done so already and this is a local storage area, | 101 // 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 | 102 // will attempt to read any values for this origin currently |
| 93 // stored on disk. | 103 // stored on disk. |
| 94 void InitialImportIfNeeded(); | 104 void InitialImportIfNeeded(); |
| 95 | 105 |
| 96 // Post tasks to defer writing a batch of changed values to | 106 // Post tasks to defer writing a batch of changed values to |
| 97 // disk on the commit sequence, and to call back on the primary | 107 // disk on the commit sequence, and to call back on the primary |
| 98 // task sequence when complete. | 108 // task sequence when complete. |
| 99 CommitBatch* CreateCommitBatchIfNeeded(); | 109 CommitBatch* CreateCommitBatchIfNeeded(); |
| 100 void OnCommitTimer(); | 110 void OnCommitTimer(); |
| 101 void CommitChanges(const CommitBatch* commit_batch); | 111 void CommitChanges(const CommitBatch* commit_batch); |
| 102 void OnCommitComplete(); | 112 void OnCommitComplete(); |
| 103 | 113 |
| 104 void ShutdownInCommitSequence(); | 114 void ShutdownInCommitSequence(); |
| 105 | 115 |
| 106 int64 namespace_id_; | 116 int64 namespace_id_; |
| 117 std::string persistent_namespace_id_; | |
| 107 GURL origin_; | 118 GURL origin_; |
| 108 FilePath directory_; | 119 FilePath directory_; |
| 109 scoped_refptr<DomStorageTaskRunner> task_runner_; | 120 scoped_refptr<DomStorageTaskRunner> task_runner_; |
| 110 scoped_refptr<DomStorageMap> map_; | 121 scoped_refptr<DomStorageMap> map_; |
| 111 scoped_ptr<DomStorageDatabase> backing_; | 122 scoped_ptr<DomStorageDatabase> backing_; |
| 112 bool is_initial_import_done_; | 123 bool is_initial_import_done_; |
| 113 bool is_shutdown_; | 124 bool is_shutdown_; |
| 114 scoped_ptr<CommitBatch> commit_batch_; | 125 scoped_ptr<CommitBatch> commit_batch_; |
| 115 int commit_batches_in_flight_; | 126 int commit_batches_in_flight_; |
| 116 }; | 127 }; |
| 117 | 128 |
| 118 } // namespace dom_storage | 129 } // namespace dom_storage |
| 119 | 130 |
| 120 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_AREA_H_ | 131 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_AREA_H_ |
| OLD | NEW |