BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / chromeos / extensions / file_manager / file_stream_md5_digester.h
blob9329f30359da99c711320bd12c5bd9a93d4839ff
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"
10 #include "base/md5.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "net/base/io_buffer.h"
15 namespace storage {
16 class FileStreamReader;
19 namespace drive {
20 namespace util {
22 // Computes the (base-16 encoded) MD5 digest of data extracted from a file
23 // stream.
24 class FileStreamMd5Digester {
25 public:
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);
39 private:
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);
53 } // namespace util
54 } // namespace drive
56 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_FILE_STREAM_MD5_DIGESTER_H_