Index: chrome/browser/drive/drive_api_util.h |
diff --git a/chrome/browser/drive/drive_api_util.h b/chrome/browser/drive/drive_api_util.h |
index 95771ca266ac150ee548a6af9e007f8fafef2f7f..977d6bbbcabff7d2451e45b450db902394614687 100644 |
--- a/chrome/browser/drive/drive_api_util.h |
+++ b/chrome/browser/drive/drive_api_util.h |
@@ -7,6 +7,7 @@ |
#include <string> |
+#include "base/md5.h" |
#include "base/memory/scoped_ptr.h" |
#include "google_apis/drive/drive_api_error_codes.h" |
#include "google_apis/drive/drive_common_callbacks.h" |
@@ -26,6 +27,14 @@ class FileResource; |
class ResourceEntry; |
} // namespace google_apis |
+namespace net { |
+class IOBuffer; |
+} // namespace net |
+ |
+namespace storage { |
+class FileStreamReader; |
+} // namespace storage |
+ |
namespace drive { |
namespace util { |
@@ -64,6 +73,43 @@ std::string CanonicalizeResourceId(const std::string& resource_id); |
// or an empty string if an error is found. |
std::string GetMd5Digest(const base::FilePath& file_path); |
+// Computes the (base-16 encoded) MD5 digest of data extracted from a file |
+// stream. |
+class FileStreamMd5Digester |
+ : public base::RefCountedThreadSafe<FileStreamMd5Digester> { |
+ public: |
+ typedef base::Callback<void(const std::string&)> ResultCallback; |
+ |
+ FileStreamMd5Digester(); |
+ |
+ // Computes an MD5 digest of data read from the given |streamReader|. The |
+ // work occurs asynchronously, and the resulting hash is returned via the |
+ // |callback|. If an error occurs, |callback| is called with an empty string. |
+ // Only one stream can be processed at a time by each digester. Do not call |
+ // GetMd5Digest before the results of a previous call have been returned. |
+ void GetMd5Digest(scoped_ptr<storage::FileStreamReader> stream_reader, |
+ const ResultCallback& callback); |
+ |
+ private: |
+ // Private for RefCountedThreadSafe. |
+ ~FileStreamMd5Digester(); |
+ |
+ // Kicks off a read of the next chunk from the stream. |
+ void ReadNextChunk(); |
+ // Handles the incoming chunk of data from a stream read. |
+ void OnChunkRead(int result); |
+ |
+ // Maximum chunk size for read operations. |
+ static const int kBufferSize_ = 512 * 1024; // 512 kB. |
mtomasz
2015/02/02 23:47:08
nit: Yeah, I'd suggest to move it to an anonymous
Ben Kwa
2015/02/03 16:32:19
Done.
|
+ scoped_ptr<storage::FileStreamReader> reader_; |
+ ResultCallback callback_; |
+ scoped_refptr<net::IOBuffer> buffer_; |
+ base::MD5Context md5_context_; |
+ |
+ friend class base::RefCountedThreadSafe<FileStreamMd5Digester>; |
+ DISALLOW_COPY_AND_ASSIGN(FileStreamMd5Digester); |
+}; |
+ |
// Returns preferred file extension for hosted documents which have given mime |
// type. |
std::string GetHostedDocumentExtension(const std::string& mime_type); |