Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(124)

Side by Side Diff: chrome/browser/extensions/api/image_writer_private/operation.cc

Issue 2825963003: Rewrite base::Bind to base::BindOnce with base_bind_rewriters in //chrome/browser/extensions (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/extensions/api/image_writer_private/operation.h" 5 #include "chrome/browser/extensions/api/image_writer_private/operation.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/files/file_enumerator.h" 9 #include "base/files/file_enumerator.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 image_path_, 132 image_path_,
133 base::Bind(&Operation::CompleteAndContinue, this, continuation), 133 base::Bind(&Operation::CompleteAndContinue, this, continuation),
134 base::Bind(&Operation::OnUnzipFailure, this), 134 base::Bind(&Operation::OnUnzipFailure, this),
135 base::Bind(&Operation::OnUnzipProgress, 135 base::Bind(&Operation::OnUnzipProgress,
136 this, 136 this,
137 zip_reader_->current_entry_info()->original_size())); 137 zip_reader_->current_entry_info()->original_size()));
138 } 138 }
139 139
140 void Operation::Finish() { 140 void Operation::Finish() {
141 if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) { 141 if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) {
142 BrowserThread::PostTask( 142 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
143 BrowserThread::FILE, FROM_HERE, base::Bind(&Operation::Finish, this)); 143 base::BindOnce(&Operation::Finish, this));
144 return; 144 return;
145 } 145 }
146 146
147 CleanUp(); 147 CleanUp();
148 148
149 BrowserThread::PostTask( 149 BrowserThread::PostTask(
150 BrowserThread::UI, 150 BrowserThread::UI, FROM_HERE,
151 FROM_HERE, 151 base::BindOnce(&OperationManager::OnComplete, manager_, extension_id_));
152 base::Bind(&OperationManager::OnComplete, manager_, extension_id_));
153 } 152 }
154 153
155 void Operation::Error(const std::string& error_message) { 154 void Operation::Error(const std::string& error_message) {
156 if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) { 155 if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) {
157 BrowserThread::PostTask(BrowserThread::FILE, 156 BrowserThread::PostTask(
158 FROM_HERE, 157 BrowserThread::FILE, FROM_HERE,
159 base::Bind(&Operation::Error, this, error_message)); 158 base::BindOnce(&Operation::Error, this, error_message));
160 return; 159 return;
161 } 160 }
162 161
163 BrowserThread::PostTask( 162 BrowserThread::PostTask(
164 BrowserThread::UI, 163 BrowserThread::UI, FROM_HERE,
165 FROM_HERE, 164 base::BindOnce(&OperationManager::OnError, manager_, extension_id_,
166 base::Bind(&OperationManager::OnError, 165 stage_, progress_, error_message));
167 manager_,
168 extension_id_,
169 stage_,
170 progress_,
171 error_message));
172 166
173 CleanUp(); 167 CleanUp();
174 } 168 }
175 169
176 void Operation::SetProgress(int progress) { 170 void Operation::SetProgress(int progress) {
177 if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) { 171 if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) {
178 BrowserThread::PostTask( 172 BrowserThread::PostTask(
179 BrowserThread::FILE, 173 BrowserThread::FILE, FROM_HERE,
180 FROM_HERE, 174 base::BindOnce(&Operation::SetProgress, this, progress));
181 base::Bind(&Operation::SetProgress,
182 this,
183 progress));
184 return; 175 return;
185 } 176 }
186 177
187 if (progress <= progress_) { 178 if (progress <= progress_) {
188 return; 179 return;
189 } 180 }
190 181
191 if (IsCancelled()) { 182 if (IsCancelled()) {
192 return; 183 return;
193 } 184 }
194 185
195 progress_ = progress; 186 progress_ = progress;
196 187
197 BrowserThread::PostTask(BrowserThread::UI, 188 BrowserThread::PostTask(
198 FROM_HERE, 189 BrowserThread::UI, FROM_HERE,
199 base::Bind(&OperationManager::OnProgress, 190 base::BindOnce(&OperationManager::OnProgress, manager_, extension_id_,
200 manager_, 191 stage_, progress_));
201 extension_id_,
202 stage_,
203 progress_));
204 } 192 }
205 193
206 void Operation::SetStage(image_writer_api::Stage stage) { 194 void Operation::SetStage(image_writer_api::Stage stage) {
207 if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) { 195 if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) {
208 BrowserThread::PostTask( 196 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
209 BrowserThread::FILE, 197 base::BindOnce(&Operation::SetStage, this, stage));
210 FROM_HERE,
211 base::Bind(&Operation::SetStage,
212 this,
213 stage));
214 return; 198 return;
215 } 199 }
216 200
217 if (IsCancelled()) { 201 if (IsCancelled()) {
218 return; 202 return;
219 } 203 }
220 204
221 stage_ = stage; 205 stage_ = stage;
222 progress_ = 0; 206 progress_ = 0;
223 207
224 BrowserThread::PostTask( 208 BrowserThread::PostTask(
225 BrowserThread::UI, 209 BrowserThread::UI, FROM_HERE,
226 FROM_HERE, 210 base::BindOnce(&OperationManager::OnProgress, manager_, extension_id_,
227 base::Bind(&OperationManager::OnProgress, 211 stage_, progress_));
228 manager_,
229 extension_id_,
230 stage_,
231 progress_));
232 } 212 }
233 213
234 bool Operation::IsCancelled() { 214 bool Operation::IsCancelled() {
235 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 215 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
236 216
237 return stage_ == image_writer_api::STAGE_NONE; 217 return stage_ == image_writer_api::STAGE_NONE;
238 } 218 }
239 219
240 void Operation::AddCleanUpFunction(const base::Closure& callback) { 220 void Operation::AddCleanUpFunction(const base::Closure& callback) {
241 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 221 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 if (file_size <= 0) { 281 if (file_size <= 0) {
302 file_size = file.GetLength(); 282 file_size = file.GetLength();
303 if (file_size < 0) { 283 if (file_size < 0) {
304 Error(error::kImageOpenError); 284 Error(error::kImageOpenError);
305 return; 285 return;
306 } 286 }
307 } 287 }
308 288
309 BrowserThread::PostTask( 289 BrowserThread::PostTask(
310 BrowserThread::FILE, FROM_HERE, 290 BrowserThread::FILE, FROM_HERE,
311 base::Bind(&Operation::MD5Chunk, this, Passed(std::move(file)), 0, 291 base::BindOnce(&Operation::MD5Chunk, this, Passed(std::move(file)), 0,
312 file_size, progress_offset, progress_scale, callback)); 292 file_size, progress_offset, progress_scale, callback));
313 } 293 }
314 294
315 void Operation::MD5Chunk( 295 void Operation::MD5Chunk(
316 base::File file, 296 base::File file,
317 int64_t bytes_processed, 297 int64_t bytes_processed,
318 int64_t bytes_total, 298 int64_t bytes_total,
319 int progress_offset, 299 int progress_offset,
320 int progress_scale, 300 int progress_scale,
321 const base::Callback<void(const std::string&)>& callback) { 301 const base::Callback<void(const std::string&)>& callback) {
322 if (IsCancelled()) 302 if (IsCancelled())
(...skipping 16 matching lines...) Expand all
339 if (len == read_size) { 319 if (len == read_size) {
340 // Process data. 320 // Process data.
341 base::MD5Update(&md5_context_, base::StringPiece(buffer.get(), len)); 321 base::MD5Update(&md5_context_, base::StringPiece(buffer.get(), len));
342 int percent_curr = 322 int percent_curr =
343 ((bytes_processed + len) * progress_scale) / bytes_total + 323 ((bytes_processed + len) * progress_scale) / bytes_total +
344 progress_offset; 324 progress_offset;
345 SetProgress(percent_curr); 325 SetProgress(percent_curr);
346 326
347 BrowserThread::PostTask( 327 BrowserThread::PostTask(
348 BrowserThread::FILE, FROM_HERE, 328 BrowserThread::FILE, FROM_HERE,
349 base::Bind(&Operation::MD5Chunk, this, Passed(std::move(file)), 329 base::BindOnce(&Operation::MD5Chunk, this, Passed(std::move(file)),
350 bytes_processed + len, bytes_total, progress_offset, 330 bytes_processed + len, bytes_total, progress_offset,
351 progress_scale, callback)); 331 progress_scale, callback));
352 // Skip closing the file. 332 // Skip closing the file.
353 return; 333 return;
354 } else { 334 } else {
355 // We didn't read the bytes we expected. 335 // We didn't read the bytes we expected.
356 Error(error::kHashReadError); 336 Error(error::kHashReadError);
357 } 337 }
358 } 338 }
359 } 339 }
360 340
361 void Operation::OnUnzipFailure() { 341 void Operation::OnUnzipFailure() {
(...skipping 13 matching lines...) Expand all
375 for (std::vector<base::Closure>::iterator it = cleanup_functions_.begin(); 355 for (std::vector<base::Closure>::iterator it = cleanup_functions_.begin();
376 it != cleanup_functions_.end(); 356 it != cleanup_functions_.end();
377 ++it) { 357 ++it) {
378 it->Run(); 358 it->Run();
379 } 359 }
380 cleanup_functions_.clear(); 360 cleanup_functions_.clear();
381 } 361 }
382 362
383 } // namespace image_writer 363 } // namespace image_writer
384 } // namespace extensions 364 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698