OLD | NEW |
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 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 int64_t bytes_processed, | 323 int64_t bytes_processed, |
324 int64_t bytes_total, | 324 int64_t bytes_total, |
325 int progress_offset, | 325 int progress_offset, |
326 int progress_scale, | 326 int progress_scale, |
327 const base::Callback<void(const std::string&)>& callback) { | 327 const base::Callback<void(const std::string&)>& callback) { |
328 if (IsCancelled()) | 328 if (IsCancelled()) |
329 return; | 329 return; |
330 | 330 |
331 CHECK_LE(bytes_processed, bytes_total); | 331 CHECK_LE(bytes_processed, bytes_total); |
332 | 332 |
333 scoped_ptr<char[]> buffer(new char[kMD5BufferSize]); | 333 std::unique_ptr<char[]> buffer(new char[kMD5BufferSize]); |
334 int read_size = std::min(bytes_total - bytes_processed, | 334 int read_size = std::min(bytes_total - bytes_processed, |
335 static_cast<int64_t>(kMD5BufferSize)); | 335 static_cast<int64_t>(kMD5BufferSize)); |
336 | 336 |
337 if (read_size == 0) { | 337 if (read_size == 0) { |
338 // Nothing to read, we are done. | 338 // Nothing to read, we are done. |
339 base::MD5Digest digest; | 339 base::MD5Digest digest; |
340 base::MD5Final(&digest, &md5_context_); | 340 base::MD5Final(&digest, &md5_context_); |
341 callback.Run(base::MD5DigestToBase16(digest)); | 341 callback.Run(base::MD5DigestToBase16(digest)); |
342 } else { | 342 } else { |
343 int len = file.Read(bytes_processed, buffer.get(), read_size); | 343 int len = file.Read(bytes_processed, buffer.get(), read_size); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 for (std::vector<base::Closure>::iterator it = cleanup_functions_.begin(); | 381 for (std::vector<base::Closure>::iterator it = cleanup_functions_.begin(); |
382 it != cleanup_functions_.end(); | 382 it != cleanup_functions_.end(); |
383 ++it) { | 383 ++it) { |
384 it->Run(); | 384 it->Run(); |
385 } | 385 } |
386 cleanup_functions_.clear(); | 386 cleanup_functions_.clear(); |
387 } | 387 } |
388 | 388 |
389 } // namespace image_writer | 389 } // namespace image_writer |
390 } // namespace extensions | 390 } // namespace extensions |
OLD | NEW |