| 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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 // End of file. | 161 // End of file. |
| 162 break; | 162 break; |
| 163 } | 163 } |
| 164 | 164 |
| 165 offset += result; | 165 offset += result; |
| 166 base::MD5Update(&context, base::StringPiece(buffer.get(), result)); | 166 base::MD5Update(&context, base::StringPiece(buffer.get(), result)); |
| 167 } | 167 } |
| 168 | 168 |
| 169 base::MD5Digest digest; | 169 base::MD5Digest digest; |
| 170 base::MD5Final(&digest, &context); | 170 base::MD5Final(&digest, &context); |
| 171 return MD5DigestToBase16(digest); | 171 return base::MD5DigestToBase16(digest); |
| 172 } | 172 } |
| 173 | 173 |
| 174 FileStreamMd5Digester::FileStreamMd5Digester() | 174 FileStreamMd5Digester::FileStreamMd5Digester() |
| 175 : buffer_(new net::IOBuffer(kMd5DigestBufferSize)) { | 175 : buffer_(new net::IOBuffer(kMd5DigestBufferSize)) { |
| 176 } | 176 } |
| 177 | 177 |
| 178 FileStreamMd5Digester::~FileStreamMd5Digester() { | 178 FileStreamMd5Digester::~FileStreamMd5Digester() { |
| 179 } | 179 } |
| 180 | 180 |
| 181 void FileStreamMd5Digester::GetMd5Digest( | 181 void FileStreamMd5Digester::GetMd5Digest( |
| (...skipping 18 matching lines...) Expand all Loading... |
| 200 void FileStreamMd5Digester::OnChunkRead(const ResultCallback& callback, | 200 void FileStreamMd5Digester::OnChunkRead(const ResultCallback& callback, |
| 201 int bytes_read) { | 201 int bytes_read) { |
| 202 if (bytes_read < 0) { | 202 if (bytes_read < 0) { |
| 203 // Error - just return empty string. | 203 // Error - just return empty string. |
| 204 callback.Run(""); | 204 callback.Run(""); |
| 205 return; | 205 return; |
| 206 } else if (bytes_read == 0) { | 206 } else if (bytes_read == 0) { |
| 207 // EOF. | 207 // EOF. |
| 208 base::MD5Digest digest; | 208 base::MD5Digest digest; |
| 209 base::MD5Final(&digest, &md5_context_); | 209 base::MD5Final(&digest, &md5_context_); |
| 210 std::string result = MD5DigestToBase16(digest); | 210 std::string result = base::MD5DigestToBase16(digest); |
| 211 callback.Run(result); | 211 callback.Run(result); |
| 212 return; | 212 return; |
| 213 } | 213 } |
| 214 | 214 |
| 215 // Read data and digest it. | 215 // Read data and digest it. |
| 216 base::MD5Update(&md5_context_, | 216 base::MD5Update(&md5_context_, |
| 217 base::StringPiece(buffer_->data(), bytes_read)); | 217 base::StringPiece(buffer_->data(), bytes_read)); |
| 218 | 218 |
| 219 // Kick off the next read. | 219 // Kick off the next read. |
| 220 ReadNextChunk(callback); | 220 ReadNextChunk(callback); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 240 const std::string extension = base::FilePath(path.Extension()).AsUTF8Unsafe(); | 240 const std::string extension = base::FilePath(path.Extension()).AsUTF8Unsafe(); |
| 241 for (size_t i = 0; i < arraysize(kHostedDocumentKinds); ++i) { | 241 for (size_t i = 0; i < arraysize(kHostedDocumentKinds); ++i) { |
| 242 if (extension == kHostedDocumentKinds[i].extension) | 242 if (extension == kHostedDocumentKinds[i].extension) |
| 243 return true; | 243 return true; |
| 244 } | 244 } |
| 245 return extension == kUnknownHostedDocumentExtension; | 245 return extension == kUnknownHostedDocumentExtension; |
| 246 } | 246 } |
| 247 | 247 |
| 248 } // namespace util | 248 } // namespace util |
| 249 } // namespace drive | 249 } // namespace drive |
| OLD | NEW |