| 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" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/nullable_string16.h" | 12 #include "base/nullable_string16.h" |
| 13 #include "base/string16.h" | 13 #include "base/string16.h" |
| 14 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
| 15 #include "webkit/dom_storage/dom_storage_database.h" | 15 #include "webkit/dom_storage/dom_storage_database.h" |
| 16 #include "webkit/dom_storage/dom_storage_types.h" | 16 #include "webkit/dom_storage/dom_storage_types.h" |
| 17 | 17 |
| 18 namespace dom_storage { | 18 namespace dom_storage { |
| 19 | 19 |
| 20 class DomStorageMap; | 20 class DomStorageMap; |
| 21 class DomStorageTaskRunner; | 21 class DomStorageTaskRunner; |
| 22 class SessionStorageDatabase; |
| 22 | 23 |
| 23 // Container for a per-origin Map of key/value pairs potentially | 24 // Container for a per-origin Map of key/value pairs potentially |
| 24 // backed by storage on disk and lazily commits changes to disk. | 25 // backed by storage on disk and lazily commits changes to disk. |
| 25 // See class comments for DomStorageContext for a larger overview. | 26 // See class comments for DomStorageContext for a larger overview. |
| 26 class DomStorageArea | 27 class DomStorageArea |
| 27 : public base::RefCountedThreadSafe<DomStorageArea> { | 28 : public base::RefCountedThreadSafe<DomStorageArea> { |
| 28 | 29 |
| 29 public: | 30 public: |
| 30 static const FilePath::CharType kDatabaseFileExtension[]; | 31 static const FilePath::CharType kDatabaseFileExtension[]; |
| 31 static FilePath DatabaseFileNameFromOrigin(const GURL& origin); | 32 static FilePath DatabaseFileNameFromOrigin(const GURL& origin); |
| 32 static GURL OriginFromDatabaseFileName(const FilePath& file_name); | 33 static GURL OriginFromDatabaseFileName(const FilePath& file_name); |
| 33 | 34 |
| 35 // Local storage backed on disk. |
| 34 DomStorageArea(int64 namespace_id, | 36 DomStorageArea(int64 namespace_id, |
| 35 const GURL& origin, | 37 const GURL& origin, |
| 36 const FilePath& directory, | 38 const FilePath& directory, |
| 37 DomStorageTaskRunner* task_runner); | 39 DomStorageTaskRunner* task_runner); |
| 38 | 40 |
| 41 // Session storage backed on disk. |
| 42 DomStorageArea(int64 namespace_id, |
| 43 const GURL& origin, |
| 44 SessionStorageDatabase* session_storage_backing, |
| 45 DomStorageTaskRunner* task_runner); |
| 46 |
| 47 // Local storage or session storage in memory. |
| 48 DomStorageArea(int64 namespace_id, |
| 49 const GURL& origin, |
| 50 DomStorageTaskRunner* task_runner); |
| 51 |
| 39 const GURL& origin() const { return origin_; } | 52 const GURL& origin() const { return origin_; } |
| 40 int64 namespace_id() const { return namespace_id_; } | 53 int64 namespace_id() const { return namespace_id_; } |
| 41 | 54 |
| 42 unsigned Length(); | 55 unsigned Length(); |
| 43 NullableString16 Key(unsigned index); | 56 NullableString16 Key(unsigned index); |
| 44 NullableString16 GetItem(const string16& key); | 57 NullableString16 GetItem(const string16& key); |
| 45 bool SetItem(const string16& key, const string16& value, | 58 bool SetItem(const string16& key, const string16& value, |
| 46 NullableString16* old_value); | 59 NullableString16* old_value); |
| 47 bool RemoveItem(const string16& key, string16* old_value); | 60 bool RemoveItem(const string16& key, string16* old_value); |
| 48 bool Clear(); | 61 bool Clear(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 // Post tasks to defer writing a batch of changed values to | 106 // Post tasks to defer writing a batch of changed values to |
| 94 // 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 |
| 95 // task sequence when complete. | 108 // task sequence when complete. |
| 96 CommitBatch* CreateCommitBatchIfNeeded(); | 109 CommitBatch* CreateCommitBatchIfNeeded(); |
| 97 void OnCommitTimer(); | 110 void OnCommitTimer(); |
| 98 void CommitChanges(); | 111 void CommitChanges(); |
| 99 void OnCommitComplete(); | 112 void OnCommitComplete(); |
| 100 | 113 |
| 101 void ShutdownInCommitSequence(); | 114 void ShutdownInCommitSequence(); |
| 102 | 115 |
| 116 DomStorageDatabase* GetBacking() const; |
| 117 |
| 103 int64 namespace_id_; | 118 int64 namespace_id_; |
| 104 GURL origin_; | 119 GURL origin_; |
| 105 FilePath directory_; | 120 FilePath directory_; |
| 106 scoped_refptr<DomStorageTaskRunner> task_runner_; | 121 scoped_refptr<DomStorageTaskRunner> task_runner_; |
| 107 scoped_refptr<DomStorageMap> map_; | 122 scoped_refptr<DomStorageMap> map_; |
| 108 scoped_ptr<DomStorageDatabase> backing_; | 123 scoped_ptr<DomStorageDatabase> backing_; |
| 124 scoped_refptr<SessionStorageDatabase> session_storage_backing_; |
| 109 bool is_initial_import_done_; | 125 bool is_initial_import_done_; |
| 110 bool is_shutdown_; | 126 bool is_shutdown_; |
| 127 bool is_shallow_copy_; |
| 111 scoped_ptr<CommitBatch> commit_batch_; | 128 scoped_ptr<CommitBatch> commit_batch_; |
| 112 scoped_ptr<CommitBatch> in_flight_commit_batch_; | 129 scoped_ptr<CommitBatch> in_flight_commit_batch_; |
| 113 }; | 130 }; |
| 114 | 131 |
| 115 } // namespace dom_storage | 132 } // namespace dom_storage |
| 116 | 133 |
| 117 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_AREA_H_ | 134 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_AREA_H_ |
| OLD | NEW |