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
3 // found in the LICENSE file.
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_
8 #include "base/callback_forward.h"
9 #include "base/macros.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "net/base/io_buffer.h"
16 class FileStreamReader
;
22 // Computes the (base-16 encoded) MD5 digest of data extracted from a file
24 class FileStreamMd5Digester
{
26 typedef base::Callback
<void(const std::string
&)> ResultCallback
;
28 FileStreamMd5Digester();
29 ~FileStreamMd5Digester();
31 // 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 // |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 // GetMd5Digest before the results of a previous call have been returned.
36 void GetMd5Digest(scoped_ptr
<storage::FileStreamReader
> stream_reader
,
37 const ResultCallback
& callback
);
40 // Kicks off a read of the next chunk from the stream.
41 void ReadNextChunk(const ResultCallback
& callback
);
42 // Handles the incoming chunk of data from a stream read.
43 void OnChunkRead(const ResultCallback
& callback
, int bytes_read
);
45 // Maximum chunk size for read operations.
46 scoped_ptr
<storage::FileStreamReader
> reader_
;
47 scoped_refptr
<net::IOBuffer
> buffer_
;
48 base::MD5Context md5_context_
;
50 DISALLOW_COPY_AND_ASSIGN(FileStreamMd5Digester
);
56 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_FILE_STREAM_MD5_DIGESTER_H_