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