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_file_system_helper.h" | 5 #include "chrome/browser/browsing_data/browsing_data_file_system_helper.h" |
6 | 6 |
| 7 #include <set> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
9 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
10 #include "base/sequenced_task_runner.h" | 12 #include "base/sequenced_task_runner.h" |
11 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
12 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
13 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 15 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
14 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
15 #include "webkit/browser/fileapi/file_system_context.h" | 17 #include "webkit/browser/fileapi/file_system_context.h" |
16 #include "webkit/browser/fileapi/file_system_quota_util.h" | 18 #include "webkit/browser/fileapi/file_system_quota_util.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 : filesystem_context_(filesystem_context), | 90 : filesystem_context_(filesystem_context), |
89 is_fetching_(false) { | 91 is_fetching_(false) { |
90 DCHECK(filesystem_context_.get()); | 92 DCHECK(filesystem_context_.get()); |
91 } | 93 } |
92 | 94 |
93 BrowsingDataFileSystemHelperImpl::~BrowsingDataFileSystemHelperImpl() { | 95 BrowsingDataFileSystemHelperImpl::~BrowsingDataFileSystemHelperImpl() { |
94 } | 96 } |
95 | 97 |
96 void BrowsingDataFileSystemHelperImpl::StartFetching( | 98 void BrowsingDataFileSystemHelperImpl::StartFetching( |
97 const base::Callback<void(const std::list<FileSystemInfo>&)>& callback) { | 99 const base::Callback<void(const std::list<FileSystemInfo>&)>& callback) { |
98 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 100 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
99 DCHECK(!is_fetching_); | 101 DCHECK(!is_fetching_); |
100 DCHECK_EQ(false, callback.is_null()); | 102 DCHECK(!callback.is_null()); |
101 is_fetching_ = true; | 103 is_fetching_ = true; |
102 completion_callback_ = callback; | 104 completion_callback_ = callback; |
103 file_task_runner()->PostTask( | 105 file_task_runner()->PostTask( |
104 FROM_HERE, | 106 FROM_HERE, |
105 base::Bind( | 107 base::Bind( |
106 &BrowsingDataFileSystemHelperImpl::FetchFileSystemInfoInFileThread, | 108 &BrowsingDataFileSystemHelperImpl::FetchFileSystemInfoInFileThread, |
107 this)); | 109 this)); |
108 } | 110 } |
109 | 111 |
110 void BrowsingDataFileSystemHelperImpl::DeleteFileSystemOrigin( | 112 void BrowsingDataFileSystemHelperImpl::DeleteFileSystemOrigin( |
111 const GURL& origin) { | 113 const GURL& origin) { |
112 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 114 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
113 file_task_runner()->PostTask( | 115 file_task_runner()->PostTask( |
114 FROM_HERE, | 116 FROM_HERE, |
115 base::Bind( | 117 base::Bind( |
116 &BrowsingDataFileSystemHelperImpl::DeleteFileSystemOriginInFileThread, | 118 &BrowsingDataFileSystemHelperImpl::DeleteFileSystemOriginInFileThread, |
117 this, origin)); | 119 this, origin)); |
118 } | 120 } |
119 | 121 |
120 void BrowsingDataFileSystemHelperImpl::FetchFileSystemInfoInFileThread() { | 122 void BrowsingDataFileSystemHelperImpl::FetchFileSystemInfoInFileThread() { |
121 DCHECK(file_task_runner()->RunsTasksOnCurrentThread()); | 123 DCHECK(file_task_runner()->RunsTasksOnCurrentThread()); |
122 | 124 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 iter != file_system_info_map.end(); ++iter) { | 158 iter != file_system_info_map.end(); ++iter) { |
157 file_system_info_.push_back(iter->second); | 159 file_system_info_.push_back(iter->second); |
158 } | 160 } |
159 | 161 |
160 BrowserThread::PostTask( | 162 BrowserThread::PostTask( |
161 BrowserThread::UI, FROM_HERE, | 163 BrowserThread::UI, FROM_HERE, |
162 base::Bind(&BrowsingDataFileSystemHelperImpl::NotifyOnUIThread, this)); | 164 base::Bind(&BrowsingDataFileSystemHelperImpl::NotifyOnUIThread, this)); |
163 } | 165 } |
164 | 166 |
165 void BrowsingDataFileSystemHelperImpl::NotifyOnUIThread() { | 167 void BrowsingDataFileSystemHelperImpl::NotifyOnUIThread() { |
166 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 168 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
167 DCHECK(is_fetching_); | 169 DCHECK(is_fetching_); |
168 completion_callback_.Run(file_system_info_); | 170 completion_callback_.Run(file_system_info_); |
169 completion_callback_.Reset(); | 171 completion_callback_.Reset(); |
170 is_fetching_ = false; | 172 is_fetching_ = false; |
171 } | 173 } |
172 | 174 |
173 void BrowsingDataFileSystemHelperImpl::DeleteFileSystemOriginInFileThread( | 175 void BrowsingDataFileSystemHelperImpl::DeleteFileSystemOriginInFileThread( |
174 const GURL& origin) { | 176 const GURL& origin) { |
175 DCHECK(file_task_runner()->RunsTasksOnCurrentThread()); | 177 DCHECK(file_task_runner()->RunsTasksOnCurrentThread()); |
176 filesystem_context_->DeleteDataForOriginOnFileTaskRunner(origin); | 178 filesystem_context_->DeleteDataForOriginOnFileTaskRunner(origin); |
(...skipping 16 matching lines...) Expand all Loading... |
193 Profile* profile) { | 195 Profile* profile) { |
194 } | 196 } |
195 | 197 |
196 CannedBrowsingDataFileSystemHelper::CannedBrowsingDataFileSystemHelper() { | 198 CannedBrowsingDataFileSystemHelper::CannedBrowsingDataFileSystemHelper() { |
197 } | 199 } |
198 | 200 |
199 CannedBrowsingDataFileSystemHelper::~CannedBrowsingDataFileSystemHelper() {} | 201 CannedBrowsingDataFileSystemHelper::~CannedBrowsingDataFileSystemHelper() {} |
200 | 202 |
201 CannedBrowsingDataFileSystemHelper* | 203 CannedBrowsingDataFileSystemHelper* |
202 CannedBrowsingDataFileSystemHelper::Clone() { | 204 CannedBrowsingDataFileSystemHelper::Clone() { |
203 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 205 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
204 CannedBrowsingDataFileSystemHelper* clone = | 206 CannedBrowsingDataFileSystemHelper* clone = |
205 new CannedBrowsingDataFileSystemHelper(); | 207 new CannedBrowsingDataFileSystemHelper(); |
206 // This list only mutates on the UI thread, so it's safe to work with it here | 208 // This list only mutates on the UI thread, so it's safe to work with it here |
207 // (given the DCHECK above). | 209 // (given the DCHECK above). |
208 clone->file_system_info_ = file_system_info_; | 210 clone->file_system_info_ = file_system_info_; |
209 return clone; | 211 return clone; |
210 } | 212 } |
211 | 213 |
212 void CannedBrowsingDataFileSystemHelper::AddFileSystem( | 214 void CannedBrowsingDataFileSystemHelper::AddFileSystem( |
213 const GURL& origin, const fileapi::FileSystemType type, const int64 size) { | 215 const GURL& origin, const fileapi::FileSystemType type, const int64 size) { |
214 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 216 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
215 // This canned implementation of AddFileSystem uses an O(n^2) algorithm; which | 217 // This canned implementation of AddFileSystem uses an O(n^2) algorithm; which |
216 // is fine, as it isn't meant for use in a high-volume context. If it turns | 218 // is fine, as it isn't meant for use in a high-volume context. If it turns |
217 // out that we want to start using this in a context with many, many origins, | 219 // out that we want to start using this in a context with many, many origins, |
218 // we should think about reworking the implementation. | 220 // we should think about reworking the implementation. |
219 bool duplicate_origin = false; | 221 bool duplicate_origin = false; |
220 for (std::list<FileSystemInfo>::iterator | 222 for (std::list<FileSystemInfo>::iterator |
221 file_system = file_system_info_.begin(); | 223 file_system = file_system_info_.begin(); |
222 file_system != file_system_info_.end(); | 224 file_system != file_system_info_.end(); |
223 ++file_system) { | 225 ++file_system) { |
224 if (file_system->origin == origin) { | 226 if (file_system->origin == origin) { |
(...skipping 15 matching lines...) Expand all Loading... |
240 | 242 |
241 void CannedBrowsingDataFileSystemHelper::Reset() { | 243 void CannedBrowsingDataFileSystemHelper::Reset() { |
242 file_system_info_.clear(); | 244 file_system_info_.clear(); |
243 } | 245 } |
244 | 246 |
245 bool CannedBrowsingDataFileSystemHelper::empty() const { | 247 bool CannedBrowsingDataFileSystemHelper::empty() const { |
246 return file_system_info_.empty(); | 248 return file_system_info_.empty(); |
247 } | 249 } |
248 | 250 |
249 size_t CannedBrowsingDataFileSystemHelper::GetFileSystemCount() const { | 251 size_t CannedBrowsingDataFileSystemHelper::GetFileSystemCount() const { |
250 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 252 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
251 return file_system_info_.size(); | 253 return file_system_info_.size(); |
252 } | 254 } |
253 | 255 |
254 void CannedBrowsingDataFileSystemHelper::StartFetching( | 256 void CannedBrowsingDataFileSystemHelper::StartFetching( |
255 const base::Callback<void(const std::list<FileSystemInfo>&)>& callback) { | 257 const base::Callback<void(const std::list<FileSystemInfo>&)>& callback) { |
256 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 258 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
257 DCHECK(!callback.is_null()); | 259 DCHECK(!callback.is_null()); |
258 | 260 |
259 BrowserThread::PostTask( | 261 BrowserThread::PostTask( |
260 BrowserThread::UI, FROM_HERE, base::Bind(callback, file_system_info_)); | 262 BrowserThread::UI, FROM_HERE, base::Bind(callback, file_system_info_)); |
261 } | 263 } |
OLD | NEW |