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

Unified 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 side-by-side diff with in-line comments
Download patch
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..945ac5c6d4f40414645e2c9d2d3d9adc85896825 100644
--- a/chrome/browser/chromeos/gdata/gdata_util.cc
+++ b/chrome/browser/chromeos/gdata/gdata_util.cc
@@ -16,6 +16,7 @@
#include "base/json/json_reader.h"
#include "base/logging.h"
#include "base/stringprintf.h"
+#include "base/string_util.h"
#include "base/threading/sequenced_worker_pool.h"
#include "chrome/common/chrome_version_info.h"
#include "chrome/common/libxml_utils.h"
@@ -221,6 +222,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 +265,71 @@ bool IsGDataAvailable(Profile* profile) {
return true;
}
+std::string EscapeCacheFileName(const std::string& filename) {
+ // This is based on net/base/escape.cc: net::(anonymous namespace)::Escape
+ const char kHexString[] = "0123456789ABCDEF";
+ std::string escaped;
+ 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.
+ unsigned char c = static_cast<unsigned char>(filename[i]);
+ if (c == '%' || c == '.' || c == '/') {
+ escaped.push_back('%');
+ escaped.push_back(kHexString[c >> 4]);
+ 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.
+ } else {
+ escaped.push_back(c);
+ }
+ }
+ return escaped;
+}
+
+std::string UnescapeCacheFileName(const std::string& filename) {
+ std::string unescaped;
+ 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.
+ 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.
+ if (c == '%' && i + 2 < filename.length()) {
+ c = (HexDigitToInt(filename[i + 1]) << 4) +
+ 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.
+ i += 2;
+ }
+ unescaped.push_back(c);
+ }
+ return unescaped;
+}
+
+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 = UnescapeCacheFileName(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 = UnescapeCacheFileName(base_name.value());
+
+ // Assign the extracted extensions to md5 and extra_extension.
+ int extension_count = extensions.size();
+ *md5 = (extension_count > 0) ? extensions[extension_count - 1] :
+ std::string();
+ *extra_extension = (extension_count > 1) ? extensions[extension_count - 2] :
+ std::string();
+}
+
} // namespace util
} // namespace gdata

Powered by Google App Engine
This is Rietveld 408576698