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_system.h" | 5 #include "chrome/browser/chromeos/drive/file_system.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/platform_file.h" | 9 #include "base/platform_file.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 return error; | 57 return error; |
58 | 58 |
59 // For entries that will never be cached, use the original resource entry | 59 // For entries that will never be cached, use the original resource entry |
60 // as is. | 60 // as is. |
61 if (!entry->has_file_specific_info() || | 61 if (!entry->has_file_specific_info() || |
62 entry->file_specific_info().is_hosted_document()) | 62 entry->file_specific_info().is_hosted_document()) |
63 return FILE_ERROR_OK; | 63 return FILE_ERROR_OK; |
64 | 64 |
65 // When cache is not found, use the original resource entry as is. | 65 // When cache is not found, use the original resource entry as is. |
66 FileCacheEntry cache_entry; | 66 FileCacheEntry cache_entry; |
67 if (!cache->GetCacheEntry(local_id, &cache_entry)) | 67 error = cache->GetCacheEntry(local_id, &cache_entry); |
| 68 if (error == FILE_ERROR_NOT_FOUND) |
68 return FILE_ERROR_OK; | 69 return FILE_ERROR_OK; |
| 70 if (error != FILE_ERROR_OK) |
| 71 return error; |
69 | 72 |
70 // When cache is non-dirty and obsolete (old hash), use the original entry. | 73 // When cache is non-dirty and obsolete (old hash), use the original entry. |
71 if (!cache_entry.is_dirty() && | 74 if (!cache_entry.is_dirty() && |
72 entry->file_specific_info().md5() != cache_entry.md5()) | 75 entry->file_specific_info().md5() != cache_entry.md5()) |
73 return FILE_ERROR_OK; | 76 return FILE_ERROR_OK; |
74 | 77 |
75 // If there's a valid cache, obtain the file info from the cache file itself. | 78 // If there's a valid cache, obtain the file info from the cache file itself. |
76 base::FilePath local_cache_path; | 79 base::FilePath local_cache_path; |
77 error = cache->GetFile(local_id, &local_cache_path); | 80 error = cache->GetFile(local_id, &local_cache_path); |
78 if (error != FILE_ERROR_OK) | 81 if (error != FILE_ERROR_OK) |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 | 151 |
149 // Runs the callback with arguments. | 152 // Runs the callback with arguments. |
150 void RunMarkMountedCallback(const MarkMountedCallback& callback, | 153 void RunMarkMountedCallback(const MarkMountedCallback& callback, |
151 base::FilePath* cache_file_path, | 154 base::FilePath* cache_file_path, |
152 FileError error) { | 155 FileError error) { |
153 DCHECK(!callback.is_null()); | 156 DCHECK(!callback.is_null()); |
154 callback.Run(error, *cache_file_path); | 157 callback.Run(error, *cache_file_path); |
155 } | 158 } |
156 | 159 |
157 // Used to implement GetCacheEntry. | 160 // Used to implement GetCacheEntry. |
158 bool GetCacheEntryInternal(internal::ResourceMetadata* resource_metadata, | 161 FileError GetCacheEntryInternal(internal::ResourceMetadata* resource_metadata, |
159 internal::FileCache* cache, | 162 internal::FileCache* cache, |
160 const base::FilePath& drive_file_path, | 163 const base::FilePath& drive_file_path, |
161 FileCacheEntry* cache_entry) { | 164 FileCacheEntry* cache_entry) { |
162 std::string id; | 165 std::string id; |
163 if (resource_metadata->GetIdByPath(drive_file_path, &id) != FILE_ERROR_OK) | 166 FileError error = resource_metadata->GetIdByPath(drive_file_path, &id); |
164 return false; | 167 if (error != FILE_ERROR_OK) |
| 168 return error; |
165 | 169 |
166 return cache->GetCacheEntry(id, cache_entry); | 170 return cache->GetCacheEntry(id, cache_entry); |
167 } | 171 } |
168 | 172 |
169 // Runs the callback with arguments. | 173 // Runs the callback with arguments. |
170 void RunGetCacheEntryCallback(const GetCacheEntryCallback& callback, | 174 void RunGetCacheEntryCallback(const GetCacheEntryCallback& callback, |
171 const FileCacheEntry* cache_entry, | 175 const FileCacheEntry* cache_entry, |
172 bool success) { | 176 FileError error) { |
173 DCHECK(!callback.is_null()); | 177 DCHECK(!callback.is_null()); |
174 callback.Run(success, *cache_entry); | 178 callback.Run(error, *cache_entry); |
175 } | 179 } |
176 | 180 |
177 // Callback for ResourceMetadata::GetLargestChangestamp. | 181 // Callback for ResourceMetadata::GetLargestChangestamp. |
178 // |callback| must not be null. | 182 // |callback| must not be null. |
179 void OnGetLargestChangestamp( | 183 void OnGetLargestChangestamp( |
180 FileSystemMetadata metadata, // Will be modified. | 184 FileSystemMetadata metadata, // Will be modified. |
181 const GetFilesystemMetadataCallback& callback, | 185 const GetFilesystemMetadataCallback& callback, |
182 int64 largest_changestamp) { | 186 int64 largest_changestamp) { |
183 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 187 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
184 DCHECK(!callback.is_null()); | 188 DCHECK(!callback.is_null()); |
(...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1009 FROM_HERE, | 1013 FROM_HERE, |
1010 base::Bind(&GetPathFromResourceIdOnBlockingPool, | 1014 base::Bind(&GetPathFromResourceIdOnBlockingPool, |
1011 resource_metadata_, | 1015 resource_metadata_, |
1012 resource_id, | 1016 resource_id, |
1013 file_path), | 1017 file_path), |
1014 base::Bind(&GetPathFromResourceIdAfterGetPath, | 1018 base::Bind(&GetPathFromResourceIdAfterGetPath, |
1015 base::Owned(file_path), | 1019 base::Owned(file_path), |
1016 callback)); | 1020 callback)); |
1017 } | 1021 } |
1018 } // namespace drive | 1022 } // namespace drive |
OLD | NEW |