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 30 matching lines...) Expand all Loading... |
41 unsigned Length(); | 41 unsigned Length(); |
42 NullableString16 Key(unsigned index); | 42 NullableString16 Key(unsigned index); |
43 NullableString16 GetItem(const string16& key); | 43 NullableString16 GetItem(const string16& key); |
44 bool SetItem(const string16& key, const string16& value, | 44 bool SetItem(const string16& key, const string16& value, |
45 NullableString16* old_value); | 45 NullableString16* old_value); |
46 bool RemoveItem(const string16& key, string16* old_value); | 46 bool RemoveItem(const string16& key, string16* old_value); |
47 bool Clear(); | 47 bool Clear(); |
48 | 48 |
49 DomStorageArea* ShallowCopy(int64 destination_namespace_id); | 49 DomStorageArea* ShallowCopy(int64 destination_namespace_id); |
50 | 50 |
| 51 // Schedules the commit of any unsaved changes and enters a |
| 52 // shutdown state such that the value getters and setters will |
| 53 // no longer do anything. |
| 54 void Shutdown(); |
| 55 |
51 private: | 56 private: |
| 57 friend class DomStorageAreaTest; |
52 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, DomStorageAreaBasics); | 58 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, DomStorageAreaBasics); |
53 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, BackingDatabaseOpened); | 59 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, BackingDatabaseOpened); |
54 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, TestDatabaseFilePath); | 60 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, TestDatabaseFilePath); |
| 61 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, CommitTasks); |
| 62 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, CommitChangesAtShutdown); |
55 friend class base::RefCountedThreadSafe<DomStorageArea>; | 63 friend class base::RefCountedThreadSafe<DomStorageArea>; |
56 | 64 |
| 65 struct CommitBatch { |
| 66 bool clear_all_first; |
| 67 ValuesMap changed_values; |
| 68 CommitBatch(); |
| 69 ~CommitBatch(); |
| 70 }; |
| 71 |
| 72 ~DomStorageArea(); |
| 73 |
57 // If we haven't done so already and this is a local storage area, | 74 // If we haven't done so already and this is a local storage area, |
58 // will attempt to read any values for this origin currently | 75 // will attempt to read any values for this origin currently |
59 // stored on disk. | 76 // stored on disk. |
60 void InitialImportIfNeeded(); | 77 void InitialImportIfNeeded(); |
61 | 78 |
62 // Posts a task to write the set of changed values to disk. | 79 // Post tasks to defer writing a batch of changed values to |
63 void ScheduleCommitChanges(); | 80 // disk on the commit sequence, and to call back on the main |
| 81 // task sequence when complete. |
| 82 CommitBatch* CreateCommitBatchIfNeeded(); |
| 83 void OnCommitTimer(); |
64 void CommitChanges(); | 84 void CommitChanges(); |
| 85 void OnCommitComplete(); |
65 | 86 |
66 ~DomStorageArea(); | 87 void ShutdownInCommitSequence(); |
67 | 88 |
68 int64 namespace_id_; | 89 int64 namespace_id_; |
69 GURL origin_; | 90 GURL origin_; |
70 FilePath directory_; | 91 FilePath directory_; |
71 scoped_refptr<DomStorageTaskRunner> task_runner_; | 92 scoped_refptr<DomStorageTaskRunner> task_runner_; |
72 scoped_refptr<DomStorageMap> map_; | 93 scoped_refptr<DomStorageMap> map_; |
73 scoped_ptr<DomStorageDatabase> backing_; | 94 scoped_ptr<DomStorageDatabase> backing_; |
74 bool initial_import_done_; | 95 bool is_initial_import_done_; |
75 ValuesMap changed_values_; | 96 bool is_shutdown_; |
76 bool clear_all_next_commit_; | 97 scoped_ptr<CommitBatch> commit_batch_; |
77 bool commit_in_flight_; | 98 scoped_ptr<CommitBatch> in_flight_commit_batch_; |
78 }; | 99 }; |
79 | 100 |
80 } // namespace dom_storage | 101 } // namespace dom_storage |
81 | 102 |
82 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_AREA_H_ | 103 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_AREA_H_ |
OLD | NEW |