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..da8f360c3b65b3a83166db924babdfc7797acd7c 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,38 @@ 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: |
+ FileStreamMd5Digester(); |
+ ~FileStreamMd5Digester(); |
+ // Computes an MD5 digest of data read from the given |streamReader|. The |
mtomasz
2015/01/31 04:53:12
nit: \n\n after destructor?
Ben Kwa
2015/02/02 22:22:11
Done.
|
+ // 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> streamReader, |
mtomasz
2015/01/31 04:53:12
nit: stream_reader
Ben Kwa
2015/02/02 22:22:11
Done.
|
+ const base::Callback<void(const std::string&)>& callback); |
mtomasz
2015/01/31 04:53:12
nit: How about typedefing the callback within File
Ben Kwa
2015/02/02 22:22:11
Done.
|
+ |
+ private: |
+ // Kicks off a read of the next chunk from the stream. |
+ void readNextChunk(); |
mtomasz
2015/01/31 04:53:12
nit: read -> Read
Ben Kwa
2015/02/02 22:22:12
Done.
|
+ // Handles the incoming chunk of data from a stream read. |
+ void OnChunkRead(int result); |
+ |
+ private: |
+ // Maximum chunk size for read operations. |
+ static const int kBufferSize_ = 512 * 1024; // 512 kB. |
mtomasz
2015/01/31 04:53:12
nit: Also, do we need it to be in the header file?
mtomasz
2015/01/31 04:53:12
nit: Isn't the chunk too large? We're doing it on
mtomasz
2015/01/31 04:53:12
nit: This may be new if initializing static member
Ben Kwa
2015/02/02 22:22:11
So... this happens on the IO thread now. I asked
Ben Kwa
2015/02/02 22:22:12
I figured that keeping this constant scoped within
Ben Kwa
2015/02/02 22:22:12
The style guides don't explicitly say anything abo
|
+ scoped_ptr<storage::FileStreamReader> reader_; |
+ base::Callback<void(const std::string&)> callback_; |
+ scoped_refptr<net::IOBuffer> buffer_; |
+ base::MD5Context md5Context_; |
mtomasz
2015/01/31 04:53:12
nit: camelCase -> is_not_allowed
Ben Kwa
2015/02/02 22:22:12
Done.
|
+ |
+ base::WeakPtrFactory<FileStreamMd5Digester> weak_ptr_factory_; |
+ 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); |