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