| 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( |
| 205 &DOMStorageContextImpl::PurgeMemory, |
| 206 this, clear_local_state)); |
| 207 return; |
| 208 } |
| 209 |
| 201 // It is only safe to purge the memory from the LocalStorage namespace, | 210 // 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 | 211 // 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 | 212 // SessionStorage namespace, its data will be gone forever, because it isn't |
| 204 // currently backed by disk. | 213 // currently backed by disk. |
| 205 DOMStorageNamespace* local_storage = | 214 DOMStorageNamespace* local_storage = |
| 206 GetStorageNamespace(kLocalStorageNamespaceId, false); | 215 GetStorageNamespace(kLocalStorageNamespaceId, false); |
| 207 if (local_storage) | 216 if (local_storage) |
| 208 local_storage->PurgeMemory(); | 217 local_storage->PurgeMemory(); |
| 209 } | 218 } |
| 210 | 219 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 file_util::FileEnumerator file_enumerator( | 279 file_util::FileEnumerator file_enumerator( |
| 271 data_path_.Append(kLocalStorageDirectory), false, | 280 data_path_.Append(kLocalStorageDirectory), false, |
| 272 file_util::FileEnumerator::FILES); | 281 file_util::FileEnumerator::FILES); |
| 273 for (FilePath file_path = file_enumerator.Next(); !file_path.empty(); | 282 for (FilePath file_path = file_enumerator.Next(); !file_path.empty(); |
| 274 file_path = file_enumerator.Next()) { | 283 file_path = file_enumerator.Next()) { |
| 275 if (file_path.Extension() == kLocalStorageExtension) | 284 if (file_path.Extension() == kLocalStorageExtension) |
| 276 file_util::Delete(file_path, false); | 285 file_util::Delete(file_path, false); |
| 277 } | 286 } |
| 278 } | 287 } |
| 279 | 288 |
| 289 void DOMStorageContextImpl::SetClearLocalState(bool clear_local_state) { |
| 290 if (!webkit_message_loop_->RunsTasksOnCurrentThread()) { |
| 291 webkit_message_loop_->PostTask( |
| 292 FROM_HERE, |
| 293 base::Bind( |
| 294 &DOMStorageContextImpl::SetClearLocalState, |
| 295 this, clear_local_state)); |
| 296 return; |
| 297 } |
| 298 clear_local_state_on_exit_ = clear_local_state; |
| 299 } |
| 300 |
| 301 void DOMStorageContextImpl::SaveSessionState() { |
| 302 if (!webkit_message_loop_->RunsTasksOnCurrentThread()) { |
| 303 webkit_message_loop_->PostTask( |
| 304 FROM_HERE, |
| 305 base::Bind( |
| 306 &DOMStorageContextImpl::SaveSessionState, |
| 307 this)); |
| 308 return; |
| 309 } |
| 310 save_session_state_ = true; |
| 311 } |
| 312 |
| 280 DOMStorageNamespace* DOMStorageContextImpl::CreateLocalStorage() { | 313 DOMStorageNamespace* DOMStorageContextImpl::CreateLocalStorage() { |
| 281 FilePath dir_path; | 314 FilePath dir_path; |
| 282 if (!data_path_.empty()) | 315 if (!data_path_.empty()) |
| 283 dir_path = data_path_.Append(kLocalStorageDirectory); | 316 dir_path = data_path_.Append(kLocalStorageDirectory); |
| 284 DOMStorageNamespace* new_namespace = | 317 DOMStorageNamespace* new_namespace = |
| 285 DOMStorageNamespace::CreateLocalStorageNamespace(this, dir_path); | 318 DOMStorageNamespace::CreateLocalStorageNamespace(this, dir_path); |
| 286 RegisterStorageNamespace(new_namespace); | 319 RegisterStorageNamespace(new_namespace); |
| 287 return new_namespace; | 320 return new_namespace; |
| 288 } | 321 } |
| 289 | 322 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 309 DOMStorageNamespace* existing_namespace = | 342 DOMStorageNamespace* existing_namespace = |
| 310 GetStorageNamespace(existing_id, false); | 343 GetStorageNamespace(existing_id, false); |
| 311 // If nothing exists, then there's nothing to clone. | 344 // If nothing exists, then there's nothing to clone. |
| 312 if (existing_namespace) | 345 if (existing_namespace) |
| 313 RegisterStorageNamespace(existing_namespace->Copy(clone_id)); | 346 RegisterStorageNamespace(existing_namespace->Copy(clone_id)); |
| 314 } | 347 } |
| 315 | 348 |
| 316 void DOMStorageContextImpl::GetAllStorageFiles( | 349 void DOMStorageContextImpl::GetAllStorageFiles( |
| 317 const GetAllStorageFilesCallback& callback) { | 350 const GetAllStorageFilesCallback& callback) { |
| 318 if (!webkit_message_loop_->RunsTasksOnCurrentThread()) { | 351 if (!webkit_message_loop_->RunsTasksOnCurrentThread()) { |
| 352 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 319 webkit_message_loop_->PostTask( | 353 webkit_message_loop_->PostTask( |
| 320 FROM_HERE, | 354 FROM_HERE, |
| 321 base::Bind( | 355 base::Bind( |
| 322 &DOMStorageContextImpl::GetAllStorageFiles, this, callback)); | 356 &DOMStorageContextImpl::GetAllStorageFiles, this, callback)); |
| 323 return; | 357 return; |
| 324 } | 358 } |
| 325 | 359 |
| 326 std::vector<FilePath> files; | 360 std::vector<FilePath> files; |
| 327 file_util::FileEnumerator file_enumerator( | 361 file_util::FileEnumerator file_enumerator( |
| 328 data_path_.Append(kLocalStorageDirectory), false, | 362 data_path_.Append(kLocalStorageDirectory), false, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 345 callback.Run(files); | 379 callback.Run(files); |
| 346 } | 380 } |
| 347 | 381 |
| 348 FilePath DOMStorageContextImpl::GetFilePath(const string16& origin_id) const { | 382 FilePath DOMStorageContextImpl::GetFilePath(const string16& origin_id) const { |
| 349 FilePath storage_dir = data_path_.Append(kLocalStorageDirectory); | 383 FilePath storage_dir = data_path_.Append(kLocalStorageDirectory); |
| 350 FilePath::StringType id = webkit_glue::WebStringToFilePathString(origin_id); | 384 FilePath::StringType id = webkit_glue::WebStringToFilePathString(origin_id); |
| 351 return storage_dir.Append(id.append(kLocalStorageExtension)); | 385 return storage_dir.Append(id.append(kLocalStorageExtension)); |
| 352 } | 386 } |
| 353 | 387 |
| 354 #endif // ENABLE_NEW_DOM_STORAGE_BACKEND | 388 #endif // ENABLE_NEW_DOM_STORAGE_BACKEND |
| 355 | |
| OLD | NEW |