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/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 11 #include "base/nullable_string16.h" | 12 #include "base/nullable_string16.h" |
| 12 #include "base/string16.h" | 13 #include "base/string16.h" |
| 13 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
| 14 #include "webkit/dom_storage/dom_storage_task_runner.h" | 15 #include "webkit/dom_storage/dom_storage_database.h" |
|
michaeln
2012/02/15 04:10:53
thnx for cleaning up this include
| |
| 15 | 16 #include "webkit/dom_storage/dom_storage_types.h" |
| 16 class FilePath; | |
| 17 class GURL; | |
| 18 | 17 |
| 19 namespace dom_storage { | 18 namespace dom_storage { |
| 20 | 19 |
| 21 class DomStorageMap; | 20 class DomStorageMap; |
| 21 class DomStorageTaskRunner; | |
| 22 | 22 |
| 23 // Container for a per-origin Map of key/value pairs potentially | 23 // Container for a per-origin Map of key/value pairs potentially |
| 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 DomStorageArea(int64 namespace_id, | 30 DomStorageArea(int64 namespace_id, |
| 31 const GURL& origin, | 31 const GURL& origin, |
| 32 const FilePath& directory, | 32 const FilePath& directory, |
| 33 DomStorageTaskRunner* task_runner); | 33 DomStorageTaskRunner* task_runner); |
| 34 | 34 |
| 35 const GURL& origin() const { return origin_; } | 35 const GURL& origin() const { return origin_; } |
| 36 int64 namespace_id() const { return namespace_id_; } | 36 int64 namespace_id() const { return namespace_id_; } |
| 37 | 37 |
| 38 unsigned Length(); | 38 unsigned Length(); |
| 39 NullableString16 Key(unsigned index); | 39 NullableString16 Key(unsigned index); |
| 40 NullableString16 GetItem(const string16& key); | 40 NullableString16 GetItem(const string16& key); |
| 41 bool SetItem(const string16& key, const string16& value, | 41 bool SetItem(const string16& key, const string16& value, |
| 42 NullableString16* old_value); | 42 NullableString16* old_value); |
| 43 bool RemoveItem(const string16& key, string16* old_value); | 43 bool RemoveItem(const string16& key, string16* old_value); |
| 44 bool Clear(); | 44 bool Clear(); |
| 45 | 45 |
| 46 DomStorageArea* ShallowCopy(int64 destination_namespace_id); | 46 DomStorageArea* ShallowCopy(int64 destination_namespace_id); |
| 47 | 47 |
| 48 private: | 48 private: |
| 49 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, DomStorageAreaBasics); | 49 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, DomStorageAreaBasics); |
| 50 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, BackingDatabaseOpened); | |
| 51 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, TestDatabaseFilePath); | |
| 50 friend class base::RefCountedThreadSafe<DomStorageArea>; | 52 friend class base::RefCountedThreadSafe<DomStorageArea>; |
| 51 | 53 |
| 54 // If we haven't done so already and this is a local storage area, | |
| 55 // will attempt to read any values for this origin currently | |
| 56 // stored on disk. | |
| 57 void InitialImportIfNeeded(); | |
| 58 | |
| 59 // Posts a task to write the set of changed values to disk. | |
| 60 void ScheduleCommitChanges(); | |
| 61 void CommitChanges(); | |
| 62 | |
| 63 static FilePath DatabaseFileNameFromOrigin(const GURL& origin); | |
| 64 | |
| 52 ~DomStorageArea(); | 65 ~DomStorageArea(); |
| 53 | 66 |
| 54 int64 namespace_id_; | 67 int64 namespace_id_; |
| 55 GURL origin_; | 68 GURL origin_; |
| 56 FilePath directory_; | 69 FilePath directory_; |
| 57 scoped_refptr<DomStorageTaskRunner> task_runner_; | 70 scoped_refptr<DomStorageTaskRunner> task_runner_; |
| 58 scoped_refptr<DomStorageMap> map_; | 71 scoped_refptr<DomStorageMap> map_; |
| 59 // TODO(benm): integrate with DomStorageDatabase to read from | 72 scoped_ptr<DomStorageDatabase> backing_; |
| 60 // and lazily write to disk. | 73 bool initial_import_done_; |
| 74 ValuesMap changed_values_; | |
| 75 bool clear_all_next_commit_; | |
| 61 }; | 76 }; |
| 62 | 77 |
| 63 } // namespace dom_storage | 78 } // namespace dom_storage |
| 64 | 79 |
| 65 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_AREA_H_ | 80 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_AREA_H_ |
| OLD | NEW |