Chromium Code Reviews| 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_util.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 kReadOnlyFilePermissions)); | 214 kReadOnlyFilePermissions)); |
| 215 // TODO(tbarzic): When we start supporting openFile operation, we may have to | 215 // TODO(tbarzic): When we start supporting openFile operation, we may have to |
| 216 // change permission for localy modified files to match handler's permissions. | 216 // change permission for localy modified files to match handler's permissions. |
| 217 cache_paths->push_back(std::make_pair( | 217 cache_paths->push_back(std::make_pair( |
| 218 file_system->GetCacheFilePath(resource_id, file_md5, | 218 file_system->GetCacheFilePath(resource_id, file_md5, |
| 219 GDataRootDirectory::CACHE_TYPE_PERSISTENT, | 219 GDataRootDirectory::CACHE_TYPE_PERSISTENT, |
| 220 GDataFileSystem::CACHED_FILE_LOCALLY_MODIFIED), | 220 GDataFileSystem::CACHED_FILE_LOCALLY_MODIFIED), |
| 221 kReadOnlyFilePermissions)); | 221 kReadOnlyFilePermissions)); |
| 222 cache_paths->push_back(std::make_pair( | 222 cache_paths->push_back(std::make_pair( |
| 223 file_system->GetCacheFilePath(resource_id, file_md5, | 223 file_system->GetCacheFilePath(resource_id, file_md5, |
| 224 GDataRootDirectory::CACHE_TYPE_PERSISTENT, | |
| 225 GDataFileSystem::CACHED_FILE_MOUNTED), | |
| 226 kReadOnlyFilePermissions)); | |
| 227 cache_paths->push_back(std::make_pair( | |
| 228 file_system->GetCacheFilePath(resource_id, file_md5, | |
| 224 GDataRootDirectory::CACHE_TYPE_TMP, | 229 GDataRootDirectory::CACHE_TYPE_TMP, |
| 225 GDataFileSystem::CACHED_FILE_FROM_SERVER), | 230 GDataFileSystem::CACHED_FILE_FROM_SERVER), |
| 226 kReadOnlyFilePermissions)); | 231 kReadOnlyFilePermissions)); |
| 227 | 232 |
| 228 } | 233 } |
| 229 | 234 |
| 230 void SetPermissionsForGDataCacheFiles(Profile* profile, | 235 void SetPermissionsForGDataCacheFiles(Profile* profile, |
| 231 int pid, | 236 int pid, |
| 232 const FilePath& path) { | 237 const FilePath& path) { |
| 233 std::vector<std::pair<FilePath, int> > cache_paths; | 238 std::vector<std::pair<FilePath, int> > cache_paths; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 252 | 257 |
| 253 // Disable gdata if preference is set. This can happen with commandline flag | 258 // Disable gdata if preference is set. This can happen with commandline flag |
| 254 // --disable-gdata or enterprise policy, or probably with user settings too | 259 // --disable-gdata or enterprise policy, or probably with user settings too |
| 255 // in the future. | 260 // in the future. |
| 256 if (profile->GetPrefs()->GetBoolean(prefs::kDisableGData)) | 261 if (profile->GetPrefs()->GetBoolean(prefs::kDisableGData)) |
| 257 return false; | 262 return false; |
| 258 | 263 |
| 259 return true; | 264 return true; |
| 260 } | 265 } |
| 261 | 266 |
| 267 // Extracts resource_id, md5, and extra_suffix from cache path. | |
| 268 // Pinned and outgoing symlinks have no md5 extension. | |
| 269 // The extra_suffix is only non-empty for mounted archives. | |
|
satorux1
2012/04/20 21:46:10
We usually don't have a function comment in .cc fi
| |
| 270 void ParseCacheFilePath(const FilePath& path, | |
| 271 std::string* resource_id, | |
| 272 std::string* md5, | |
| 273 std::string* extra_suffix) | |
| 274 { | |
|
satorux1
2012/04/20 21:46:10
move { to the previous line.
| |
| 275 DCHECK(resource_id); | |
| 276 DCHECK(md5); | |
| 277 DCHECK(extra_suffix); | |
| 278 | |
| 279 // Extract up to two extensions from the right. | |
| 280 FilePath base_name = path.BaseName(); | |
| 281 int num_extensions; | |
|
satorux1
2012/04/20 21:46:10
please initialize this with 0, to be extra defensi
| |
| 282 FilePath::StringType extension[2]; | |
|
satorux1
2012/04/20 21:46:10
extension -> extensions
| |
| 283 for (num_extensions = 0; num_extensions < 2; ++num_extensions) { | |
|
satorux1
2012/04/20 21:46:10
rather than 2, please do arraysize(extensions)
| |
| 284 extension[num_extensions] = base_name.Extension(); | |
| 285 if (!extension[num_extensions].empty()) { | |
| 286 // FilePath::Extension returns ".", so strip it. | |
| 287 extension[num_extensions] = | |
|
satorux1
2012/04/20 21:46:10
instead of using a fixed array, using vector<> and
| |
| 288 GDataEntry::UnescapeUtf8FileName(extension[num_extensions].substr(1)); | |
| 289 base_name = base_name.RemoveExtension(); | |
| 290 } else { | |
| 291 break; | |
| 292 } | |
| 293 } | |
| 294 | |
| 295 *resource_id = GDataEntry::UnescapeUtf8FileName( | |
| 296 base_name.RemoveExtension().value()); | |
| 297 if (num_extensions == 2) { | |
| 298 // The extra_suffix is non-empty: "<resource_id>.<md5>.<extra_suffix>". | |
| 299 *extra_suffix = extension[0]; | |
| 300 *md5 = extension[1]; | |
| 301 } else { | |
| 302 // The extra_suffix is not present: "<resource_id>.<md5>". | |
| 303 *extra_suffix = std::string(); | |
| 304 *md5 = extension[0]; | |
| 305 } | |
| 306 } | |
| 307 | |
| 262 } // namespace util | 308 } // namespace util |
| 263 } // namespace gdata | 309 } // namespace gdata |
| OLD | NEW |