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

Side by Side Diff: chrome/browser/chromeos/drive/file_system_util.cc

Issue 296593003: Make various string_util functions take StringPieces instead of char[]. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 7 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 | Annotate | Revision Log
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/drive/file_system_util.h" 5 #include "chrome/browser/chromeos/drive/file_system_util.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 30 matching lines...) Expand all
41 #include "net/base/escape.h" 41 #include "net/base/escape.h"
42 #include "webkit/browser/fileapi/file_system_url.h" 42 #include "webkit/browser/fileapi/file_system_url.h"
43 43
44 using content::BrowserThread; 44 using content::BrowserThread;
45 45
46 namespace drive { 46 namespace drive {
47 namespace util { 47 namespace util {
48 48
49 namespace { 49 namespace {
50 50
51 const base::FilePath::CharType kSpecialMountPointRoot[] =
52 FILE_PATH_LITERAL("/special");
53
54 const char kDriveMountPointNameBase[] = "drive";
55
56 const base::FilePath::CharType kDriveMyDriveRootPath[] =
57 FILE_PATH_LITERAL("drive/root");
58
59 const base::FilePath::CharType kFileCacheVersionDir[] =
60 FILE_PATH_LITERAL("v1");
61
62 const char kSlash[] = "/";
63 const char kDot = '.';
64 const char kEscapedChars[] = "_";
65
66 std::string ReadStringFromGDocFile(const base::FilePath& file_path, 51 std::string ReadStringFromGDocFile(const base::FilePath& file_path,
67 const std::string& key) { 52 const std::string& key) {
68 const int64 kMaxGDocSize = 4096; 53 const int64 kMaxGDocSize = 4096;
69 int64 file_size = 0; 54 int64 file_size = 0;
70 if (!base::GetFileSize(file_path, &file_size) || 55 if (!base::GetFileSize(file_path, &file_size) ||
71 file_size > kMaxGDocSize) { 56 file_size > kMaxGDocSize) {
72 LOG(WARNING) << "File too large to be a GDoc file " << file_path.value(); 57 LOG(WARNING) << "File too large to be a GDoc file " << file_path.value();
73 return std::string(); 58 return std::string();
74 } 59 }
75 60
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 } // namespace 101 } // namespace
117 102
118 const base::FilePath& GetDriveGrandRootPath() { 103 const base::FilePath& GetDriveGrandRootPath() {
119 CR_DEFINE_STATIC_LOCAL(base::FilePath, grand_root_path, 104 CR_DEFINE_STATIC_LOCAL(base::FilePath, grand_root_path,
120 (kDriveGrandRootDirName)); 105 (kDriveGrandRootDirName));
121 return grand_root_path; 106 return grand_root_path;
122 } 107 }
123 108
124 const base::FilePath& GetDriveMyDriveRootPath() { 109 const base::FilePath& GetDriveMyDriveRootPath() {
125 CR_DEFINE_STATIC_LOCAL(base::FilePath, drive_root_path, 110 CR_DEFINE_STATIC_LOCAL(base::FilePath, drive_root_path,
126 (kDriveMyDriveRootPath)); 111 (FILE_PATH_LITERAL("drive/root")));
127 return drive_root_path; 112 return drive_root_path;
128 } 113 }
129 114
130 base::FilePath GetDriveMountPointPathForUserIdHash( 115 base::FilePath GetDriveMountPointPathForUserIdHash(
131 const std::string user_id_hash) { 116 const std::string user_id_hash) {
117 static const base::FilePath::CharType kSpecialMountPointRoot[] =
118 FILE_PATH_LITERAL("/special");
119 static const char kDriveMountPointNameBase[] = "drive";
132 return base::FilePath(kSpecialMountPointRoot).AppendASCII( 120 return base::FilePath(kSpecialMountPointRoot).AppendASCII(
133 net::EscapePath(kDriveMountPointNameBase + 121 net::EscapePath(kDriveMountPointNameBase +
134 (user_id_hash.empty() ? "" : "-" + user_id_hash))); 122 (user_id_hash.empty() ? "" : "-" + user_id_hash)));
135 } 123 }
136 124
137 base::FilePath GetDriveMountPointPath(Profile* profile) { 125 base::FilePath GetDriveMountPointPath(Profile* profile) {
138 std::string id = chromeos::ProfileHelper::GetUserIdHashFromProfile(profile); 126 std::string id = chromeos::ProfileHelper::GetUserIdHashFromProfile(profile);
139 if (id.empty() || id == chrome::kLegacyProfileDir) { 127 if (id.empty() || id == chrome::kLegacyProfileDir) {
140 // ProfileHelper::GetUserIdHashFromProfile works only when multi-profile is 128 // ProfileHelper::GetUserIdHashFromProfile works only when multi-profile is
141 // enabled. In that case, we fall back to use UserManager (it basically just 129 // enabled. In that case, we fall back to use UserManager (it basically just
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 if (!url.is_valid() || url.type() != fileapi::kFileSystemTypeDrive) 248 if (!url.is_valid() || url.type() != fileapi::kFileSystemTypeDrive)
261 return base::FilePath(); 249 return base::FilePath();
262 return ExtractDrivePath(url.path()); 250 return ExtractDrivePath(url.path());
263 } 251 }
264 252
265 base::FilePath GetCacheRootPath(Profile* profile) { 253 base::FilePath GetCacheRootPath(Profile* profile) {
266 base::FilePath cache_base_path; 254 base::FilePath cache_base_path;
267 chrome::GetUserCacheDirectory(profile->GetPath(), &cache_base_path); 255 chrome::GetUserCacheDirectory(profile->GetPath(), &cache_base_path);
268 base::FilePath cache_root_path = 256 base::FilePath cache_root_path =
269 cache_base_path.Append(chromeos::kDriveCacheDirname); 257 cache_base_path.Append(chromeos::kDriveCacheDirname);
258 static const base::FilePath::CharType kFileCacheVersionDir[] =
259 FILE_PATH_LITERAL("v1");
270 return cache_root_path.Append(kFileCacheVersionDir); 260 return cache_root_path.Append(kFileCacheVersionDir);
271 } 261 }
272 262
273 std::string EscapeCacheFileName(const std::string& filename) { 263 std::string EscapeCacheFileName(const std::string& filename) {
274 // This is based on net/base/escape.cc: net::(anonymous namespace)::Escape 264 // This is based on net/base/escape.cc: net::(anonymous namespace)::Escape
275 std::string escaped; 265 std::string escaped;
276 for (size_t i = 0; i < filename.size(); ++i) { 266 for (size_t i = 0; i < filename.size(); ++i) {
277 char c = filename[i]; 267 char c = filename[i];
278 if (c == '%' || c == '.' || c == '/') { 268 if (c == '%' || c == '.' || c == '/') {
279 base::StringAppendF(&escaped, "%%%02X", c); 269 base::StringAppendF(&escaped, "%%%02X", c);
(...skipping 17 matching lines...) Expand all
297 } 287 }
298 return unescaped; 288 return unescaped;
299 } 289 }
300 290
301 std::string NormalizeFileName(const std::string& input) { 291 std::string NormalizeFileName(const std::string& input) {
302 DCHECK(base::IsStringUTF8(input)); 292 DCHECK(base::IsStringUTF8(input));
303 293
304 std::string output; 294 std::string output;
305 if (!base::ConvertToUtf8AndNormalize(input, base::kCodepageUTF8, &output)) 295 if (!base::ConvertToUtf8AndNormalize(input, base::kCodepageUTF8, &output))
306 output = input; 296 output = input;
307 base::ReplaceChars(output, kSlash, std::string(kEscapedChars), &output); 297 base::ReplaceChars(output, "/", "_", &output);
308 if (!output.empty() && output.find_first_not_of(kDot, 0) == std::string::npos) 298 if (!output.empty() && output.find_first_not_of('.', 0) == std::string::npos)
309 output = kEscapedChars; 299 output = "_";
310 return output; 300 return output;
311 } 301 }
312 302
313 void PrepareWritableFileAndRun(Profile* profile, 303 void PrepareWritableFileAndRun(Profile* profile,
314 const base::FilePath& path, 304 const base::FilePath& path,
315 const PrepareWritableFileCallback& callback) { 305 const PrepareWritableFileCallback& callback) {
316 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 306 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
317 DCHECK(!callback.is_null()); 307 DCHECK(!callback.is_null());
318 308
319 FileSystemInterface* file_system = GetFileSystemByProfile(profile); 309 FileSystemInterface* file_system = GetFileSystemByProfile(profile);
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 const bool disable_sync_over_celluar = 410 const bool disable_sync_over_celluar =
421 profile->GetPrefs()->GetBoolean(prefs::kDisableDriveOverCellular); 411 profile->GetPrefs()->GetBoolean(prefs::kDisableDriveOverCellular);
422 412
423 if (is_connection_cellular && disable_sync_over_celluar) 413 if (is_connection_cellular && disable_sync_over_celluar)
424 return DRIVE_CONNECTED_METERED; 414 return DRIVE_CONNECTED_METERED;
425 return DRIVE_CONNECTED; 415 return DRIVE_CONNECTED;
426 } 416 }
427 417
428 } // namespace util 418 } // namespace util
429 } // namespace drive 419 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698