OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_AREA_H_ | 5 #ifndef CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_AREA_H_ |
6 #define CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_AREA_H_ | 6 #define CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_AREA_H_ |
7 | 7 |
8 #include <string> | |
9 | |
8 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
9 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
10 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
11 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
12 #include "base/strings/nullable_string16.h" | 14 #include "base/strings/nullable_string16.h" |
13 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
14 #include "content/common/content_export.h" | 16 #include "content/common/content_export.h" |
15 #include "content/common/dom_storage/dom_storage_types.h" | 17 #include "content/common/dom_storage/dom_storage_types.h" |
16 #include "url/gurl.h" | 18 #include "url/gurl.h" |
17 | 19 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
58 base::NullableString16* old_value); | 60 base::NullableString16* old_value); |
59 bool RemoveItem(const base::string16& key, base::string16* old_value); | 61 bool RemoveItem(const base::string16& key, base::string16* old_value); |
60 bool Clear(); | 62 bool Clear(); |
61 void FastClear(); | 63 void FastClear(); |
62 | 64 |
63 DOMStorageArea* ShallowCopy( | 65 DOMStorageArea* ShallowCopy( |
64 int64 destination_namespace_id, | 66 int64 destination_namespace_id, |
65 const std::string& destination_persistent_namespace_id); | 67 const std::string& destination_persistent_namespace_id); |
66 | 68 |
67 bool HasUncommittedChanges() const; | 69 bool HasUncommittedChanges() const; |
70 void ScheduleImmediateCommit(); | |
68 | 71 |
69 // Similar to Clear() but more optimized for just deleting | 72 // Similar to Clear() but more optimized for just deleting |
70 // without raising events. | 73 // without raising events. |
71 void DeleteOrigin(); | 74 void DeleteOrigin(); |
72 | 75 |
73 // Frees up memory when possible. Typically, this method returns | 76 // Frees up memory when possible. Typically, this method returns |
74 // the object to its just constructed state, however if uncommitted | 77 // the object to its just constructed state, however if uncommitted |
75 // changes are pending, it does nothing. | 78 // changes are pending, it does nothing. |
76 void PurgeMemory(); | 79 void PurgeMemory(); |
77 | 80 |
78 // Schedules the commit of any unsaved changes and enters a | 81 // Schedules the commit of any unsaved changes and enters a |
79 // shutdown state such that the value getters and setters will | 82 // shutdown state such that the value getters and setters will |
80 // no longer do anything. | 83 // no longer do anything. |
81 void Shutdown(); | 84 void Shutdown(); |
82 | 85 |
83 // Returns true if the data is loaded in memory. | 86 // Returns true if the data is loaded in memory. |
84 bool IsLoadedInMemory() const { return is_initial_import_done_; } | 87 bool IsLoadedInMemory() const { return is_initial_import_done_; } |
85 | 88 |
86 private: | 89 private: |
87 friend class DOMStorageAreaTest; | 90 friend class DOMStorageAreaTest; |
88 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, DOMStorageAreaBasics); | 91 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, DOMStorageAreaBasics); |
89 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, BackingDatabaseOpened); | 92 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, BackingDatabaseOpened); |
90 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, TestDatabaseFilePath); | 93 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, TestDatabaseFilePath); |
91 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, CommitTasks); | 94 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, CommitTasks); |
92 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, CommitChangesAtShutdown); | 95 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, CommitChangesAtShutdown); |
93 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, DeleteOrigin); | 96 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, DeleteOrigin); |
94 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, PurgeMemory); | 97 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, PurgeMemory); |
98 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, RateLimiter); | |
95 FRIEND_TEST_ALL_PREFIXES(DOMStorageContextImplTest, PersistentIds); | 99 FRIEND_TEST_ALL_PREFIXES(DOMStorageContextImplTest, PersistentIds); |
96 friend class base::RefCountedThreadSafe<DOMStorageArea>; | 100 friend class base::RefCountedThreadSafe<DOMStorageArea>; |
97 | 101 |
102 class CONTENT_EXPORT RateLimiter { | |
103 public: | |
104 RateLimiter(size_t desired_rate, base::TimeDelta time_quantum); | |
105 | |
106 void add_samples(size_t samples); | |
107 base::TimeDelta ComputeTimeNeeded() const; | |
108 base::TimeDelta ComputeDelayNeeded( | |
109 const base::TimeDelta elapsed_time) const; | |
110 | |
111 private: | |
112 float rate_; | |
113 float samples_; | |
114 base::TimeDelta time_quantum_; | |
115 }; | |
116 | |
98 struct CommitBatch { | 117 struct CommitBatch { |
99 bool clear_all_first; | 118 bool clear_all_first; |
100 DOMStorageValuesMap changed_values; | 119 DOMStorageValuesMap changed_values; |
120 | |
101 CommitBatch(); | 121 CommitBatch(); |
102 ~CommitBatch(); | 122 ~CommitBatch(); |
123 size_t GetDataSize() const; | |
103 }; | 124 }; |
104 | 125 |
105 ~DOMStorageArea(); | 126 ~DOMStorageArea(); |
106 | 127 |
107 // If we haven't done so already and this is a local storage area, | 128 // If we haven't done so already and this is a local storage area, |
108 // will attempt to read any values for this origin currently | 129 // will attempt to read any values for this origin currently |
109 // stored on disk. | 130 // stored on disk. |
110 void InitialImportIfNeeded(); | 131 void InitialImportIfNeeded(); |
111 | 132 |
112 // Post tasks to defer writing a batch of changed values to | 133 // Post tasks to defer writing a batch of changed values to |
113 // disk on the commit sequence, and to call back on the primary | 134 // disk on the commit sequence, and to call back on the primary |
114 // task sequence when complete. | 135 // task sequence when complete. |
115 CommitBatch* CreateCommitBatchIfNeeded(); | 136 CommitBatch* CreateCommitBatchIfNeeded(); |
116 void OnCommitTimer(); | 137 void OnCommitTimer(); |
138 void PostCommitTask(); | |
117 void CommitChanges(const CommitBatch* commit_batch); | 139 void CommitChanges(const CommitBatch* commit_batch); |
118 void OnCommitComplete(); | 140 void OnCommitComplete(); |
141 base::TimeDelta ComputeCommitDelay() const; | |
119 | 142 |
120 void ShutdownInCommitSequence(); | 143 void ShutdownInCommitSequence(); |
121 | 144 |
122 int64 namespace_id_; | 145 int64 namespace_id_; |
123 std::string persistent_namespace_id_; | 146 std::string persistent_namespace_id_; |
124 GURL origin_; | 147 GURL origin_; |
125 base::FilePath directory_; | 148 base::FilePath directory_; |
126 scoped_refptr<DOMStorageTaskRunner> task_runner_; | 149 scoped_refptr<DOMStorageTaskRunner> task_runner_; |
127 scoped_refptr<DOMStorageMap> map_; | 150 scoped_refptr<DOMStorageMap> map_; |
128 scoped_ptr<DOMStorageDatabaseAdapter> backing_; | 151 scoped_ptr<DOMStorageDatabaseAdapter> backing_; |
129 scoped_refptr<SessionStorageDatabase> session_storage_backing_; | 152 scoped_refptr<SessionStorageDatabase> session_storage_backing_; |
130 bool is_initial_import_done_; | 153 bool is_initial_import_done_; |
131 bool is_shutdown_; | 154 bool is_shutdown_; |
132 scoped_ptr<CommitBatch> commit_batch_; | 155 scoped_ptr<CommitBatch> commit_batch_; |
133 int commit_batches_in_flight_; | 156 int commit_batches_in_flight_; |
157 base::TimeTicks start_time_; | |
158 RateLimiter data_rate_limiter_; | |
159 RateLimiter commit_rate_limiter_; | |
134 }; | 160 }; |
Alexei Svitkine (slow)
2015/02/17 01:05:20
Nit: Is there a reason this class doesn't have DIS
| |
135 | 161 |
136 } // namespace content | 162 } // namespace content |
137 | 163 |
138 #endif // CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_AREA_H_ | 164 #endif // CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_AREA_H_ |
OLD | NEW |