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..d5b77ef8cfff2a9a6979fa0e646b0a5e767cb79f 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,54 @@ bool IsGDataAvailable(Profile* profile) { |
| return true; |
| } |
| +void ParseCacheFilePath(const FilePath& path, |
| + std::string* resource_id, |
| + std::string* md5, |
| + std::string* extra_extension) { |
| + DCHECK(resource_id); |
| + DCHECK(md5); |
| + DCHECK(extra_extension); |
| + |
| + // 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_extension. |
| + switch (extensions.size()) { |
|
tbarzic
2012/04/23 18:03:22
What do you think about this:
size_t extension_cou
hshi
2012/04/23 20:45:47
Done.
|
| + case 0: |
| + // Only resource_id is present: "<resource_id>". |
| + *md5 = std::string(); |
| + *extra_extension = std::string(); |
| + break; |
| + case 1: |
| + // Both resource_id and md5 are present: "<resource_id>.<md5>". |
| + *md5 = extensions[0]; |
| + *extra_extension = std::string(); |
| + break; |
| + case 2: |
| + // All three parts are present: ""<resource_id>.<md5>.<extra_extension>". |
| + *md5 = extensions[1]; |
| + *extra_extension = extensions[0]; |
| + break; |
| + default: |
| + NOTREACHED(); |
| + } |
| +} |
| + |
| } // namespace util |
| } // namespace gdata |