Chromium Code Reviews| Index: chrome/browser/chromeos/gdata/gdata_util.cc |
| diff --git a/chrome/browser/chromeos/gdata/gdata_util.cc b/chrome/browser/chromeos/gdata/gdata_util.cc |
| index b69f120bfec7f6e622376223e957d1ceb4811cce..4dcf18bf6f7b0e0739976ad87aae8849979b4ac9 100644 |
| --- a/chrome/browser/chromeos/gdata/gdata_util.cc |
| +++ b/chrome/browser/chromeos/gdata/gdata_util.cc |
| @@ -21,6 +21,7 @@ |
| #include "chrome/common/chrome_version_info.h" |
| #include "chrome/common/pref_names.h" |
| #include "chrome/common/url_constants.h" |
| +#include "chrome/browser/chromeos/gdata/gdata.pb.h" |
| #include "chrome/browser/chromeos/gdata/gdata_file_system.h" |
| #include "chrome/browser/chromeos/gdata/gdata_system_service.h" |
| #include "chrome/browser/chromeos/login/user.h" |
| @@ -93,6 +94,65 @@ void OpenEditURLUIThread(Profile* profile, GURL* edit_url) { |
| } |
| } |
| +// Invoked upon completion of GetFileInfoByPathAsync initiated by |
| +// InsertGDataCachePathPermissions. |
| +void OnGetFileInfoForInsertGDataCachePathsPermissions( |
| + Profile* profile, |
| + std::vector<std::pair<FilePath, int> >* cache_paths, |
| + const base::Closure& callback, |
| + base::PlatformFileError error, |
| + scoped_ptr<GDataFileProto> file_info) { |
| + DCHECK(profile); |
| + DCHECK(cache_paths); |
| + |
| + GDataFileSystem* file_system = GetGDataFileSystem(profile); |
| + if (!file_system) { |
| + if (!callback.is_null()) |
| + callback.Run(); |
| + return; |
| + } |
| + |
| + std::string resource_id; |
| + std::string file_md5; |
| + |
| + // TODO(hshi): GetFileInfoByPathAsync may fail when the gdata file is not |
| + // present in cache. For now just grant permission to the entire cache subdir. |
| + if (error == base::PLATFORM_FILE_OK && file_info.get()) { |
| + resource_id = file_info->gdata_entry().resource_id(); |
| + file_md5 = file_info->file_md5(); |
| + } |
| + |
| + // We check permissions for raw cache file paths only for read-only |
| + // operations (when fileEntry.file() is called), so read only permissions |
| + // should be sufficient for all cache paths. For the rest of supported |
| + // operations the file access check is done for drive/ paths. |
| + cache_paths->push_back(std::make_pair( |
| + file_system->GetCacheFilePath(resource_id, file_md5, |
| + GDataCache::CACHE_TYPE_PERSISTENT, |
| + GDataFileSystem::CACHED_FILE_FROM_SERVER), |
| + kReadOnlyFilePermissions)); |
| + // TODO(tbarzic): When we start supporting openFile operation, we may have to |
| + // change permission for localy modified files to match handler's permissions. |
| + cache_paths->push_back(std::make_pair( |
| + file_system->GetCacheFilePath(resource_id, file_md5, |
| + GDataCache::CACHE_TYPE_PERSISTENT, |
| + GDataFileSystem::CACHED_FILE_LOCALLY_MODIFIED), |
| + kReadOnlyFilePermissions)); |
| + cache_paths->push_back(std::make_pair( |
| + file_system->GetCacheFilePath(resource_id, file_md5, |
| + GDataCache::CACHE_TYPE_PERSISTENT, |
| + GDataFileSystem::CACHED_FILE_MOUNTED), |
| + kReadOnlyFilePermissions)); |
| + cache_paths->push_back(std::make_pair( |
| + file_system->GetCacheFilePath(resource_id, file_md5, |
| + GDataCache::CACHE_TYPE_TMP, |
| + GDataFileSystem::CACHED_FILE_FROM_SERVER), |
| + kReadOnlyFilePermissions)); |
| + |
| + if (!callback.is_null()) |
| + callback.Run(); |
| +} |
| + |
| } // namespace |
| const FilePath& GetGDataMountPointPath() { |
| @@ -231,46 +291,40 @@ FilePath ExtractGDataPath(const FilePath& path) { |
| void InsertGDataCachePathsPermissions( |
| Profile* profile, |
| - const FilePath& gdata_path, |
| - std::vector<std::pair<FilePath, int> >* cache_paths ) { |
| + scoped_ptr<std::vector<FilePath> > gdata_paths, |
| + std::vector<std::pair<FilePath, int> >* cache_paths, |
| + const base::Closure& callback) { |
| + DCHECK(profile); |
| + DCHECK(gdata_paths.get()); |
| DCHECK(cache_paths); |
| GDataFileSystem* file_system = GetGDataFileSystem(profile); |
| - if (!file_system) |
| + if (!file_system || gdata_paths->empty()) { |
| + if (!callback.is_null()) |
|
tbarzic
2012/06/08 17:59:13
I don't think this method makes much sense without
hshi1
2012/06/08 18:21:41
Done.
|
| + callback.Run(); |
| return; |
| + } |
| - GDataFileProperties file_properties; |
| - file_system->GetFileInfoByPath(gdata_path, &file_properties); |
| - |
| - std::string resource_id = file_properties.resource_id; |
| - std::string file_md5 = file_properties.file_md5; |
| - |
| - // We check permissions for raw cache file paths only for read-only |
| - // operations (when fileEntry.file() is called), so read only permissions |
| - // should be sufficient for all cache paths. For the rest of supported |
| - // operations the file access check is done for drive/ paths. |
| - cache_paths->push_back(std::make_pair( |
| - file_system->GetCacheFilePath(resource_id, file_md5, |
| - GDataCache::CACHE_TYPE_PERSISTENT, |
| - GDataFileSystem::CACHED_FILE_FROM_SERVER), |
| - kReadOnlyFilePermissions)); |
| - // TODO(tbarzic): When we start supporting openFile operation, we may have to |
| - // change permission for localy modified files to match handler's permissions. |
| - cache_paths->push_back(std::make_pair( |
| - file_system->GetCacheFilePath(resource_id, file_md5, |
| - GDataCache::CACHE_TYPE_PERSISTENT, |
| - GDataFileSystem::CACHED_FILE_LOCALLY_MODIFIED), |
| - kReadOnlyFilePermissions)); |
| - cache_paths->push_back(std::make_pair( |
| - file_system->GetCacheFilePath(resource_id, file_md5, |
| - GDataCache::CACHE_TYPE_PERSISTENT, |
| - GDataFileSystem::CACHED_FILE_MOUNTED), |
| - kReadOnlyFilePermissions)); |
| - cache_paths->push_back(std::make_pair( |
| - file_system->GetCacheFilePath(resource_id, file_md5, |
| - GDataCache::CACHE_TYPE_TMP, |
| - GDataFileSystem::CACHED_FILE_FROM_SERVER), |
| - kReadOnlyFilePermissions)); |
| + // Remove one file path entry from the back of the input vector |gdata_paths|. |
| + FilePath gdata_path = gdata_paths->back(); |
| + gdata_paths->pop_back(); |
| + |
| + // Call GetFileInfoByPathAsync() to get file info for |gdata_path| then insert |
| + // all possible cache paths to the output vector |cache_paths|. |
| + // Note that we can only process one file path at a time. Upon completion |
| + // of OnGetFileInfoForInsertGDataCachePathsPermissions(), we recursively call |
| + // InsertGDataCachePathsPermissions() to process the next file path from the |
| + // back of the input vector |gdata_paths| until it is empty. |
| + file_system->GetFileInfoByPathAsync( |
| + gdata_path, |
| + base::Bind(&OnGetFileInfoForInsertGDataCachePathsPermissions, |
| + profile, |
| + cache_paths, |
| + base::Bind(&InsertGDataCachePathsPermissions, |
| + profile, |
| + base::Passed(&gdata_paths), |
| + cache_paths, |
| + callback))); |
| } |
| bool IsGDataAvailable(Profile* profile) { |