| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_FILE_STREAM_MD5_DIGESTER
_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_FILE_STREAM_MD5_DIGESTER
_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_FILE_STREAM_MD5_DIGESTER
_H_ | 6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_FILE_STREAM_MD5_DIGESTER
_H_ |
| 7 | 7 |
| 8 #include <memory> |
| 9 |
| 8 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
| 9 #include "base/macros.h" | 11 #include "base/macros.h" |
| 10 #include "base/md5.h" | 12 #include "base/md5.h" |
| 11 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "net/base/io_buffer.h" | 14 #include "net/base/io_buffer.h" |
| 14 | 15 |
| 15 namespace storage { | 16 namespace storage { |
| 16 class FileStreamReader; | 17 class FileStreamReader; |
| 17 } | 18 } |
| 18 | 19 |
| 19 namespace drive { | 20 namespace drive { |
| 20 namespace util { | 21 namespace util { |
| 21 | 22 |
| 22 // Computes the (base-16 encoded) MD5 digest of data extracted from a file | 23 // Computes the (base-16 encoded) MD5 digest of data extracted from a file |
| 23 // stream. | 24 // stream. |
| 24 class FileStreamMd5Digester { | 25 class FileStreamMd5Digester { |
| 25 public: | 26 public: |
| 26 typedef base::Callback<void(const std::string&)> ResultCallback; | 27 typedef base::Callback<void(const std::string&)> ResultCallback; |
| 27 | 28 |
| 28 FileStreamMd5Digester(); | 29 FileStreamMd5Digester(); |
| 29 ~FileStreamMd5Digester(); | 30 ~FileStreamMd5Digester(); |
| 30 | 31 |
| 31 // Computes an MD5 digest of data read from the given |streamReader|. The | 32 // Computes an MD5 digest of data read from the given |streamReader|. The |
| 32 // work occurs asynchronously, and the resulting hash is returned via the | 33 // work occurs asynchronously, and the resulting hash is returned via the |
| 33 // |callback|. If an error occurs, |callback| is called with an empty string. | 34 // |callback|. If an error occurs, |callback| is called with an empty string. |
| 34 // Only one stream can be processed at a time by each digester. Do not call | 35 // Only one stream can be processed at a time by each digester. Do not call |
| 35 // GetMd5Digest before the results of a previous call have been returned. | 36 // GetMd5Digest before the results of a previous call have been returned. |
| 36 void GetMd5Digest(scoped_ptr<storage::FileStreamReader> stream_reader, | 37 void GetMd5Digest(std::unique_ptr<storage::FileStreamReader> stream_reader, |
| 37 const ResultCallback& callback); | 38 const ResultCallback& callback); |
| 38 | 39 |
| 39 private: | 40 private: |
| 40 // Kicks off a read of the next chunk from the stream. | 41 // Kicks off a read of the next chunk from the stream. |
| 41 void ReadNextChunk(const ResultCallback& callback); | 42 void ReadNextChunk(const ResultCallback& callback); |
| 42 // Handles the incoming chunk of data from a stream read. | 43 // Handles the incoming chunk of data from a stream read. |
| 43 void OnChunkRead(const ResultCallback& callback, int bytes_read); | 44 void OnChunkRead(const ResultCallback& callback, int bytes_read); |
| 44 | 45 |
| 45 // Maximum chunk size for read operations. | 46 // Maximum chunk size for read operations. |
| 46 scoped_ptr<storage::FileStreamReader> reader_; | 47 std::unique_ptr<storage::FileStreamReader> reader_; |
| 47 scoped_refptr<net::IOBuffer> buffer_; | 48 scoped_refptr<net::IOBuffer> buffer_; |
| 48 base::MD5Context md5_context_; | 49 base::MD5Context md5_context_; |
| 49 | 50 |
| 50 DISALLOW_COPY_AND_ASSIGN(FileStreamMd5Digester); | 51 DISALLOW_COPY_AND_ASSIGN(FileStreamMd5Digester); |
| 51 }; | 52 }; |
| 52 | 53 |
| 53 } // namespace util | 54 } // namespace util |
| 54 } // namespace drive | 55 } // namespace drive |
| 55 | 56 |
| 56 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_FILE_STREAM_MD5_DIGES
TER_H_ | 57 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_FILE_STREAM_MD5_DIGES
TER_H_ |
| OLD | NEW |