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

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
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
14 #include "base/file_path.h" 14 #include "base/file_path.h"
15 #include "base/file_util.h" 15 #include "base/file_util.h"
16 #include "base/json/json_reader.h" 16 #include "base/json/json_reader.h"
17 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/stringprintf.h" 18 #include "base/stringprintf.h"
19 #include "base/string_util.h"
19 #include "base/threading/sequenced_worker_pool.h" 20 #include "base/threading/sequenced_worker_pool.h"
20 #include "chrome/common/chrome_version_info.h" 21 #include "chrome/common/chrome_version_info.h"
21 #include "chrome/common/libxml_utils.h" 22 #include "chrome/common/libxml_utils.h"
22 #include "chrome/common/pref_names.h" 23 #include "chrome/common/pref_names.h"
23 #include "chrome/common/url_constants.h" 24 #include "chrome/common/url_constants.h"
24 #include "chrome/browser/chromeos/gdata/gdata_file_system.h" 25 #include "chrome/browser/chromeos/gdata/gdata_file_system.h"
25 #include "chrome/browser/chromeos/gdata/gdata_system_service.h" 26 #include "chrome/browser/chromeos/gdata/gdata_system_service.h"
26 #include "chrome/browser/prefs/pref_service.h" 27 #include "chrome/browser/prefs/pref_service.h"
27 #include "chrome/browser/profiles/profile.h" 28 #include "chrome/browser/profiles/profile.h"
28 #include "chrome/browser/ui/browser.h" 29 #include "chrome/browser/ui/browser.h"
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 kReadOnlyFilePermissions)); 215 kReadOnlyFilePermissions));
215 // TODO(tbarzic): When we start supporting openFile operation, we may have to 216 // TODO(tbarzic): When we start supporting openFile operation, we may have to
216 // change permission for localy modified files to match handler's permissions. 217 // change permission for localy modified files to match handler's permissions.
217 cache_paths->push_back(std::make_pair( 218 cache_paths->push_back(std::make_pair(
218 file_system->GetCacheFilePath(resource_id, file_md5, 219 file_system->GetCacheFilePath(resource_id, file_md5,
219 GDataRootDirectory::CACHE_TYPE_PERSISTENT, 220 GDataRootDirectory::CACHE_TYPE_PERSISTENT,
220 GDataFileSystem::CACHED_FILE_LOCALLY_MODIFIED), 221 GDataFileSystem::CACHED_FILE_LOCALLY_MODIFIED),
221 kReadOnlyFilePermissions)); 222 kReadOnlyFilePermissions));
222 cache_paths->push_back(std::make_pair( 223 cache_paths->push_back(std::make_pair(
223 file_system->GetCacheFilePath(resource_id, file_md5, 224 file_system->GetCacheFilePath(resource_id, file_md5,
225 GDataRootDirectory::CACHE_TYPE_PERSISTENT,
226 GDataFileSystem::CACHED_FILE_MOUNTED),
227 kReadOnlyFilePermissions));
228 cache_paths->push_back(std::make_pair(
229 file_system->GetCacheFilePath(resource_id, file_md5,
224 GDataRootDirectory::CACHE_TYPE_TMP, 230 GDataRootDirectory::CACHE_TYPE_TMP,
225 GDataFileSystem::CACHED_FILE_FROM_SERVER), 231 GDataFileSystem::CACHED_FILE_FROM_SERVER),
226 kReadOnlyFilePermissions)); 232 kReadOnlyFilePermissions));
227 233
228 } 234 }
229 235
230 void SetPermissionsForGDataCacheFiles(Profile* profile, 236 void SetPermissionsForGDataCacheFiles(Profile* profile,
231 int pid, 237 int pid,
232 const FilePath& path) { 238 const FilePath& path) {
233 std::vector<std::pair<FilePath, int> > cache_paths; 239 std::vector<std::pair<FilePath, int> > cache_paths;
(...skipping 18 matching lines...) Expand all
252 258
253 // Disable gdata if preference is set. This can happen with commandline flag 259 // Disable gdata if preference is set. This can happen with commandline flag
254 // --disable-gdata or enterprise policy, or probably with user settings too 260 // --disable-gdata or enterprise policy, or probably with user settings too
255 // in the future. 261 // in the future.
256 if (profile->GetPrefs()->GetBoolean(prefs::kDisableGData)) 262 if (profile->GetPrefs()->GetBoolean(prefs::kDisableGData))
257 return false; 263 return false;
258 264
259 return true; 265 return true;
260 } 266 }
261 267
268 std::string EscapeCacheFileName(const std::string& filename) {
269 // This is based on net/base/escape.cc: net::(anonymous namespace)::Escape
270 const char kHexString[] = "0123456789ABCDEF";
271 std::string escaped;
272 for (unsigned int i = 0; i < filename.length(); ++i) {
satorux1 2012/04/23 21:02:25 unsigned int -> size_t length() -> size() - size(
hshi 2012/04/23 22:01:23 Done.
273 unsigned char c = static_cast<unsigned char>(filename[i]);
274 if (c == '%' || c == '.' || c == '/') {
275 escaped.push_back('%');
276 escaped.push_back(kHexString[c >> 4]);
277 escaped.push_back(kHexString[c & 0xf]);
satorux1 2012/04/23 21:02:25 base::StringAppendF(&escaped, "%%%02X", c) may be
hshi 2012/04/23 22:01:23 Done.
278 } else {
279 escaped.push_back(c);
280 }
281 }
282 return escaped;
283 }
284
285 std::string UnescapeCacheFileName(const std::string& filename) {
286 std::string unescaped;
287 for (unsigned int i = 0; i < filename.length(); ++i) {
satorux1 2012/04/23 21:02:25 size_t and size()
hshi 2012/04/23 22:01:23 Done.
288 unsigned char c = static_cast<unsigned char>(filename[i]);
satorux1 2012/04/23 21:02:25 you probably don't need to cast this to unsigned.
hshi 2012/04/23 22:01:23 Done.
289 if (c == '%' && i + 2 < filename.length()) {
290 c = (HexDigitToInt(filename[i + 1]) << 4) +
291 HexDigitToInt(filename[i + 2]);
satorux1 2012/04/23 21:02:25 one more space to align two lines vertically?
hshi 2012/04/23 22:01:23 Done.
292 i += 2;
293 }
294 unescaped.push_back(c);
295 }
296 return unescaped;
297 }
298
299 void ParseCacheFilePath(const FilePath& path,
300 std::string* resource_id,
301 std::string* md5,
302 std::string* extra_extension) {
303 DCHECK(resource_id);
304 DCHECK(md5);
305 DCHECK(extra_extension);
306
307 // Extract up to two extensions from the right.
308 FilePath base_name = path.BaseName();
309 const int kNumExtensionsToExtract = 2;
310 std::vector<FilePath::StringType> extensions;
311 for (int i = 0; i < kNumExtensionsToExtract; ++i) {
312 FilePath::StringType extension = base_name.Extension();
313 if (!extension.empty()) {
314 // FilePath::Extension returns ".", so strip it.
315 extension = UnescapeCacheFileName(extension.substr(1));
316 base_name = base_name.RemoveExtension();
317 extensions.push_back(extension);
318 } else {
319 break;
320 }
321 }
322
323 // The base_name here is already stripped of extensions in the loop above.
324 *resource_id = UnescapeCacheFileName(base_name.value());
325
326 // Assign the extracted extensions to md5 and extra_extension.
327 int extension_count = extensions.size();
328 *md5 = (extension_count > 0) ? extensions[extension_count - 1] :
329 std::string();
330 *extra_extension = (extension_count > 1) ? extensions[extension_count - 2] :
331 std::string();
332 }
333
262 } // namespace util 334 } // namespace util
263 } // namespace gdata 335 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698