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_file_system.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_file_system.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <sys/stat.h> | 8 #include <sys/stat.h> |
9 | 9 |
10 #include <set> | 10 #include <set> |
(...skipping 2038 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2049 | 2049 |
2050 GDataEntry* GDataFileSystem::GetGDataEntryByPath( | 2050 GDataEntry* GDataFileSystem::GetGDataEntryByPath( |
2051 const FilePath& file_path) { | 2051 const FilePath& file_path) { |
2052 lock_.AssertAcquired(); | 2052 lock_.AssertAcquired(); |
2053 // Find directory element within the cached file system snapshot. | 2053 // Find directory element within the cached file system snapshot. |
2054 ReadOnlyFindEntryDelegate find_delegate; | 2054 ReadOnlyFindEntryDelegate find_delegate; |
2055 UnsafeFindEntryByPath(file_path, &find_delegate); | 2055 UnsafeFindEntryByPath(file_path, &find_delegate); |
2056 return find_delegate.entry(); | 2056 return find_delegate.entry(); |
2057 } | 2057 } |
2058 | 2058 |
2059 void GDataFileSystem::GetFileFromCacheByPath( | |
2060 const FilePath& gdata_file_path, | |
2061 const GetFileFromCacheCallback& callback) { | |
2062 std::string resource_id; | |
2063 std::string md5; | |
2064 | |
2065 { // Lock to use GetGDataEntryByPath and returned pointer, but need to | |
2066 // release before GetFileFromCacheByResourceIdAndMd5. | |
2067 base::AutoLock lock(lock_); | |
2068 GDataEntry* entry = GetGDataEntryByPath(gdata_file_path); | |
2069 | |
2070 if (entry && entry->AsGDataFile()) { | |
2071 GDataFile* file = entry->AsGDataFile(); | |
2072 resource_id = file->resource_id(); | |
2073 md5 = file->file_md5(); | |
2074 } else { | |
2075 // Invoke |callback| with error. | |
2076 if (!callback.is_null()) { | |
2077 base::MessageLoopProxy::current()->PostTask( | |
2078 FROM_HERE, | |
2079 base::Bind(callback, | |
2080 base::PLATFORM_FILE_ERROR_NOT_FOUND, | |
2081 std::string(), | |
2082 std::string(), | |
2083 gdata_file_path, | |
2084 FilePath())); | |
2085 } | |
2086 return; | |
2087 } | |
2088 } | |
2089 | |
2090 GetFileFromCacheByResourceIdAndMd5Internal( | |
2091 resource_id, md5, gdata_file_path, callback); | |
2092 } | |
2093 | |
2094 void GDataFileSystem::GetCacheState(const std::string& resource_id, | 2059 void GDataFileSystem::GetCacheState(const std::string& resource_id, |
2095 const std::string& md5, | 2060 const std::string& md5, |
2096 const GetCacheStateCallback& callback) { | 2061 const GetCacheStateCallback& callback) { |
2097 // This method originates from GDataFile::GetCacheState, which already locks, | 2062 // This method originates from GDataFile::GetCacheState, which already locks, |
2098 // so we shouldn't lock here. | 2063 // so we shouldn't lock here. |
2099 UnsafeInitializeCacheIfNecessary(); | 2064 UnsafeInitializeCacheIfNecessary(); |
2100 | 2065 |
2101 base::PlatformFileError* error = | 2066 base::PlatformFileError* error = |
2102 new base::PlatformFileError(base::PLATFORM_FILE_OK); | 2067 new base::PlatformFileError(base::PLATFORM_FILE_OK); |
2103 int* cache_state = new int(GDataFile::CACHE_STATE_NONE); | 2068 int* cache_state = new int(GDataFile::CACHE_STATE_NONE); |
(...skipping 2252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4356 pref_registrar_->Init(profile_->GetPrefs()); | 4321 pref_registrar_->Init(profile_->GetPrefs()); |
4357 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); | 4322 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); |
4358 } | 4323 } |
4359 | 4324 |
4360 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { | 4325 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { |
4361 delete global_free_disk_getter_for_testing; // Safe to delete NULL; | 4326 delete global_free_disk_getter_for_testing; // Safe to delete NULL; |
4362 global_free_disk_getter_for_testing = getter; | 4327 global_free_disk_getter_for_testing = getter; |
4363 } | 4328 } |
4364 | 4329 |
4365 } // namespace gdata | 4330 } // namespace gdata |
OLD | NEW |