OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/browser/in_process_webkit/dom_storage_context_impl.h" | 5 #include "content/browser/in_process_webkit/dom_storage_context_impl.h" |
6 | 6 |
7 #ifdef ENABLE_NEW_DOM_STORAGE_BACKEND | 7 #ifdef ENABLE_NEW_DOM_STORAGE_BACKEND |
8 // This class is replaced by a new implementation in | 8 // This class is replaced by a new implementation in |
9 // content/browser/dom_storage/dom_storage_context_impl_new.h | 9 // content/browser/dom_storage/dom_storage_context_impl_new.h |
10 #else | 10 #else |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 message_filter_set_.erase(message_filter); | 191 message_filter_set_.erase(message_filter); |
192 } | 192 } |
193 | 193 |
194 const DOMStorageContextImpl::MessageFilterSet* | 194 const DOMStorageContextImpl::MessageFilterSet* |
195 DOMStorageContextImpl::GetMessageFilterSet() const { | 195 DOMStorageContextImpl::GetMessageFilterSet() const { |
196 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 196 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
197 return &message_filter_set_; | 197 return &message_filter_set_; |
198 } | 198 } |
199 | 199 |
200 void DOMStorageContextImpl::PurgeMemory() { | 200 void DOMStorageContextImpl::PurgeMemory() { |
| 201 if (!webkit_message_loop_->RunsTasksOnCurrentThread()) { |
| 202 webkit_message_loop_->PostTask( |
| 203 FROM_HERE, |
| 204 base::Bind(&DOMStorageContextImpl::PurgeMemory, this)); |
| 205 return; |
| 206 } |
| 207 |
201 // It is only safe to purge the memory from the LocalStorage namespace, | 208 // It is only safe to purge the memory from the LocalStorage namespace, |
202 // because it is backed by disk and can be reloaded later. If we purge a | 209 // because it is backed by disk and can be reloaded later. If we purge a |
203 // SessionStorage namespace, its data will be gone forever, because it isn't | 210 // SessionStorage namespace, its data will be gone forever, because it isn't |
204 // currently backed by disk. | 211 // currently backed by disk. |
205 DOMStorageNamespace* local_storage = | 212 DOMStorageNamespace* local_storage = |
206 GetStorageNamespace(kLocalStorageNamespaceId, false); | 213 GetStorageNamespace(kLocalStorageNamespaceId, false); |
207 if (local_storage) | 214 if (local_storage) |
208 local_storage->PurgeMemory(); | 215 local_storage->PurgeMemory(); |
209 } | 216 } |
210 | 217 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 file_util::FileEnumerator file_enumerator( | 277 file_util::FileEnumerator file_enumerator( |
271 data_path_.Append(kLocalStorageDirectory), false, | 278 data_path_.Append(kLocalStorageDirectory), false, |
272 file_util::FileEnumerator::FILES); | 279 file_util::FileEnumerator::FILES); |
273 for (FilePath file_path = file_enumerator.Next(); !file_path.empty(); | 280 for (FilePath file_path = file_enumerator.Next(); !file_path.empty(); |
274 file_path = file_enumerator.Next()) { | 281 file_path = file_enumerator.Next()) { |
275 if (file_path.Extension() == kLocalStorageExtension) | 282 if (file_path.Extension() == kLocalStorageExtension) |
276 file_util::Delete(file_path, false); | 283 file_util::Delete(file_path, false); |
277 } | 284 } |
278 } | 285 } |
279 | 286 |
| 287 void DOMStorageContextImpl::SetClearLocalState(bool clear_local_state) { |
| 288 if (!webkit_message_loop_->RunsTasksOnCurrentThread()) { |
| 289 webkit_message_loop_->PostTask( |
| 290 FROM_HERE, |
| 291 base::Bind( |
| 292 &DOMStorageContextImpl::SetClearLocalState, |
| 293 this, clear_local_state)); |
| 294 return; |
| 295 } |
| 296 clear_local_state_on_exit_ = clear_local_state; |
| 297 } |
| 298 |
| 299 void DOMStorageContextImpl::SaveSessionState() { |
| 300 if (!webkit_message_loop_->RunsTasksOnCurrentThread()) { |
| 301 webkit_message_loop_->PostTask( |
| 302 FROM_HERE, |
| 303 base::Bind(&DOMStorageContextImpl::SaveSessionState, this)); |
| 304 return; |
| 305 } |
| 306 save_session_state_ = true; |
| 307 } |
| 308 |
280 DOMStorageNamespace* DOMStorageContextImpl::CreateLocalStorage() { | 309 DOMStorageNamespace* DOMStorageContextImpl::CreateLocalStorage() { |
281 FilePath dir_path; | 310 FilePath dir_path; |
282 if (!data_path_.empty()) | 311 if (!data_path_.empty()) |
283 dir_path = data_path_.Append(kLocalStorageDirectory); | 312 dir_path = data_path_.Append(kLocalStorageDirectory); |
284 DOMStorageNamespace* new_namespace = | 313 DOMStorageNamespace* new_namespace = |
285 DOMStorageNamespace::CreateLocalStorageNamespace(this, dir_path); | 314 DOMStorageNamespace::CreateLocalStorageNamespace(this, dir_path); |
286 RegisterStorageNamespace(new_namespace); | 315 RegisterStorageNamespace(new_namespace); |
287 return new_namespace; | 316 return new_namespace; |
288 } | 317 } |
289 | 318 |
(...skipping 19 matching lines...) Expand all Loading... |
309 DOMStorageNamespace* existing_namespace = | 338 DOMStorageNamespace* existing_namespace = |
310 GetStorageNamespace(existing_id, false); | 339 GetStorageNamespace(existing_id, false); |
311 // If nothing exists, then there's nothing to clone. | 340 // If nothing exists, then there's nothing to clone. |
312 if (existing_namespace) | 341 if (existing_namespace) |
313 RegisterStorageNamespace(existing_namespace->Copy(clone_id)); | 342 RegisterStorageNamespace(existing_namespace->Copy(clone_id)); |
314 } | 343 } |
315 | 344 |
316 void DOMStorageContextImpl::GetAllStorageFiles( | 345 void DOMStorageContextImpl::GetAllStorageFiles( |
317 const GetAllStorageFilesCallback& callback) { | 346 const GetAllStorageFilesCallback& callback) { |
318 if (!webkit_message_loop_->RunsTasksOnCurrentThread()) { | 347 if (!webkit_message_loop_->RunsTasksOnCurrentThread()) { |
| 348 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
319 webkit_message_loop_->PostTask( | 349 webkit_message_loop_->PostTask( |
320 FROM_HERE, | 350 FROM_HERE, |
321 base::Bind( | 351 base::Bind( |
322 &DOMStorageContextImpl::GetAllStorageFiles, this, callback)); | 352 &DOMStorageContextImpl::GetAllStorageFiles, this, callback)); |
323 return; | 353 return; |
324 } | 354 } |
325 | 355 |
326 std::vector<FilePath> files; | 356 std::vector<FilePath> files; |
327 file_util::FileEnumerator file_enumerator( | 357 file_util::FileEnumerator file_enumerator( |
328 data_path_.Append(kLocalStorageDirectory), false, | 358 data_path_.Append(kLocalStorageDirectory), false, |
(...skipping 16 matching lines...) Expand all Loading... |
345 callback.Run(files); | 375 callback.Run(files); |
346 } | 376 } |
347 | 377 |
348 FilePath DOMStorageContextImpl::GetFilePath(const string16& origin_id) const { | 378 FilePath DOMStorageContextImpl::GetFilePath(const string16& origin_id) const { |
349 FilePath storage_dir = data_path_.Append(kLocalStorageDirectory); | 379 FilePath storage_dir = data_path_.Append(kLocalStorageDirectory); |
350 FilePath::StringType id = webkit_glue::WebStringToFilePathString(origin_id); | 380 FilePath::StringType id = webkit_glue::WebStringToFilePathString(origin_id); |
351 return storage_dir.Append(id.append(kLocalStorageExtension)); | 381 return storage_dir.Append(id.append(kLocalStorageExtension)); |
352 } | 382 } |
353 | 383 |
354 #endif // ENABLE_NEW_DOM_STORAGE_BACKEND | 384 #endif // ENABLE_NEW_DOM_STORAGE_BACKEND |
355 | |
OLD | NEW |