OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/drive/drive_api_util.h" | 5 #include "chrome/browser/drive/drive_api_util.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/files/file.h" | 9 #include "base/files/file.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
185 } | 185 } |
186 | 186 |
187 void FileStreamMd5Digester::ReadNextChunk() { | 187 void FileStreamMd5Digester::ReadNextChunk() { |
188 const int result = reader_->Read( | 188 const int result = reader_->Read( |
189 buffer_.get(), kMd5DigestBufferSize, | 189 buffer_.get(), kMd5DigestBufferSize, |
190 base::Bind(&FileStreamMd5Digester::OnChunkRead, base::Unretained(this))); | 190 base::Bind(&FileStreamMd5Digester::OnChunkRead, base::Unretained(this))); |
191 if (result != net::ERR_IO_PENDING) | 191 if (result != net::ERR_IO_PENDING) |
192 OnChunkRead(result); | 192 OnChunkRead(result); |
193 } | 193 } |
194 | 194 |
195 void FileStreamMd5Digester::OnChunkRead(int result) { | 195 void FileStreamMd5Digester::OnChunkRead(int bytesRead) { |
mtomasz
2015/02/25 02:36:30
nit: bytes_read.
| |
196 if (result < 0) { | 196 if (bytesRead < 0) { |
197 // Error - just return empty string. | 197 // Error - just return empty string. |
198 callback_.Run(""); | 198 callback_.Run(""); |
199 return; | 199 return; |
200 } else if (result == 0) { | 200 } else if (bytesRead == 0) { |
201 // EOF. | 201 // EOF. |
202 base::MD5Digest digest; | 202 base::MD5Digest digest; |
203 base::MD5Final(&digest, &md5_context_); | 203 base::MD5Final(&digest, &md5_context_); |
204 std::string result = MD5DigestToBase16(digest); | 204 std::string result = MD5DigestToBase16(digest); |
205 callback_.Run(result); | 205 callback_.Run(result); |
206 return; | 206 return; |
207 } | 207 } |
208 | 208 |
209 // Read data and digest it. | 209 // Read data and digest it. |
210 base::MD5Update(&md5_context_, base::StringPiece(buffer_->data(), result)); | 210 base::MD5Update(&md5_context_, base::StringPiece(buffer_->data(), bytesRead)); |
211 | 211 |
212 // Kick off the next read. | 212 // Kick off the next read. |
213 ReadNextChunk(); | 213 ReadNextChunk(); |
214 } | 214 } |
215 | 215 |
216 std::string GetHostedDocumentExtension(const std::string& mime_type) { | 216 std::string GetHostedDocumentExtension(const std::string& mime_type) { |
217 for (size_t i = 0; i < arraysize(kHostedDocumentKinds); ++i) { | 217 for (size_t i = 0; i < arraysize(kHostedDocumentKinds); ++i) { |
218 if (mime_type == kHostedDocumentKinds[i].mime_type) | 218 if (mime_type == kHostedDocumentKinds[i].mime_type) |
219 return kHostedDocumentKinds[i].extension; | 219 return kHostedDocumentKinds[i].extension; |
220 } | 220 } |
(...skipping 12 matching lines...) Expand all Loading... | |
233 const std::string extension = base::FilePath(path.Extension()).AsUTF8Unsafe(); | 233 const std::string extension = base::FilePath(path.Extension()).AsUTF8Unsafe(); |
234 for (size_t i = 0; i < arraysize(kHostedDocumentKinds); ++i) { | 234 for (size_t i = 0; i < arraysize(kHostedDocumentKinds); ++i) { |
235 if (extension == kHostedDocumentKinds[i].extension) | 235 if (extension == kHostedDocumentKinds[i].extension) |
236 return true; | 236 return true; |
237 } | 237 } |
238 return extension == kUnknownHostedDocumentExtension; | 238 return extension == kUnknownHostedDocumentExtension; |
239 } | 239 } |
240 | 240 |
241 } // namespace util | 241 } // namespace util |
242 } // namespace drive | 242 } // namespace drive |
OLD | NEW |