| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browsing_data_indexed_db_helper.h" | 5 #include "chrome/browser/browsing_data/browsing_data_indexed_db_helper.h" |
| 6 | 6 |
| 7 #include <vector> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/callback.h" | 10 #include "base/callback.h" |
| 9 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 10 #include "base/file_util.h" | 12 #include "base/file_util.h" |
| 11 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 13 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 14 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
| 15 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 17 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
| 16 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/indexed_db_context.h" | 19 #include "content/public/browser/indexed_db_context.h" |
| 18 #include "webkit/database/database_util.h" | 20 #include "webkit/database/database_util.h" |
| 19 #include "webkit/glue/webkit_glue.h" | 21 #include "webkit/glue/webkit_glue.h" |
| 20 | 22 |
| 21 using content::BrowserThread; | 23 using content::BrowserThread; |
| 22 using content::IndexedDBContext; | 24 using content::IndexedDBContext; |
| 25 using content::IndexedDBInfo; |
| 23 using webkit_database::DatabaseUtil; | 26 using webkit_database::DatabaseUtil; |
| 24 | 27 |
| 25 namespace { | 28 namespace { |
| 26 | 29 |
| 27 class BrowsingDataIndexedDBHelperImpl : public BrowsingDataIndexedDBHelper { | 30 class BrowsingDataIndexedDBHelperImpl : public BrowsingDataIndexedDBHelper { |
| 28 public: | 31 public: |
| 29 explicit BrowsingDataIndexedDBHelperImpl( | 32 explicit BrowsingDataIndexedDBHelperImpl( |
| 30 IndexedDBContext* indexed_db_context); | 33 IndexedDBContext* indexed_db_context); |
| 31 | 34 |
| 32 virtual void StartFetching( | 35 virtual void StartFetching( |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 99 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 97 BrowserThread::PostTask( | 100 BrowserThread::PostTask( |
| 98 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, | 101 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, |
| 99 base::Bind( | 102 base::Bind( |
| 100 &BrowsingDataIndexedDBHelperImpl::DeleteIndexedDBInWebKitThread, this, | 103 &BrowsingDataIndexedDBHelperImpl::DeleteIndexedDBInWebKitThread, this, |
| 101 origin)); | 104 origin)); |
| 102 } | 105 } |
| 103 | 106 |
| 104 void BrowsingDataIndexedDBHelperImpl::FetchIndexedDBInfoInWebKitThread() { | 107 void BrowsingDataIndexedDBHelperImpl::FetchIndexedDBInfoInWebKitThread() { |
| 105 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 108 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); |
| 106 std::vector<GURL> origins = indexed_db_context_->GetAllOrigins(); | 109 std::vector<IndexedDBInfo> origins = indexed_db_context_->GetAllOriginsInfo(); |
| 107 for (std::vector<GURL>::const_iterator iter = origins.begin(); | 110 for (std::vector<IndexedDBInfo>::const_iterator iter = origins.begin(); |
| 108 iter != origins.end(); ++iter) { | 111 iter != origins.end(); ++iter) { |
| 109 const GURL& origin = *iter; | 112 const IndexedDBInfo& origin = *iter; |
| 110 if (!BrowsingDataHelper::HasWebScheme(origin)) | 113 if (!BrowsingDataHelper::HasWebScheme(origin.origin)) |
| 111 continue; // Non-websafe state is not considered browsing data. | 114 continue; // Non-websafe state is not considered browsing data. |
| 112 | 115 |
| 113 indexed_db_info_.push_back(IndexedDBInfo( | 116 indexed_db_info_.push_back(origin); |
| 114 origin, | |
| 115 indexed_db_context_->GetOriginDiskUsage(origin), | |
| 116 indexed_db_context_->GetOriginLastModified(origin))); | |
| 117 } | 117 } |
| 118 | 118 |
| 119 BrowserThread::PostTask( | 119 BrowserThread::PostTask( |
| 120 BrowserThread::UI, FROM_HERE, | 120 BrowserThread::UI, FROM_HERE, |
| 121 base::Bind(&BrowsingDataIndexedDBHelperImpl::NotifyInUIThread, this)); | 121 base::Bind(&BrowsingDataIndexedDBHelperImpl::NotifyInUIThread, this)); |
| 122 } | 122 } |
| 123 | 123 |
| 124 void BrowsingDataIndexedDBHelperImpl::NotifyInUIThread() { | 124 void BrowsingDataIndexedDBHelperImpl::NotifyInUIThread() { |
| 125 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 125 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 126 DCHECK(is_fetching_); | 126 DCHECK(is_fetching_); |
| 127 completion_callback_.Run(indexed_db_info_); | 127 completion_callback_.Run(indexed_db_info_); |
| 128 completion_callback_.Reset(); | 128 completion_callback_.Reset(); |
| 129 is_fetching_ = false; | 129 is_fetching_ = false; |
| 130 } | 130 } |
| 131 | 131 |
| 132 void BrowsingDataIndexedDBHelperImpl::DeleteIndexedDBInWebKitThread( | 132 void BrowsingDataIndexedDBHelperImpl::DeleteIndexedDBInWebKitThread( |
| 133 const GURL& origin) { | 133 const GURL& origin) { |
| 134 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 134 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); |
| 135 indexed_db_context_->DeleteForOrigin(origin); | 135 indexed_db_context_->DeleteForOrigin(origin); |
| 136 } | 136 } |
| 137 | 137 |
| 138 } // namespace | 138 } // namespace |
| 139 | 139 |
| 140 BrowsingDataIndexedDBHelper::IndexedDBInfo::IndexedDBInfo( | |
| 141 const GURL& origin, | |
| 142 int64 size, | |
| 143 base::Time last_modified) | |
| 144 : origin(origin), | |
| 145 size(size), | |
| 146 last_modified(last_modified) { | |
| 147 } | |
| 148 | |
| 149 BrowsingDataIndexedDBHelper::IndexedDBInfo::~IndexedDBInfo() {} | |
| 150 | 140 |
| 151 // static | 141 // static |
| 152 BrowsingDataIndexedDBHelper* BrowsingDataIndexedDBHelper::Create( | 142 BrowsingDataIndexedDBHelper* BrowsingDataIndexedDBHelper::Create( |
| 153 IndexedDBContext* indexed_db_context) { | 143 IndexedDBContext* indexed_db_context) { |
| 154 return new BrowsingDataIndexedDBHelperImpl(indexed_db_context); | 144 return new BrowsingDataIndexedDBHelperImpl(indexed_db_context); |
| 155 } | 145 } |
| 156 | 146 |
| 157 CannedBrowsingDataIndexedDBHelper:: | 147 CannedBrowsingDataIndexedDBHelper:: |
| 158 PendingIndexedDBInfo::PendingIndexedDBInfo(const GURL& origin, | 148 PendingIndexedDBInfo::PendingIndexedDBInfo(const GURL& origin, |
| 159 const string16& name) | 149 const string16& name) |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, | 222 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, |
| 233 base::Bind( | 223 base::Bind( |
| 234 &CannedBrowsingDataIndexedDBHelper::ConvertPendingInfoInWebKitThread, | 224 &CannedBrowsingDataIndexedDBHelper::ConvertPendingInfoInWebKitThread, |
| 235 this)); | 225 this)); |
| 236 } | 226 } |
| 237 | 227 |
| 238 void CannedBrowsingDataIndexedDBHelper::ConvertPendingInfoInWebKitThread() { | 228 void CannedBrowsingDataIndexedDBHelper::ConvertPendingInfoInWebKitThread() { |
| 239 base::AutoLock auto_lock(lock_); | 229 base::AutoLock auto_lock(lock_); |
| 240 indexed_db_info_.clear(); | 230 indexed_db_info_.clear(); |
| 241 for (std::set<PendingIndexedDBInfo>::const_iterator | 231 for (std::set<PendingIndexedDBInfo>::const_iterator |
| 242 info = pending_indexed_db_info_.begin(); | 232 pending_info = pending_indexed_db_info_.begin(); |
| 243 info != pending_indexed_db_info_.end(); ++info) { | 233 pending_info != pending_indexed_db_info_.end(); ++pending_info) { |
| 244 indexed_db_info_.push_back(IndexedDBInfo( | 234 IndexedDBInfo info(pending_info->origin, 0, base::Time()); |
| 245 info->origin, | 235 indexed_db_info_.push_back(info); |
| 246 0, | |
| 247 base::Time())); | |
| 248 } | 236 } |
| 249 | 237 |
| 250 BrowserThread::PostTask( | 238 BrowserThread::PostTask( |
| 251 BrowserThread::UI, FROM_HERE, | 239 BrowserThread::UI, FROM_HERE, |
| 252 base::Bind(&CannedBrowsingDataIndexedDBHelper::NotifyInUIThread, this)); | 240 base::Bind(&CannedBrowsingDataIndexedDBHelper::NotifyInUIThread, this)); |
| 253 } | 241 } |
| 254 | 242 |
| 255 void CannedBrowsingDataIndexedDBHelper::NotifyInUIThread() { | 243 void CannedBrowsingDataIndexedDBHelper::NotifyInUIThread() { |
| 256 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 244 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 257 DCHECK(is_fetching_); | 245 DCHECK(is_fetching_); |
| 258 | 246 |
| 259 completion_callback_.Run(indexed_db_info_); | 247 completion_callback_.Run(indexed_db_info_); |
| 260 completion_callback_.Reset(); | 248 completion_callback_.Reset(); |
| 261 is_fetching_ = false; | 249 is_fetching_ = false; |
| 262 } | 250 } |
| OLD | NEW |