Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(416)

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_util.cc

Issue 10116044: gdata: Support mounting archive files in GData cache. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: gdata: Support mounting archive files in GData cache. Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 void ParseCacheFilePath(const FilePath& path,
268 std::string* resource_id,
269 std::string* md5,
270 std::string* extra_extension) {
271 DCHECK(resource_id);
272 DCHECK(md5);
273 DCHECK(extra_extension);
274
275 // Extract up to two extensions from the right.
276 FilePath base_name = path.BaseName();
277 const int kNumExtensionsToExtract = 2;
278 std::vector<FilePath::StringType> extensions;
279 for (int i = 0; i < kNumExtensionsToExtract; ++i) {
280 FilePath::StringType extension = base_name.Extension();
281 if (!extension.empty()) {
282 // FilePath::Extension returns ".", so strip it.
283 extension = GDataEntry::UnescapeUtf8FileName(extension.substr(1));
284 base_name = base_name.RemoveExtension();
285 extensions.push_back(extension);
286 } else {
287 break;
288 }
289 }
290
291 // The base_name here is already stripped of extensions in the loop above.
292 *resource_id = GDataEntry::UnescapeUtf8FileName(base_name.value());
293
294 // Assign the extracted extensions to md5 and extra_extension.
295 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.
296 case 0:
297 // Only resource_id is present: "<resource_id>".
298 *md5 = std::string();
299 *extra_extension = std::string();
300 break;
301 case 1:
302 // Both resource_id and md5 are present: "<resource_id>.<md5>".
303 *md5 = extensions[0];
304 *extra_extension = std::string();
305 break;
306 case 2:
307 // All three parts are present: ""<resource_id>.<md5>.<extra_extension>".
308 *md5 = extensions[1];
309 *extra_extension = extensions[0];
310 break;
311 default:
312 NOTREACHED();
313 }
314 }
315
262 } // namespace util 316 } // namespace util
263 } // namespace gdata 317 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698