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 | |
851 FilePath dest_path; | 835 FilePath dest_path; |
852 FilePath symlink_path; | 836 FilePath symlink_path; |
853 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_TMP; | 837 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_TMP; |
854 | 838 |
855 // If file was previously pinned, store it in persistent dir and create | 839 // If file was previously pinned, store it in persistent dir and create |
856 // symlink in pinned dir. | 840 // symlink in pinned dir. |
857 GDataCacheEntry cache_entry; | 841 GDataCacheEntry cache_entry; |
858 if (GetCacheEntry(resource_id, md5, &cache_entry)) { // File exists in cache. | 842 if (GetCacheEntry(resource_id, md5, &cache_entry)) { // File exists in cache. |
859 // If file is dirty or mounted, return error. | 843 // If file is dirty or mounted, return error. |
860 if (cache_entry.is_dirty() || cache_entry.is_mounted()) { | 844 if (cache_entry.is_dirty() || cache_entry.is_mounted()) { |
(...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1595 const GDataCacheEntry& cache_entry) { | 1579 const GDataCacheEntry& cache_entry) { |
1596 return cache_entry.is_persistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; | 1580 return cache_entry.is_persistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; |
1597 } | 1581 } |
1598 | 1582 |
1599 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { | 1583 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { |
1600 delete global_free_disk_getter_for_testing; // Safe to delete NULL; | 1584 delete global_free_disk_getter_for_testing; // Safe to delete NULL; |
1601 global_free_disk_getter_for_testing = getter; | 1585 global_free_disk_getter_for_testing = getter; |
1602 } | 1586 } |
1603 | 1587 |
1604 } // namespace gdata | 1588 } // namespace gdata |
OLD | NEW |