| 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/chromeos/drive/file_cache.h" | 5 #include "chrome/browser/chromeos/drive/file_cache.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/files/file_enumerator.h" | 10 #include "base/files/file_enumerator.h" |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 if (!it->second.is_dirty && | 422 if (!it->second.is_dirty && |
| 423 it->second.md5 == util::GetMd5Digest(current)) { | 423 it->second.md5 == util::GetMd5Digest(current)) { |
| 424 base::DeleteFile(current, false /* recursive */); | 424 base::DeleteFile(current, false /* recursive */); |
| 425 continue; | 425 continue; |
| 426 } | 426 } |
| 427 } | 427 } |
| 428 | 428 |
| 429 // Read file contents to sniff mime type. | 429 // Read file contents to sniff mime type. |
| 430 std::vector<char> content(net::kMaxBytesToSniff); | 430 std::vector<char> content(net::kMaxBytesToSniff); |
| 431 const int read_result = | 431 const int read_result = |
| 432 file_util::ReadFile(current, &content[0], content.size()); | 432 base::ReadFile(current, &content[0], content.size()); |
| 433 if (read_result < 0) { | 433 if (read_result < 0) { |
| 434 LOG(WARNING) << "Cannot read: " << current.value(); | 434 LOG(WARNING) << "Cannot read: " << current.value(); |
| 435 return false; | 435 return false; |
| 436 } | 436 } |
| 437 if (read_result == 0) // Skip empty files. | 437 if (read_result == 0) // Skip empty files. |
| 438 continue; | 438 continue; |
| 439 | 439 |
| 440 // Use recovered file name if available, otherwise decide file name with | 440 // Use recovered file name if available, otherwise decide file name with |
| 441 // sniffed mime type. | 441 // sniffed mime type. |
| 442 base::FilePath dest_base_name(FILE_PATH_LITERAL("file")); | 442 base::FilePath dest_base_name(FILE_PATH_LITERAL("file")); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 const std::string& id = GetIdFromPath(new_path); | 586 const std::string& id = GetIdFromPath(new_path); |
| 587 new_path = GetCacheFilePath(util::CanonicalizeResourceId(id)); | 587 new_path = GetCacheFilePath(util::CanonicalizeResourceId(id)); |
| 588 if (new_path != current && !base::Move(current, new_path)) | 588 if (new_path != current && !base::Move(current, new_path)) |
| 589 return false; | 589 return false; |
| 590 } | 590 } |
| 591 return true; | 591 return true; |
| 592 } | 592 } |
| 593 | 593 |
| 594 } // namespace internal | 594 } // namespace internal |
| 595 } // namespace drive | 595 } // namespace drive |
| OLD | NEW |