OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/browsing_data_local_storage_helper.h" |
| 6 |
| 7 #include "base/file_util.h" |
| 8 #include "base/message_loop.h" |
| 9 #include "chrome/browser/chrome_thread.h" |
| 10 #include "chrome/browser/in_process_webkit/webkit_context.h" |
| 11 #include "chrome/browser/profile.h" |
| 12 #include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h" |
| 13 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" |
| 14 #include "webkit/glue/glue_util.h" |
| 15 #include "webkit/glue/webkit_glue.h" |
| 16 |
| 17 BrowsingDataLocalStorageHelper::BrowsingDataLocalStorageHelper( |
| 18 Profile* profile) |
| 19 : profile_(profile), |
| 20 completion_callback_(NULL), |
| 21 is_fetching_(false) { |
| 22 DCHECK(profile_); |
| 23 } |
| 24 |
| 25 void BrowsingDataLocalStorageHelper::StartFetching( |
| 26 Callback1<const std::vector<LocalStorageInfo>& >::Type* callback) { |
| 27 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| 28 DCHECK(!is_fetching_); |
| 29 DCHECK(callback); |
| 30 is_fetching_ = true; |
| 31 completion_callback_.reset(callback); |
| 32 ChromeThread::PostTask( |
| 33 ChromeThread::WEBKIT, FROM_HERE, |
| 34 NewRunnableMethod( |
| 35 this, |
| 36 &BrowsingDataLocalStorageHelper:: |
| 37 FetchLocalStorageInfoInWebKitThread)); |
| 38 } |
| 39 |
| 40 void BrowsingDataLocalStorageHelper::CancelNotification() { |
| 41 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| 42 completion_callback_.reset(NULL); |
| 43 } |
| 44 |
| 45 void BrowsingDataLocalStorageHelper::DeleteLocalStorageFile( |
| 46 const FilePath& file_path) { |
| 47 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| 48 ChromeThread::PostTask( |
| 49 ChromeThread::WEBKIT, FROM_HERE, |
| 50 NewRunnableMethod( |
| 51 this, |
| 52 &BrowsingDataLocalStorageHelper:: |
| 53 DeleteLocalStorageFileInWebKitThread, |
| 54 file_path)); |
| 55 } |
| 56 |
| 57 void BrowsingDataLocalStorageHelper::DeleteAllLocalStorageFiles() { |
| 58 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| 59 ChromeThread::PostTask( |
| 60 ChromeThread::WEBKIT, FROM_HERE, |
| 61 NewRunnableMethod( |
| 62 this, |
| 63 &BrowsingDataLocalStorageHelper:: |
| 64 DeleteAllLocalStorageFilesInWebKitThread)); |
| 65 } |
| 66 |
| 67 void BrowsingDataLocalStorageHelper::FetchLocalStorageInfoInWebKitThread() { |
| 68 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); |
| 69 file_util::FileEnumerator file_enumerator( |
| 70 profile_->GetWebKitContext()->data_path().Append( |
| 71 DOMStorageContext::kLocalStorageDirectory), |
| 72 false, file_util::FileEnumerator::FILES); |
| 73 for (FilePath file_path = file_enumerator.Next(); !file_path.empty(); |
| 74 file_path = file_enumerator.Next()) { |
| 75 if (file_path.Extension() == DOMStorageContext::kLocalStorageExtension) { |
| 76 scoped_ptr<WebKit::WebSecurityOrigin> web_security_origin( |
| 77 WebKit::WebSecurityOrigin::createFromDatabaseIdentifier( |
| 78 webkit_glue::FilePathToWebString(file_path.BaseName()))); |
| 79 file_util::FileInfo file_info; |
| 80 bool ret = file_util::GetFileInfo(file_path, &file_info); |
| 81 if (ret) { |
| 82 local_storage_info_.push_back(LocalStorageInfo( |
| 83 webkit_glue::WebStringToStdString(web_security_origin->protocol()), |
| 84 webkit_glue::WebStringToStdString(web_security_origin->host()), |
| 85 web_security_origin->port(), |
| 86 webkit_glue::WebStringToStdString( |
| 87 web_security_origin->databaseIdentifier()), |
| 88 webkit_glue::WebStringToStdString( |
| 89 web_security_origin->toString()), |
| 90 file_path, |
| 91 file_info.size, |
| 92 file_info.last_modified)); |
| 93 } |
| 94 } |
| 95 } |
| 96 |
| 97 ChromeThread::PostTask( |
| 98 ChromeThread::UI, FROM_HERE, |
| 99 NewRunnableMethod( |
| 100 this, &BrowsingDataLocalStorageHelper::NotifyInUIThread)); |
| 101 } |
| 102 |
| 103 void BrowsingDataLocalStorageHelper::NotifyInUIThread() { |
| 104 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| 105 DCHECK(is_fetching_); |
| 106 // Note: completion_callback_ mutates only in the UI thread, so it's safe to |
| 107 // test it here. |
| 108 if (completion_callback_ != NULL) |
| 109 completion_callback_->Run(local_storage_info_); |
| 110 is_fetching_ = false; |
| 111 } |
| 112 |
| 113 void BrowsingDataLocalStorageHelper::DeleteLocalStorageFileInWebKitThread( |
| 114 const FilePath& file_path) { |
| 115 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); |
| 116 profile_->GetWebKitContext()->dom_storage_context()->DeleteLocalStorageFile( |
| 117 file_path); |
| 118 } |
| 119 |
| 120 void |
| 121 BrowsingDataLocalStorageHelper::DeleteAllLocalStorageFilesInWebKitThread() { |
| 122 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); |
| 123 profile_->GetWebKitContext()->dom_storage_context() |
| 124 ->DeleteAllLocalStorageFiles(); |
| 125 } |
OLD | NEW |