Chromium Code Reviews| 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 "chrome/browser/browsing_data_local_storage_helper.h" | 5 #include "chrome/browser/browsing_data_local_storage_helper.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 } | 59 } |
| 60 | 60 |
| 61 void BrowsingDataLocalStorageHelper::StartFetching( | 61 void BrowsingDataLocalStorageHelper::StartFetching( |
| 62 const base::Callback<void(const std::list<LocalStorageInfo>&)>& callback) { | 62 const base::Callback<void(const std::list<LocalStorageInfo>&)>& callback) { |
| 63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 64 DCHECK(!is_fetching_); | 64 DCHECK(!is_fetching_); |
| 65 DCHECK_EQ(false, callback.is_null()); | 65 DCHECK_EQ(false, callback.is_null()); |
| 66 | 66 |
| 67 is_fetching_ = true; | 67 is_fetching_ = true; |
| 68 completion_callback_ = callback; | 68 completion_callback_ = callback; |
| 69 BrowserThread::PostTask( | 69 dom_storage_context_->task_runner()->PostTask( |
| 70 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, | 70 FROM_HERE, |
| 71 base::Bind( | 71 base::Bind( |
| 72 &BrowsingDataLocalStorageHelper::FetchLocalStorageInfoInWebKitThread, | 72 &BrowsingDataLocalStorageHelper::FetchLocalStorageInfoInWebKitThread, |
| 73 this)); | 73 this)); |
| 74 } | 74 } |
| 75 | 75 |
| 76 void BrowsingDataLocalStorageHelper::CancelNotification() { | 76 void BrowsingDataLocalStorageHelper::CancelNotification() { |
| 77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 78 completion_callback_.Reset(); | 78 completion_callback_.Reset(); |
| 79 } | 79 } |
| 80 | 80 |
| 81 void BrowsingDataLocalStorageHelper::DeleteLocalStorageFile( | 81 void BrowsingDataLocalStorageHelper::DeleteLocalStorageFile( |
| 82 const FilePath& file_path) { | 82 const FilePath& file_path) { |
| 83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 84 BrowserThread::PostTask( | 84 dom_storage_context_->task_runner()->PostTask( |
| 85 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, | 85 FROM_HERE, |
| 86 base::Bind( | 86 base::Bind( |
| 87 &BrowsingDataLocalStorageHelper::DeleteLocalStorageFileInWebKitThread, | 87 &BrowsingDataLocalStorageHelper::DeleteLocalStorageFileInWebKitThread, |
| 88 this, file_path)); | 88 this, file_path)); |
| 89 } | 89 } |
| 90 | 90 |
| 91 void BrowsingDataLocalStorageHelper::FetchLocalStorageInfoInWebKitThread() { | 91 void BrowsingDataLocalStorageHelper::FetchLocalStorageInfoInWebKitThread() { |
|
michaeln
2012/03/14 05:17:26
i'll change these methods names to read <DoX>InSeq
| |
| 92 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 92 DCHECK(dom_storage_context_->task_runner()->RunsTasksOnCurrentThread()); |
| 93 std::vector<FilePath> files = dom_storage_context_->GetAllStorageFiles(); | 93 std::vector<FilePath> files = dom_storage_context_->GetAllStorageFiles(); |
| 94 for (size_t i = 0; i < files.size(); ++i) { | 94 for (size_t i = 0; i < files.size(); ++i) { |
| 95 FilePath file_path = files[i]; | 95 FilePath file_path = files[i]; |
| 96 WebSecurityOrigin web_security_origin = | 96 WebSecurityOrigin web_security_origin = |
| 97 WebSecurityOrigin::createFromDatabaseIdentifier( | 97 WebSecurityOrigin::createFromDatabaseIdentifier( |
| 98 webkit_glue::FilePathToWebString(file_path.BaseName())); | 98 webkit_glue::FilePathToWebString(file_path.BaseName())); |
| 99 if (EqualsASCII(web_security_origin.protocol(), chrome::kExtensionScheme)) { | 99 if (EqualsASCII(web_security_origin.protocol(), chrome::kExtensionScheme)) { |
| 100 // Extension state is not considered browsing data. | 100 // Extension state is not considered browsing data. |
| 101 continue; | 101 continue; |
| 102 } | 102 } |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 127 // test it here. | 127 // test it here. |
| 128 if (!completion_callback_.is_null()) { | 128 if (!completion_callback_.is_null()) { |
| 129 completion_callback_.Run(local_storage_info_); | 129 completion_callback_.Run(local_storage_info_); |
| 130 completion_callback_.Reset(); | 130 completion_callback_.Reset(); |
| 131 } | 131 } |
| 132 is_fetching_ = false; | 132 is_fetching_ = false; |
| 133 } | 133 } |
| 134 | 134 |
| 135 void BrowsingDataLocalStorageHelper::DeleteLocalStorageFileInWebKitThread( | 135 void BrowsingDataLocalStorageHelper::DeleteLocalStorageFileInWebKitThread( |
| 136 const FilePath& file_path) { | 136 const FilePath& file_path) { |
| 137 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 137 DCHECK(dom_storage_context_->task_runner()->RunsTasksOnCurrentThread()); |
| 138 dom_storage_context_->DeleteLocalStorageFile(file_path); | 138 dom_storage_context_->DeleteLocalStorageFile(file_path); |
| 139 } | 139 } |
| 140 | 140 |
| 141 //--------------------------------------------------------- | |
| 142 | |
| 141 CannedBrowsingDataLocalStorageHelper::CannedBrowsingDataLocalStorageHelper( | 143 CannedBrowsingDataLocalStorageHelper::CannedBrowsingDataLocalStorageHelper( |
| 142 Profile* profile) | 144 Profile* profile) |
| 143 : BrowsingDataLocalStorageHelper(profile), | 145 : BrowsingDataLocalStorageHelper(profile), |
| 144 profile_(profile) { | 146 profile_(profile) { |
| 145 } | 147 } |
| 146 | 148 |
| 147 CannedBrowsingDataLocalStorageHelper* | 149 CannedBrowsingDataLocalStorageHelper* |
| 148 CannedBrowsingDataLocalStorageHelper::Clone() { | 150 CannedBrowsingDataLocalStorageHelper::Clone() { |
| 149 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 151 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 150 CannedBrowsingDataLocalStorageHelper* clone = | 152 CannedBrowsingDataLocalStorageHelper* clone = |
| 151 new CannedBrowsingDataLocalStorageHelper(profile_); | 153 new CannedBrowsingDataLocalStorageHelper(profile_); |
| 152 | 154 |
| 153 base::AutoLock auto_lock(lock_); | |
| 154 clone->pending_local_storage_info_ = pending_local_storage_info_; | 155 clone->pending_local_storage_info_ = pending_local_storage_info_; |
| 155 clone->local_storage_info_ = local_storage_info_; | 156 clone->local_storage_info_ = local_storage_info_; |
| 156 return clone; | 157 return clone; |
| 157 } | 158 } |
| 158 | 159 |
| 159 void CannedBrowsingDataLocalStorageHelper::AddLocalStorage( | 160 void CannedBrowsingDataLocalStorageHelper::AddLocalStorage( |
| 160 const GURL& origin) { | 161 const GURL& origin) { |
| 161 base::AutoLock auto_lock(lock_); | |
| 162 pending_local_storage_info_.insert(origin); | 162 pending_local_storage_info_.insert(origin); |
| 163 } | 163 } |
| 164 | 164 |
| 165 void CannedBrowsingDataLocalStorageHelper::Reset() { | 165 void CannedBrowsingDataLocalStorageHelper::Reset() { |
| 166 base::AutoLock auto_lock(lock_); | |
| 167 local_storage_info_.clear(); | 166 local_storage_info_.clear(); |
| 168 pending_local_storage_info_.clear(); | 167 pending_local_storage_info_.clear(); |
| 169 } | 168 } |
| 170 | 169 |
| 171 bool CannedBrowsingDataLocalStorageHelper::empty() const { | 170 bool CannedBrowsingDataLocalStorageHelper::empty() const { |
| 172 base::AutoLock auto_lock(lock_); | |
| 173 return local_storage_info_.empty() && pending_local_storage_info_.empty(); | 171 return local_storage_info_.empty() && pending_local_storage_info_.empty(); |
| 174 } | 172 } |
| 175 | 173 |
| 176 void CannedBrowsingDataLocalStorageHelper::StartFetching( | 174 void CannedBrowsingDataLocalStorageHelper::StartFetching( |
| 177 const base::Callback<void(const std::list<LocalStorageInfo>&)>& callback) { | 175 const base::Callback<void(const std::list<LocalStorageInfo>&)>& callback) { |
| 178 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 176 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 179 DCHECK(!is_fetching_); | 177 DCHECK(!is_fetching_); |
| 180 DCHECK_EQ(false, callback.is_null()); | 178 DCHECK_EQ(false, callback.is_null()); |
| 181 | 179 |
| 182 is_fetching_ = true; | 180 is_fetching_ = true; |
| 183 completion_callback_ = callback; | 181 completion_callback_ = callback; |
| 184 BrowserThread::PostTask( | 182 |
| 185 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, | 183 // We post a task to emulate async fetching behavior. |
| 184 MessageLoop::current()->PostTask( | |
| 185 FROM_HERE, | |
| 186 base::Bind(&CannedBrowsingDataLocalStorageHelper:: | 186 base::Bind(&CannedBrowsingDataLocalStorageHelper:: |
| 187 ConvertPendingInfoInWebKitThread, this)); | 187 ConvertPendingInfo, this)); |
| 188 } | 188 } |
| 189 | 189 |
| 190 CannedBrowsingDataLocalStorageHelper::~CannedBrowsingDataLocalStorageHelper() {} | 190 CannedBrowsingDataLocalStorageHelper::~CannedBrowsingDataLocalStorageHelper() {} |
| 191 | 191 |
| 192 void CannedBrowsingDataLocalStorageHelper::ConvertPendingInfoInWebKitThread() { | 192 void CannedBrowsingDataLocalStorageHelper::ConvertPendingInfo() { |
| 193 base::AutoLock auto_lock(lock_); | |
| 194 for (std::set<GURL>::iterator info = pending_local_storage_info_.begin(); | 193 for (std::set<GURL>::iterator info = pending_local_storage_info_.begin(); |
| 195 info != pending_local_storage_info_.end(); ++info) { | 194 info != pending_local_storage_info_.end(); ++info) { |
| 196 WebSecurityOrigin web_security_origin = | 195 WebSecurityOrigin web_security_origin = |
| 197 WebSecurityOrigin::createFromString( | 196 WebSecurityOrigin::createFromString( |
| 198 UTF8ToUTF16(info->spec())); | 197 UTF8ToUTF16(info->spec())); |
| 199 std::string security_origin(web_security_origin.toString().utf8()); | 198 std::string security_origin(web_security_origin.toString().utf8()); |
| 200 | 199 |
| 201 bool duplicate = false; | 200 bool duplicate = false; |
| 202 for (std::list<LocalStorageInfo>::iterator | 201 for (std::list<LocalStorageInfo>::iterator |
| 203 local_storage = local_storage_info_.begin(); | 202 local_storage = local_storage_info_.begin(); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 221 0, | 220 0, |
| 222 base::Time())); | 221 base::Time())); |
| 223 } | 222 } |
| 224 pending_local_storage_info_.clear(); | 223 pending_local_storage_info_.clear(); |
| 225 | 224 |
| 226 BrowserThread::PostTask( | 225 BrowserThread::PostTask( |
| 227 BrowserThread::UI, FROM_HERE, | 226 BrowserThread::UI, FROM_HERE, |
| 228 base::Bind(&CannedBrowsingDataLocalStorageHelper::NotifyInUIThread, | 227 base::Bind(&CannedBrowsingDataLocalStorageHelper::NotifyInUIThread, |
| 229 this)); | 228 this)); |
| 230 } | 229 } |
| OLD | NEW |