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_indexed_db_helper.h" | 5 #include "chrome/browser/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" |
(...skipping 29 matching lines...) Expand all Loading... |
40 | 40 |
41 // Enumerates all indexed database files in the WEBKIT thread. | 41 // Enumerates all indexed database files in the WEBKIT thread. |
42 void FetchIndexedDBInfoInWebKitThread(); | 42 void FetchIndexedDBInfoInWebKitThread(); |
43 // Notifies the completion callback in the UI thread. | 43 // Notifies the completion callback in the UI thread. |
44 void NotifyInUIThread(); | 44 void NotifyInUIThread(); |
45 // Delete a single indexed database in the WEBKIT thread. | 45 // Delete a single indexed database in the WEBKIT thread. |
46 void DeleteIndexedDBInWebKitThread(const GURL& origin); | 46 void DeleteIndexedDBInWebKitThread(const GURL& origin); |
47 | 47 |
48 scoped_refptr<IndexedDBContext> indexed_db_context_; | 48 scoped_refptr<IndexedDBContext> indexed_db_context_; |
49 | 49 |
50 // This only mutates in the WEBKIT thread. | 50 // Access to |indexed_db_info_| is triggered indirectly via the UI thread and |
| 51 // guarded by |is_fetching_|. This means |indexed_db_info_| is only accessed |
| 52 // while |is_fetching_| is true. The flag |is_fetching_| is only accessed on |
| 53 // the UI thread. |
| 54 // In the context of this class |indexed_db_info_| is only accessed on the |
| 55 // WEBKIT thread. |
51 std::list<IndexedDBInfo> indexed_db_info_; | 56 std::list<IndexedDBInfo> indexed_db_info_; |
52 | 57 |
53 // This only mutates on the UI thread. | 58 // This only mutates on the UI thread. |
54 base::Callback<void(const std::list<IndexedDBInfo>&)> completion_callback_; | 59 base::Callback<void(const std::list<IndexedDBInfo>&)> completion_callback_; |
55 | 60 |
56 // Indicates whether or not we're currently fetching information: | 61 // Indicates whether or not we're currently fetching information: |
57 // it's true when StartFetching() is called in the UI thread, and it's reset | 62 // it's true when StartFetching() is called in the UI thread, and it's reset |
58 // after we notified the callback in the UI thread. | 63 // after we notified the callback in the UI thread. |
59 // This only mutates on the UI thread. | 64 // This only mutates on the UI thread. |
60 bool is_fetching_; | 65 bool is_fetching_; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 | 149 |
145 BrowsingDataIndexedDBHelper::IndexedDBInfo::~IndexedDBInfo() {} | 150 BrowsingDataIndexedDBHelper::IndexedDBInfo::~IndexedDBInfo() {} |
146 | 151 |
147 // static | 152 // static |
148 BrowsingDataIndexedDBHelper* BrowsingDataIndexedDBHelper::Create( | 153 BrowsingDataIndexedDBHelper* BrowsingDataIndexedDBHelper::Create( |
149 Profile* profile) { | 154 Profile* profile) { |
150 return new BrowsingDataIndexedDBHelperImpl(profile); | 155 return new BrowsingDataIndexedDBHelperImpl(profile); |
151 } | 156 } |
152 | 157 |
153 CannedBrowsingDataIndexedDBHelper:: | 158 CannedBrowsingDataIndexedDBHelper:: |
154 PendingIndexedDBInfo::PendingIndexedDBInfo() { | |
155 } | |
156 | |
157 CannedBrowsingDataIndexedDBHelper:: | |
158 PendingIndexedDBInfo::PendingIndexedDBInfo(const GURL& origin, | 159 PendingIndexedDBInfo::PendingIndexedDBInfo(const GURL& origin, |
159 const string16& description) | 160 const string16& name) |
160 : origin(origin), | 161 : origin(origin), |
161 description(description) { | 162 name(name) { |
162 } | 163 } |
163 | 164 |
164 CannedBrowsingDataIndexedDBHelper:: | 165 CannedBrowsingDataIndexedDBHelper:: |
165 PendingIndexedDBInfo::~PendingIndexedDBInfo() { | 166 PendingIndexedDBInfo::~PendingIndexedDBInfo() { |
166 } | 167 } |
167 | 168 |
| 169 bool CannedBrowsingDataIndexedDBHelper::PendingIndexedDBInfo::operator<( |
| 170 const PendingIndexedDBInfo& other) const { |
| 171 if (origin == other.origin) |
| 172 return name < other.name; |
| 173 return origin < other.origin; |
| 174 } |
| 175 |
168 CannedBrowsingDataIndexedDBHelper::CannedBrowsingDataIndexedDBHelper() | 176 CannedBrowsingDataIndexedDBHelper::CannedBrowsingDataIndexedDBHelper() |
169 : is_fetching_(false) { | 177 : is_fetching_(false) { |
170 } | 178 } |
171 | 179 |
| 180 CannedBrowsingDataIndexedDBHelper::~CannedBrowsingDataIndexedDBHelper() {} |
| 181 |
172 CannedBrowsingDataIndexedDBHelper* CannedBrowsingDataIndexedDBHelper::Clone() { | 182 CannedBrowsingDataIndexedDBHelper* CannedBrowsingDataIndexedDBHelper::Clone() { |
173 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 183 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
174 CannedBrowsingDataIndexedDBHelper* clone = | 184 CannedBrowsingDataIndexedDBHelper* clone = |
175 new CannedBrowsingDataIndexedDBHelper(); | 185 new CannedBrowsingDataIndexedDBHelper(); |
176 | 186 |
177 base::AutoLock auto_lock(lock_); | 187 base::AutoLock auto_lock(lock_); |
178 clone->pending_indexed_db_info_ = pending_indexed_db_info_; | 188 clone->pending_indexed_db_info_ = pending_indexed_db_info_; |
179 clone->indexed_db_info_ = indexed_db_info_; | 189 clone->indexed_db_info_ = indexed_db_info_; |
180 return clone; | 190 return clone; |
181 } | 191 } |
182 | 192 |
183 void CannedBrowsingDataIndexedDBHelper::AddIndexedDB( | 193 void CannedBrowsingDataIndexedDBHelper::AddIndexedDB( |
184 const GURL& origin, const string16& description) { | 194 const GURL& origin, const string16& name) { |
185 if (!BrowsingDataHelper::HasValidScheme(origin)) | 195 if (!BrowsingDataHelper::HasValidScheme(origin)) |
186 return; // Non-websafe state is not considered browsing data. | 196 return; // Non-websafe state is not considered browsing data. |
187 | 197 |
188 base::AutoLock auto_lock(lock_); | 198 base::AutoLock auto_lock(lock_); |
189 pending_indexed_db_info_.push_back(PendingIndexedDBInfo(origin, description)); | 199 pending_indexed_db_info_.insert(PendingIndexedDBInfo(origin, name)); |
190 } | 200 } |
191 | 201 |
192 void CannedBrowsingDataIndexedDBHelper::Reset() { | 202 void CannedBrowsingDataIndexedDBHelper::Reset() { |
193 base::AutoLock auto_lock(lock_); | 203 base::AutoLock auto_lock(lock_); |
194 indexed_db_info_.clear(); | 204 indexed_db_info_.clear(); |
195 pending_indexed_db_info_.clear(); | 205 pending_indexed_db_info_.clear(); |
196 } | 206 } |
197 | 207 |
198 bool CannedBrowsingDataIndexedDBHelper::empty() const { | 208 bool CannedBrowsingDataIndexedDBHelper::empty() const { |
199 base::AutoLock auto_lock(lock_); | 209 base::AutoLock auto_lock(lock_); |
200 return indexed_db_info_.empty() && pending_indexed_db_info_.empty(); | 210 return indexed_db_info_.empty() && pending_indexed_db_info_.empty(); |
201 } | 211 } |
202 | 212 |
203 size_t CannedBrowsingDataIndexedDBHelper::GetIndexedDBCount() const { | 213 size_t CannedBrowsingDataIndexedDBHelper::GetIndexedDBCount() const { |
| 214 base::AutoLock auto_lock(lock_); |
204 return pending_indexed_db_info_.size(); | 215 return pending_indexed_db_info_.size(); |
205 } | 216 } |
206 | 217 |
| 218 const std::set<CannedBrowsingDataIndexedDBHelper::PendingIndexedDBInfo>& |
| 219 CannedBrowsingDataIndexedDBHelper::GetIndexedDBInfo() const { |
| 220 base::AutoLock auto_lock(lock_); |
| 221 return pending_indexed_db_info_; |
| 222 } |
| 223 |
207 void CannedBrowsingDataIndexedDBHelper::StartFetching( | 224 void CannedBrowsingDataIndexedDBHelper::StartFetching( |
208 const base::Callback<void(const std::list<IndexedDBInfo>&)>& callback) { | 225 const base::Callback<void(const std::list<IndexedDBInfo>&)>& callback) { |
209 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 226 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
210 DCHECK(!is_fetching_); | 227 DCHECK(!is_fetching_); |
211 DCHECK_EQ(false, callback.is_null()); | 228 DCHECK_EQ(false, callback.is_null()); |
212 | 229 |
213 is_fetching_ = true; | 230 is_fetching_ = true; |
214 completion_callback_ = callback; | 231 completion_callback_ = callback; |
215 BrowserThread::PostTask( | 232 BrowserThread::PostTask( |
216 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, | 233 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, |
217 base::Bind( | 234 base::Bind( |
218 &CannedBrowsingDataIndexedDBHelper::ConvertPendingInfoInWebKitThread, | 235 &CannedBrowsingDataIndexedDBHelper::ConvertPendingInfoInWebKitThread, |
219 this)); | 236 this)); |
220 } | 237 } |
221 | 238 |
222 CannedBrowsingDataIndexedDBHelper::~CannedBrowsingDataIndexedDBHelper() {} | |
223 | |
224 void CannedBrowsingDataIndexedDBHelper::ConvertPendingInfoInWebKitThread() { | 239 void CannedBrowsingDataIndexedDBHelper::ConvertPendingInfoInWebKitThread() { |
225 base::AutoLock auto_lock(lock_); | 240 base::AutoLock auto_lock(lock_); |
226 for (std::list<PendingIndexedDBInfo>::const_iterator | 241 indexed_db_info_.clear(); |
| 242 for (std::set<PendingIndexedDBInfo>::const_iterator |
227 info = pending_indexed_db_info_.begin(); | 243 info = pending_indexed_db_info_.begin(); |
228 info != pending_indexed_db_info_.end(); ++info) { | 244 info != pending_indexed_db_info_.end(); ++info) { |
229 bool duplicate = false; | |
230 for (std::list<IndexedDBInfo>::iterator | |
231 indexed_db = indexed_db_info_.begin(); | |
232 indexed_db != indexed_db_info_.end(); ++indexed_db) { | |
233 if (indexed_db->origin == info->origin) { | |
234 duplicate = true; | |
235 break; | |
236 } | |
237 } | |
238 if (duplicate) | |
239 continue; | |
240 | |
241 indexed_db_info_.push_back(IndexedDBInfo( | 245 indexed_db_info_.push_back(IndexedDBInfo( |
242 info->origin, | 246 info->origin, |
243 0, | 247 0, |
244 base::Time())); | 248 base::Time())); |
245 } | 249 } |
246 pending_indexed_db_info_.clear(); | |
247 | 250 |
248 BrowserThread::PostTask( | 251 BrowserThread::PostTask( |
249 BrowserThread::UI, FROM_HERE, | 252 BrowserThread::UI, FROM_HERE, |
250 base::Bind(&CannedBrowsingDataIndexedDBHelper::NotifyInUIThread, this)); | 253 base::Bind(&CannedBrowsingDataIndexedDBHelper::NotifyInUIThread, this)); |
251 } | 254 } |
252 | 255 |
253 void CannedBrowsingDataIndexedDBHelper::NotifyInUIThread() { | 256 void CannedBrowsingDataIndexedDBHelper::NotifyInUIThread() { |
254 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 257 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
255 DCHECK(is_fetching_); | 258 DCHECK(is_fetching_); |
256 | 259 |
257 completion_callback_.Run(indexed_db_info_); | 260 completion_callback_.Run(indexed_db_info_); |
258 completion_callback_.Reset(); | 261 completion_callback_.Reset(); |
259 is_fetching_ = false; | 262 is_fetching_ = false; |
260 } | 263 } |
OLD | NEW |