Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 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_indexed_db_helper.h" | 5 #include "chrome/browser/browsing_data_indexed_db_helper.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 void BrowsingDataIndexedDBHelperImpl::FetchIndexedDBInfoInWebKitThread() { | 102 void BrowsingDataIndexedDBHelperImpl::FetchIndexedDBInfoInWebKitThread() { |
| 103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); | 103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); |
| 104 file_util::FileEnumerator file_enumerator( | 104 file_util::FileEnumerator file_enumerator( |
| 105 profile_->GetWebKitContext()->data_path().Append( | 105 profile_->GetWebKitContext()->data_path().Append( |
| 106 IndexedDBContext::kIndexedDBDirectory), | 106 IndexedDBContext::kIndexedDBDirectory), |
| 107 false, file_util::FileEnumerator::FILES); | 107 false, file_util::FileEnumerator::FILES); |
| 108 for (FilePath file_path = file_enumerator.Next(); !file_path.empty(); | 108 for (FilePath file_path = file_enumerator.Next(); !file_path.empty(); |
| 109 file_path = file_enumerator.Next()) { | 109 file_path = file_enumerator.Next()) { |
| 110 if (file_path.Extension() == IndexedDBContext::kIndexedDBExtension) { | 110 if (file_path.Extension() == IndexedDBContext::kIndexedDBExtension) { |
| 111 WebSecurityOrigin web_security_origin = | 111 WebSecurityOrigin web_security_origin = |
| 112 WebKit::WebSecurityOrigin::createFromDatabaseIdentifier( | 112 WebSecurityOrigin::createFromDatabaseIdentifier( |
| 113 webkit_glue::FilePathToWebString(file_path.BaseName())); | 113 webkit_glue::FilePathToWebString(file_path.BaseName())); |
| 114 if (EqualsASCII(web_security_origin.protocol(), | 114 if (EqualsASCII(web_security_origin.protocol(), |
| 115 chrome::kExtensionScheme)) { | 115 chrome::kExtensionScheme)) { |
| 116 // Extension state is not considered browsing data. | 116 // Extension state is not considered browsing data. |
| 117 continue; | 117 continue; |
| 118 } | 118 } |
| 119 base::PlatformFileInfo file_info; | 119 base::PlatformFileInfo file_info; |
| 120 bool ret = file_util::GetFileInfo(file_path, &file_info); | 120 bool ret = file_util::GetFileInfo(file_path, &file_info); |
| 121 if (ret) { | 121 if (ret) { |
| 122 indexed_db_info_.push_back(IndexedDBInfo( | 122 indexed_db_info_.push_back(IndexedDBInfo( |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 } | 178 } |
| 179 | 179 |
| 180 BrowsingDataIndexedDBHelper::IndexedDBInfo::~IndexedDBInfo() {} | 180 BrowsingDataIndexedDBHelper::IndexedDBInfo::~IndexedDBInfo() {} |
| 181 | 181 |
| 182 // static | 182 // static |
| 183 BrowsingDataIndexedDBHelper* BrowsingDataIndexedDBHelper::Create( | 183 BrowsingDataIndexedDBHelper* BrowsingDataIndexedDBHelper::Create( |
| 184 Profile* profile) { | 184 Profile* profile) { |
| 185 return new BrowsingDataIndexedDBHelperImpl(profile); | 185 return new BrowsingDataIndexedDBHelperImpl(profile); |
| 186 } | 186 } |
| 187 | 187 |
| 188 CannedBrowsingDataIndexedDBHelper:: | |
| 189 PendingIndexedDBInfo::PendingIndexedDBInfo() { | |
| 190 } | |
| 191 | |
| 192 CannedBrowsingDataIndexedDBHelper:: | |
| 193 PendingIndexedDBInfo::PendingIndexedDBInfo(const GURL& origin, | |
| 194 const string16& description) | |
| 195 : origin(origin), | |
| 196 description(description) { | |
| 197 } | |
| 198 | |
| 199 CannedBrowsingDataIndexedDBHelper:: | |
| 200 PendingIndexedDBInfo::~PendingIndexedDBInfo() { | |
| 201 } | |
| 202 | |
| 188 CannedBrowsingDataIndexedDBHelper::CannedBrowsingDataIndexedDBHelper( | 203 CannedBrowsingDataIndexedDBHelper::CannedBrowsingDataIndexedDBHelper( |
| 189 Profile* profile) | 204 Profile* profile) |
| 190 : profile_(profile) { | 205 : profile_(profile), |
| 206 completion_callback_(NULL), | |
| 207 is_fetching_(false) { | |
| 191 DCHECK(profile); | 208 DCHECK(profile); |
| 192 } | 209 } |
| 193 | 210 |
| 194 void CannedBrowsingDataIndexedDBHelper::AddIndexedDB( | 211 void CannedBrowsingDataIndexedDBHelper::AddIndexedDB( |
| 195 const GURL& origin, const string16& description) { | 212 const GURL& origin, const string16& description) { |
| 196 WebSecurityOrigin web_security_origin = | 213 base::AutoLock auto_lock(lock_); |
| 197 WebSecurityOrigin::createFromString( | 214 pending_indexed_db_info_.push_back(PendingIndexedDBInfo(origin, description)); |
| 198 UTF8ToUTF16(origin.spec())); | |
| 199 std::string security_origin(web_security_origin.toString().utf8()); | |
| 200 | |
| 201 for (std::vector<IndexedDBInfo>::iterator | |
| 202 indexed_db = indexed_db_info_.begin(); | |
| 203 indexed_db != indexed_db_info_.end(); ++indexed_db) { | |
| 204 if (indexed_db->origin == security_origin) | |
| 205 return; | |
| 206 } | |
| 207 | |
| 208 indexed_db_info_.push_back(IndexedDBInfo( | |
| 209 web_security_origin.protocol().utf8(), | |
| 210 web_security_origin.host().utf8(), | |
| 211 web_security_origin.port(), | |
| 212 web_security_origin.databaseIdentifier().utf8(), | |
| 213 security_origin, | |
| 214 profile_->GetWebKitContext()->indexed_db_context()-> | |
| 215 GetIndexedDBFilePath(web_security_origin.databaseIdentifier()), | |
| 216 0, | |
| 217 base::Time())); | |
| 218 } | 215 } |
| 219 | 216 |
| 220 void CannedBrowsingDataIndexedDBHelper::Reset() { | 217 void CannedBrowsingDataIndexedDBHelper::Reset() { |
| 218 base::AutoLock auto_lock(lock_); | |
| 221 indexed_db_info_.clear(); | 219 indexed_db_info_.clear(); |
| 220 pending_indexed_db_info_.clear(); | |
| 222 } | 221 } |
| 223 | 222 |
| 224 bool CannedBrowsingDataIndexedDBHelper::empty() const { | 223 bool CannedBrowsingDataIndexedDBHelper::empty() const { |
| 225 return indexed_db_info_.empty(); | 224 base::AutoLock auto_lock(lock_); |
| 225 return indexed_db_info_.empty() && pending_indexed_db_info_.empty(); | |
| 226 } | 226 } |
| 227 | 227 |
| 228 void CannedBrowsingDataIndexedDBHelper::StartFetching( | 228 void CannedBrowsingDataIndexedDBHelper::StartFetching( |
| 229 Callback1<const std::vector<IndexedDBInfo>& >::Type* callback) { | 229 Callback1<const std::vector<IndexedDBInfo>& >::Type* callback) { |
| 230 callback->Run(indexed_db_info_); | 230 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 231 delete callback; | 231 DCHECK(!is_fetching_); |
| 232 DCHECK(callback); | |
| 233 is_fetching_ = true; | |
| 234 completion_callback_.reset(callback); | |
| 235 BrowserThread::PostTask(BrowserThread::WEBKIT, FROM_HERE, NewRunnableMethod( | |
| 236 this, | |
| 237 &CannedBrowsingDataIndexedDBHelper::ConvertPendingInfoInWebKitThread)); | |
| 232 } | 238 } |
| 233 | 239 |
| 234 CannedBrowsingDataIndexedDBHelper::~CannedBrowsingDataIndexedDBHelper() {} | 240 CannedBrowsingDataIndexedDBHelper::~CannedBrowsingDataIndexedDBHelper() {} |
| 241 | |
| 242 void CannedBrowsingDataIndexedDBHelper::ConvertPendingInfoInWebKitThread() { | |
| 243 base::AutoLock auto_lock(lock_); | |
| 244 for (std::vector<PendingIndexedDBInfo>::const_iterator | |
| 245 info = pending_indexed_db_info_.begin(); | |
| 246 info != pending_indexed_db_info_.end(); ++info) { | |
| 247 WebSecurityOrigin web_security_origin = | |
| 248 WebSecurityOrigin::createFromString( | |
| 249 UTF8ToUTF16(info->origin.spec())); | |
| 250 std::string security_origin(web_security_origin.toString().utf8()); | |
| 251 | |
| 252 bool duplicate = false; | |
| 253 for (std::vector<IndexedDBInfo>::iterator | |
| 254 indexed_db = indexed_db_info_.begin(); | |
| 255 indexed_db != indexed_db_info_.end(); ++indexed_db) { | |
| 256 if (indexed_db->origin == security_origin) { | |
| 257 duplicate = true; | |
| 258 break; | |
| 259 } | |
| 260 } | |
| 261 if (duplicate) | |
| 262 continue; | |
| 263 | |
| 264 indexed_db_info_.push_back(IndexedDBInfo( | |
| 265 web_security_origin.protocol().utf8(), | |
| 266 web_security_origin.host().utf8(), | |
| 267 web_security_origin.port(), | |
| 268 web_security_origin.databaseIdentifier().utf8(), | |
| 269 security_origin, | |
| 270 profile_->GetWebKitContext()->indexed_db_context()-> | |
| 271 GetIndexedDBFilePath(web_security_origin.databaseIdentifier()), | |
| 272 0, | |
| 273 base::Time())); | |
| 274 } | |
| 275 pending_indexed_db_info_.clear(); | |
| 276 | |
| 277 BrowserThread::PostTask( | |
| 278 BrowserThread::UI, FROM_HERE, | |
| 279 NewRunnableMethod( | |
| 280 this, &CannedBrowsingDataIndexedDBHelper::NotifyInUIThread)); | |
| 281 } | |
| 282 | |
| 283 void CannedBrowsingDataIndexedDBHelper::NotifyInUIThread() { | |
| 284 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 285 DCHECK(is_fetching_); | |
| 286 // Note: completion_callback_ mutates only in the UI thread, so it's safe to | |
| 287 // test it here. | |
| 288 if (completion_callback_ != NULL) { | |
|
bulach
2011/02/22 22:34:01
oh, I think we can change both here (and the origi
| |
| 289 completion_callback_->Run(indexed_db_info_); | |
| 290 completion_callback_.reset(); | |
| 291 } | |
| 292 is_fetching_ = false; | |
| 293 } | |
| OLD | NEW |