| 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/drive_cache.h" | 5 #include "chrome/browser/chromeos/drive/drive_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/logging.h" | 10 #include "base/logging.h" |
| (...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 return result.Pass(); | 574 return result.Pass(); |
| 575 } | 575 } |
| 576 | 576 |
| 577 DriveFileError DriveCache::StoreOnBlockingPool( | 577 DriveFileError DriveCache::StoreOnBlockingPool( |
| 578 const std::string& resource_id, | 578 const std::string& resource_id, |
| 579 const std::string& md5, | 579 const std::string& md5, |
| 580 const base::FilePath& source_path, | 580 const base::FilePath& source_path, |
| 581 FileOperationType file_operation_type) { | 581 FileOperationType file_operation_type) { |
| 582 AssertOnSequencedWorkerPool(); | 582 AssertOnSequencedWorkerPool(); |
| 583 | 583 |
| 584 int64 file_size = 0; |
| 584 if (file_operation_type == FILE_OPERATION_COPY) { | 585 if (file_operation_type == FILE_OPERATION_COPY) { |
| 585 int64 file_size; | |
| 586 if (!file_util::GetFileSize(source_path, &file_size)) { | 586 if (!file_util::GetFileSize(source_path, &file_size)) { |
| 587 LOG(WARNING) << "Couldn't get file size for: " << source_path.value(); | 587 LOG(WARNING) << "Couldn't get file size for: " << source_path.value(); |
| 588 return DRIVE_FILE_ERROR_FAILED; | 588 return DRIVE_FILE_ERROR_FAILED; |
| 589 } | 589 } |
| 590 | |
| 591 const bool enough_space = FreeDiskSpaceOnBlockingPoolIfNeededFor(file_size); | |
| 592 if (!enough_space) | |
| 593 return DRIVE_FILE_ERROR_NO_SPACE; | |
| 594 } | 590 } |
| 591 if (!FreeDiskSpaceOnBlockingPoolIfNeededFor(file_size)) |
| 592 return DRIVE_FILE_ERROR_NO_SPACE; |
| 595 | 593 |
| 596 base::FilePath symlink_path; | 594 base::FilePath symlink_path; |
| 597 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_TMP; | 595 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_TMP; |
| 598 | 596 |
| 599 // If file was previously pinned, store it in persistent dir. | 597 // If file was previously pinned, store it in persistent dir. |
| 600 DriveCacheEntry cache_entry; | 598 DriveCacheEntry cache_entry; |
| 601 if (GetCacheEntryOnBlockingPool(resource_id, md5, &cache_entry)) { | 599 if (GetCacheEntryOnBlockingPool(resource_id, md5, &cache_entry)) { |
| 602 // File exists in cache. | 600 // File exists in cache. |
| 603 // If file is dirty or mounted, return error. | 601 // If file is dirty or mounted, return error. |
| 604 if (cache_entry.is_dirty() || cache_entry.is_mounted()) { | 602 if (cache_entry.is_dirty() || cache_entry.is_mounted()) { |
| (...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1202 return success; | 1200 return success; |
| 1203 } | 1201 } |
| 1204 | 1202 |
| 1205 // static | 1203 // static |
| 1206 DriveCache::CacheSubDirectoryType DriveCache::GetSubDirectoryType( | 1204 DriveCache::CacheSubDirectoryType DriveCache::GetSubDirectoryType( |
| 1207 const DriveCacheEntry& cache_entry) { | 1205 const DriveCacheEntry& cache_entry) { |
| 1208 return cache_entry.is_persistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; | 1206 return cache_entry.is_persistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; |
| 1209 } | 1207 } |
| 1210 | 1208 |
| 1211 } // namespace drive | 1209 } // namespace drive |
| OLD | NEW |