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 21b2129545f7d2c4d4b46cc9158281245b47ca04..5db79213f31a598eedb1cba8cffa714bfbbb786f 100644 |
| --- a/chrome/browser/chromeos/gdata/gdata_util.cc |
| +++ b/chrome/browser/chromeos/gdata/gdata_util.cc |
| @@ -221,6 +221,11 @@ void InsertGDataCachePathsPermissions( |
| kReadOnlyFilePermissions)); |
| cache_paths->push_back(std::make_pair( |
| file_system->GetCacheFilePath(resource_id, file_md5, |
| + GDataRootDirectory::CACHE_TYPE_PERSISTENT, |
| + GDataFileSystem::CACHED_FILE_MOUNTED), |
| + kReadOnlyFilePermissions)); |
| + cache_paths->push_back(std::make_pair( |
| + file_system->GetCacheFilePath(resource_id, file_md5, |
| GDataRootDirectory::CACHE_TYPE_TMP, |
| GDataFileSystem::CACHED_FILE_FROM_SERVER), |
| kReadOnlyFilePermissions)); |
| @@ -259,5 +264,55 @@ bool IsGDataAvailable(Profile* profile) { |
| return true; |
| } |
| +void ParseCacheFilePath(const FilePath& path, |
| + std::string* resource_id, |
| + std::string* md5, |
| + std::string* extra_suffix) { |
| + DCHECK(resource_id); |
| + DCHECK(md5); |
| + DCHECK(extra_suffix); |
| + |
| + // Extract up to two extensions from the right. |
| + FilePath base_name = path.BaseName(); |
| + const int kNumExtensionsToExtract = 2; |
| + std::vector<FilePath::StringType> extensions; |
| + for (int i = 0; i < kNumExtensionsToExtract; ++i) { |
| + FilePath::StringType extension = base_name.Extension(); |
| + if (!extension.empty()) { |
| + // FilePath::Extension returns ".", so strip it. |
| + extension = GDataEntry::UnescapeUtf8FileName(extension.substr(1)); |
| + base_name = base_name.RemoveExtension(); |
| + extensions.push_back(extension); |
| + } else { |
| + break; |
| + } |
| + } |
| + |
| + // The base_name here is already stripped of extensions in the loop above. |
| + *resource_id = GDataEntry::UnescapeUtf8FileName(base_name.value()); |
| + |
| + // Assign the extracted extensions to md5 and extra_suffix. |
| + DCHECK(extensions.size() >= 0 && |
| + extensions.size() <= (size_t)kNumExtensionsToExtract); |
| + switch (extensions.size()) |
| + { |
|
satorux1
2012/04/20 23:05:39
move { to the previous line.
|
| + case 0: |
| + // Only resource_id is present: "<resource_id>". |
| + *md5 = std::string(); |
| + *extra_suffix = std::string(); |
| + break; |
| + case 1: |
| + // Both resource_id and md5 are present: "<resource_id>.<md5>". |
| + *md5 = extensions[0]; |
| + *extra_suffix = std::string(); |
| + break; |
| + case 2: |
| + // All three parts are present: ""<resource_id>.<md5>.<extra_suffix>". |
| + *md5 = extensions[1]; |
| + *extra_suffix = extensions[0]; |
| + break; |
|
satorux1
2012/04/20 23:05:39
add
default:
NOTREACHED();
|
| + } |
| +} |
| + |
| } // namespace util |
| } // namespace gdata |