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/gdata/gdata_cache.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_cache.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/chromeos/chromeos_version.h" | 9 #include "base/chromeos/chromeos_version.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
825 } | 825 } |
826 | 826 |
827 void GDataCache::Store(const std::string& resource_id, | 827 void GDataCache::Store(const std::string& resource_id, |
828 const std::string& md5, | 828 const std::string& md5, |
829 const FilePath& source_path, | 829 const FilePath& source_path, |
830 FileOperationType file_operation_type, | 830 FileOperationType file_operation_type, |
831 GDataFileError* error) { | 831 GDataFileError* error) { |
832 AssertOnSequencedWorkerPool(); | 832 AssertOnSequencedWorkerPool(); |
833 DCHECK(error); | 833 DCHECK(error); |
834 | 834 |
| 835 if (file_operation_type == FILE_OPERATION_COPY) { |
| 836 int64 file_size; |
| 837 if (!file_util::GetFileSize(source_path, &file_size)) { |
| 838 LOG(WARNING) << "Couldn't get file size for: " << source_path.value(); |
| 839 *error = GDATA_FILE_ERROR_FAILED; |
| 840 return; |
| 841 } |
| 842 |
| 843 bool enough_space = false; |
| 844 FreeDiskSpaceIfNeededFor(file_size, &enough_space); |
| 845 if (!enough_space) { |
| 846 *error = GDATA_FILE_ERROR_NO_SPACE; |
| 847 return; |
| 848 } |
| 849 } |
| 850 |
835 FilePath dest_path; | 851 FilePath dest_path; |
836 FilePath symlink_path; | 852 FilePath symlink_path; |
837 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_TMP; | 853 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_TMP; |
838 | 854 |
839 // If file was previously pinned, store it in persistent dir and create | 855 // If file was previously pinned, store it in persistent dir and create |
840 // symlink in pinned dir. | 856 // symlink in pinned dir. |
841 GDataCacheEntry cache_entry; | 857 GDataCacheEntry cache_entry; |
842 if (GetCacheEntry(resource_id, md5, &cache_entry)) { // File exists in cache. | 858 if (GetCacheEntry(resource_id, md5, &cache_entry)) { // File exists in cache. |
843 // If file is dirty or mounted, return error. | 859 // If file is dirty or mounted, return error. |
844 if (cache_entry.is_dirty() || cache_entry.is_mounted()) { | 860 if (cache_entry.is_dirty() || cache_entry.is_mounted()) { |
(...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1579 const GDataCacheEntry& cache_entry) { | 1595 const GDataCacheEntry& cache_entry) { |
1580 return cache_entry.is_persistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; | 1596 return cache_entry.is_persistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; |
1581 } | 1597 } |
1582 | 1598 |
1583 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { | 1599 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { |
1584 delete global_free_disk_getter_for_testing; // Safe to delete NULL; | 1600 delete global_free_disk_getter_for_testing; // Safe to delete NULL; |
1585 global_free_disk_getter_for_testing = getter; | 1601 global_free_disk_getter_for_testing = getter; |
1586 } | 1602 } |
1587 | 1603 |
1588 } // namespace gdata | 1604 } // namespace gdata |
OLD | NEW |