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 #include "webkit/dom_storage/dom_storage_context.h" | 5 #include "webkit/dom_storage/dom_storage_context.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
11 #include "base/time.h" | 11 #include "base/time.h" |
12 #include "webkit/dom_storage/dom_storage_area.h" | 12 #include "webkit/dom_storage/dom_storage_area.h" |
13 #include "webkit/dom_storage/dom_storage_database.h" | |
13 #include "webkit/dom_storage/dom_storage_namespace.h" | 14 #include "webkit/dom_storage/dom_storage_namespace.h" |
14 #include "webkit/dom_storage/dom_storage_task_runner.h" | 15 #include "webkit/dom_storage/dom_storage_task_runner.h" |
15 #include "webkit/dom_storage/dom_storage_types.h" | 16 #include "webkit/dom_storage/dom_storage_types.h" |
17 #include "webkit/dom_storage/session_storage_database.h" | |
16 #include "webkit/quota/special_storage_policy.h" | 18 #include "webkit/quota/special_storage_policy.h" |
17 | 19 |
18 using file_util::FileEnumerator; | 20 using file_util::FileEnumerator; |
19 | 21 |
20 namespace dom_storage { | 22 namespace dom_storage { |
21 | 23 |
22 DomStorageContext::UsageInfo::UsageInfo() : data_size(0) {} | 24 DomStorageContext::UsageInfo::UsageInfo() : data_size(0) {} |
23 DomStorageContext::UsageInfo::~UsageInfo() {} | 25 DomStorageContext::UsageInfo::~UsageInfo() {} |
24 | 26 |
25 DomStorageContext::DomStorageContext( | 27 DomStorageContext::DomStorageContext( |
26 const FilePath& localstorage_directory, | 28 const FilePath& localstorage_directory, |
27 const FilePath& sessionstorage_directory, | 29 const FilePath& sessionstorage_directory, |
28 quota::SpecialStoragePolicy* special_storage_policy, | 30 quota::SpecialStoragePolicy* special_storage_policy, |
29 DomStorageTaskRunner* task_runner) | 31 DomStorageTaskRunner* task_runner) |
30 : localstorage_directory_(localstorage_directory), | 32 : localstorage_directory_(localstorage_directory), |
31 sessionstorage_directory_(sessionstorage_directory), | 33 sessionstorage_directory_(sessionstorage_directory), |
32 task_runner_(task_runner), | 34 task_runner_(task_runner), |
33 is_shutdown_(false), | 35 is_shutdown_(false), |
34 clear_local_state_(false), | 36 clear_local_state_(false), |
35 save_session_state_(false), | 37 save_session_state_(false), |
36 special_storage_policy_(special_storage_policy) { | 38 special_storage_policy_(special_storage_policy) { |
37 // AtomicSequenceNum starts at 0 but we want to start session | 39 // AtomicSequenceNum starts at 0 but we want to start session |
38 // namespace ids at one since zero is reserved for the | 40 // namespace ids at one since zero is reserved for the |
39 // kLocalStorageNamespaceId. | 41 // kLocalStorageNamespaceId. |
40 session_id_sequence_.GetNext(); | 42 session_id_sequence_.GetNext(); |
43 if (!sessionstorage_directory_.empty()) { | |
44 session_storage_database_ = | |
45 new SessionStorageDatabase(sessionstorage_directory_); | |
46 } | |
41 } | 47 } |
42 | 48 |
43 DomStorageContext::~DomStorageContext() { | 49 DomStorageContext::~DomStorageContext() { |
44 } | 50 } |
45 | 51 |
46 DomStorageNamespace* DomStorageContext::GetStorageNamespace( | 52 DomStorageNamespace* DomStorageContext::GetStorageNamespace( |
47 int64 namespace_id) { | 53 int64 namespace_id) { |
48 if (is_shutdown_) | 54 if (is_shutdown_) |
49 return NULL; | 55 return NULL; |
50 StorageNamespaceMap::iterator found = namespaces_.find(namespace_id); | 56 StorageNamespaceMap::iterator found = namespaces_.find(namespace_id); |
(...skipping 29 matching lines...) Expand all Loading... | |
80 info.origin = DomStorageArea::OriginFromDatabaseFileName(path); | 86 info.origin = DomStorageArea::OriginFromDatabaseFileName(path); |
81 if (include_file_info) { | 87 if (include_file_info) { |
82 FileEnumerator::FindInfo find_info; | 88 FileEnumerator::FindInfo find_info; |
83 enumerator.GetFindInfo(&find_info); | 89 enumerator.GetFindInfo(&find_info); |
84 info.data_size = FileEnumerator::GetFilesize(find_info); | 90 info.data_size = FileEnumerator::GetFilesize(find_info); |
85 info.last_modified = FileEnumerator::GetLastModifiedTime(find_info); | 91 info.last_modified = FileEnumerator::GetLastModifiedTime(find_info); |
86 } | 92 } |
87 infos->push_back(info); | 93 infos->push_back(info); |
88 } | 94 } |
89 } | 95 } |
96 // FIXME(marja): Get usage infos for sessionStorage (crbug.com/123599). | |
90 } | 97 } |
91 | 98 |
92 void DomStorageContext::DeleteOrigin(const GURL& origin) { | 99 void DomStorageContext::DeleteOrigin(const GURL& origin) { |
93 DCHECK(!is_shutdown_); | 100 DCHECK(!is_shutdown_); |
94 DomStorageNamespace* local = GetStorageNamespace(kLocalStorageNamespaceId); | 101 DomStorageNamespace* local = GetStorageNamespace(kLocalStorageNamespaceId); |
95 local->DeleteOrigin(origin); | 102 local->DeleteOrigin(origin); |
96 } | 103 } |
97 | 104 |
98 void DomStorageContext::DeleteDataModifiedSince(const base::Time& cutoff) { | 105 void DomStorageContext::DeleteDataModifiedSince(const base::Time& cutoff) { |
99 std::vector<UsageInfo> infos; | 106 std::vector<UsageInfo> infos; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
139 if (clear_local_state_ || has_session_only_origins) { | 146 if (clear_local_state_ || has_session_only_origins) { |
140 // We may have to delete something. We continue on the | 147 // We may have to delete something. We continue on the |
141 // commit sequence after area shutdown tasks have cycled | 148 // commit sequence after area shutdown tasks have cycled |
142 // thru that sequence (and closed their database files). | 149 // thru that sequence (and closed their database files). |
143 bool success = task_runner_->PostShutdownBlockingTask( | 150 bool success = task_runner_->PostShutdownBlockingTask( |
144 FROM_HERE, | 151 FROM_HERE, |
145 DomStorageTaskRunner::COMMIT_SEQUENCE, | 152 DomStorageTaskRunner::COMMIT_SEQUENCE, |
146 base::Bind(&DomStorageContext::ClearLocalStateInCommitSequence, this)); | 153 base::Bind(&DomStorageContext::ClearLocalStateInCommitSequence, this)); |
147 DCHECK(success); | 154 DCHECK(success); |
148 } | 155 } |
156 | |
157 // If the last exit was unclean, the session storage backing might contain | |
158 // leftover data. Delete it now. | |
159 // TODO(marja): When doing a session restore, protect parts of the data from | |
160 // deletion. | |
161 bool success = task_runner_->PostShutdownBlockingTask( | |
162 FROM_HERE, | |
163 DomStorageTaskRunner::COMMIT_SEQUENCE, | |
164 base::Bind(&DomStorageContext::DeleteLeftoverDataInCommitSequence, this)); | |
michaeln
2012/04/22 21:43:35
it might be premature to have this here, feels lik
marja
2012/05/11 12:18:32
Should I make it so that this CL just deletes all
michaeln
2012/05/16 08:10:55
Maybe don't try to answer this question just yet,
| |
165 DCHECK(success); | |
149 } | 166 } |
150 | 167 |
151 void DomStorageContext::AddEventObserver(EventObserver* observer) { | 168 void DomStorageContext::AddEventObserver(EventObserver* observer) { |
152 event_observers_.AddObserver(observer); | 169 event_observers_.AddObserver(observer); |
153 } | 170 } |
154 | 171 |
155 void DomStorageContext::RemoveEventObserver(EventObserver* observer) { | 172 void DomStorageContext::RemoveEventObserver(EventObserver* observer) { |
156 event_observers_.RemoveObserver(observer); | 173 event_observers_.RemoveObserver(observer); |
157 } | 174 } |
158 | 175 |
(...skipping 25 matching lines...) Expand all Loading... | |
184 EventObserver, event_observers_, | 201 EventObserver, event_observers_, |
185 OnDomStorageAreaCleared(area, page_url)); | 202 OnDomStorageAreaCleared(area, page_url)); |
186 } | 203 } |
187 | 204 |
188 void DomStorageContext::CreateSessionNamespace( | 205 void DomStorageContext::CreateSessionNamespace( |
189 int64 namespace_id) { | 206 int64 namespace_id) { |
190 if (is_shutdown_) | 207 if (is_shutdown_) |
191 return; | 208 return; |
192 DCHECK(namespace_id != kLocalStorageNamespaceId); | 209 DCHECK(namespace_id != kLocalStorageNamespaceId); |
193 DCHECK(namespaces_.find(namespace_id) == namespaces_.end()); | 210 DCHECK(namespaces_.find(namespace_id) == namespaces_.end()); |
194 namespaces_[namespace_id] = new DomStorageNamespace( | 211 if (session_storage_database_.get()) { |
195 namespace_id, task_runner_); | 212 // Session storage with backing. |
213 namespaces_[namespace_id] = new DomStorageNamespace( | |
214 namespace_id, session_storage_database_.get(), task_runner_); | |
215 } else { | |
216 // Session storage without backing. | |
217 namespaces_[namespace_id] = new DomStorageNamespace( | |
218 namespace_id, task_runner_); | |
219 } | |
196 } | 220 } |
197 | 221 |
198 void DomStorageContext::DeleteSessionNamespace( | 222 void DomStorageContext::DeleteSessionNamespace( |
199 int64 namespace_id) { | 223 int64 namespace_id) { |
200 DCHECK_NE(kLocalStorageNamespaceId, namespace_id); | 224 DCHECK_NE(kLocalStorageNamespaceId, namespace_id); |
201 namespaces_.erase(namespace_id); | 225 namespaces_.erase(namespace_id); |
226 // TODO(marja): When doing a session restore, protect parts of the data from | |
227 // deletion. | |
michaeln
2012/04/22 21:43:35
maybe the way the session handling logic in chrome
marja
2012/05/11 12:18:32
Hmm, not sure yet how this would work.
Could the
| |
228 if (session_storage_database_.get()) { | |
229 bool success = task_runner_->PostShutdownBlockingTask( | |
230 FROM_HERE, | |
231 DomStorageTaskRunner::COMMIT_SEQUENCE, | |
232 base::Bind(&DomStorageContext::DeleteSessionNamespaceInCommitSequence, | |
233 this, namespace_id)); | |
234 DCHECK(success); | |
235 } | |
202 } | 236 } |
203 | 237 |
204 void DomStorageContext::CloneSessionNamespace( | 238 void DomStorageContext::CloneSessionNamespace( |
205 int64 existing_id, int64 new_id) { | 239 int64 existing_id, int64 new_id) { |
206 if (is_shutdown_) | 240 if (is_shutdown_) |
207 return; | 241 return; |
208 DCHECK_NE(kLocalStorageNamespaceId, existing_id); | 242 DCHECK_NE(kLocalStorageNamespaceId, existing_id); |
209 DCHECK_NE(kLocalStorageNamespaceId, new_id); | 243 DCHECK_NE(kLocalStorageNamespaceId, new_id); |
210 StorageNamespaceMap::iterator found = namespaces_.find(existing_id); | 244 StorageNamespaceMap::iterator found = namespaces_.find(existing_id); |
211 if (found != namespaces_.end()) | 245 if (found != namespaces_.end()) |
(...skipping 18 matching lines...) Expand all Loading... | |
230 const bool kNotRecursive = false; | 264 const bool kNotRecursive = false; |
231 FilePath database_file_path = localstorage_directory_.Append( | 265 FilePath database_file_path = localstorage_directory_.Append( |
232 DomStorageArea::DatabaseFileNameFromOrigin(origin)); | 266 DomStorageArea::DatabaseFileNameFromOrigin(origin)); |
233 file_util::Delete(database_file_path, kNotRecursive); | 267 file_util::Delete(database_file_path, kNotRecursive); |
234 file_util::Delete( | 268 file_util::Delete( |
235 DomStorageDatabase::GetJournalFilePath(database_file_path), | 269 DomStorageDatabase::GetJournalFilePath(database_file_path), |
236 kNotRecursive); | 270 kNotRecursive); |
237 } | 271 } |
238 } | 272 } |
239 | 273 |
274 void DomStorageContext::DeleteSessionNamespaceInCommitSequence( | |
275 int64 namespace_id) { | |
276 session_storage_database_->DeleteNamespace(namespace_id); | |
277 } | |
278 | |
279 void DomStorageContext::DeleteLeftoverDataInCommitSequence() { | |
280 session_storage_database_->DeleteLeftoverData(); | |
281 } | |
282 | |
240 } // namespace dom_storage | 283 } // namespace dom_storage |
OLD | NEW |