Chromium Code Reviews| 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 813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 824 } | 824 } |
| 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 |
|
kinaba
2012/08/13 05:06:30
I think we can wrap whole these checks with:
if (f
Zachary Kuznia
2012/08/13 05:12:26
Done.
| |
| 835 int64 file_size; | |
| 836 if (!file_util::GetFileSize(source_path, &file_size)) { | |
| 837 LOG(WARNING) << "Couldn't get file size for: " << source_path.value(); | |
| 838 *error = GDATA_FILE_ERROR_FAILED; | |
| 839 return; | |
| 840 } | |
| 841 | |
| 842 bool enough_space = false; | |
| 843 FreeDiskSpaceIfNeededFor(file_size, &enough_space); | |
| 844 if (!enough_space) { | |
| 845 *error = GDATA_FILE_ERROR_NO_SPACE; | |
| 846 return; | |
| 847 } | |
| 848 | |
| 835 FilePath dest_path; | 849 FilePath dest_path; |
| 836 FilePath symlink_path; | 850 FilePath symlink_path; |
| 837 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_TMP; | 851 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_TMP; |
| 838 | 852 |
| 839 // If file was previously pinned, store it in persistent dir and create | 853 // If file was previously pinned, store it in persistent dir and create |
| 840 // symlink in pinned dir. | 854 // symlink in pinned dir. |
| 841 GDataCacheEntry cache_entry; | 855 GDataCacheEntry cache_entry; |
| 842 if (GetCacheEntry(resource_id, md5, &cache_entry)) { // File exists in cache. | 856 if (GetCacheEntry(resource_id, md5, &cache_entry)) { // File exists in cache. |
| 843 // If file is dirty or mounted, return error. | 857 // If file is dirty or mounted, return error. |
| 844 if (cache_entry.is_dirty() || cache_entry.is_mounted()) { | 858 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) { | 1593 const GDataCacheEntry& cache_entry) { |
| 1580 return cache_entry.is_persistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; | 1594 return cache_entry.is_persistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; |
| 1581 } | 1595 } |
| 1582 | 1596 |
| 1583 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { | 1597 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { |
| 1584 delete global_free_disk_getter_for_testing; // Safe to delete NULL; | 1598 delete global_free_disk_getter_for_testing; // Safe to delete NULL; |
| 1585 global_free_disk_getter_for_testing = getter; | 1599 global_free_disk_getter_for_testing = getter; |
| 1586 } | 1600 } |
| 1587 | 1601 |
| 1588 } // namespace gdata | 1602 } // namespace gdata |
| OLD | NEW |