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 "webkit/common/fileapi/file_system_util.h" | 5 #include "storage/common/fileapi/file_system_util.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "net/base/escape.h" | 14 #include "net/base/escape.h" |
15 #include "net/base/net_errors.h" | 15 #include "net/base/net_errors.h" |
16 #include "url/gurl.h" | 16 #include "url/gurl.h" |
17 #include "webkit/common/database/database_identifier.h" | 17 #include "storage/common/database/database_identifier.h" |
18 | 18 |
19 namespace fileapi { | 19 namespace storage { |
20 | 20 |
21 const char kPersistentDir[] = "/persistent"; | 21 const char kPersistentDir[] = "/persistent"; |
22 const char kTemporaryDir[] = "/temporary"; | 22 const char kTemporaryDir[] = "/temporary"; |
23 const char kIsolatedDir[] = "/isolated"; | 23 const char kIsolatedDir[] = "/isolated"; |
24 const char kExternalDir[] = "/external"; | 24 const char kExternalDir[] = "/external"; |
25 const char kTestDir[] = "/test"; | 25 const char kTestDir[] = "/test"; |
26 | 26 |
27 const base::FilePath::CharType VirtualPath::kRoot[] = FILE_PATH_LITERAL("/"); | 27 const base::FilePath::CharType VirtualPath::kRoot[] = FILE_PATH_LITERAL("/"); |
28 const base::FilePath::CharType VirtualPath::kSeparator = FILE_PATH_LITERAL('/'); | 28 const base::FilePath::CharType VirtualPath::kSeparator = FILE_PATH_LITERAL('/'); |
29 | 29 |
(...skipping 12 matching lines...) Expand all Loading... |
42 path.find_last_of(base::FilePath::kSeparators); | 42 path.find_last_of(base::FilePath::kSeparators); |
43 if (last_separator != base::FilePath::StringType::npos && | 43 if (last_separator != base::FilePath::StringType::npos && |
44 last_separator < path.size() - 1) | 44 last_separator < path.size() - 1) |
45 path.erase(0, last_separator + 1); | 45 path.erase(0, last_separator + 1); |
46 | 46 |
47 return base::FilePath(path); | 47 return base::FilePath(path); |
48 } | 48 } |
49 | 49 |
50 base::FilePath VirtualPath::DirName(const base::FilePath& virtual_path) { | 50 base::FilePath VirtualPath::DirName(const base::FilePath& virtual_path) { |
51 typedef base::FilePath::StringType StringType; | 51 typedef base::FilePath::StringType StringType; |
52 StringType path = virtual_path.value(); | 52 StringType path = virtual_path.value(); |
53 | 53 |
54 // The logic below is taken from that of base::FilePath::DirName, except | 54 // The logic below is taken from that of base::FilePath::DirName, except |
55 // that this version never cares about '//' or drive-letters even on win32. | 55 // that this version never cares about '//' or drive-letters even on win32. |
56 | 56 |
57 // Strip trailing separators. | 57 // Strip trailing separators. |
58 while (path.size() > 1 && base::FilePath::IsSeparator(path[path.size() - 1])) | 58 while (path.size() > 1 && base::FilePath::IsSeparator(path[path.size() - 1])) |
59 path.resize(path.size() - 1); | 59 path.resize(path.size() - 1); |
60 | 60 |
61 StringType::size_type last_separator = | 61 StringType::size_type last_separator = |
62 path.find_last_of(base::FilePath::kSeparators); | 62 path.find_last_of(base::FilePath::kSeparators); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 std::vector<base::FilePath::StringType>::const_iterator it; | 117 std::vector<base::FilePath::StringType>::const_iterator it; |
118 for (it = stringtype_components.begin(); it != stringtype_components.end(); | 118 for (it = stringtype_components.begin(); it != stringtype_components.end(); |
119 ++it) { | 119 ++it) { |
120 components->push_back(base::FilePath(*it).AsUTF8Unsafe()); | 120 components->push_back(base::FilePath(*it).AsUTF8Unsafe()); |
121 } | 121 } |
122 } | 122 } |
123 | 123 |
124 base::FilePath::StringType VirtualPath::GetNormalizedFilePath( | 124 base::FilePath::StringType VirtualPath::GetNormalizedFilePath( |
125 const base::FilePath& path) { | 125 const base::FilePath& path) { |
126 base::FilePath::StringType normalized_path = path.value(); | 126 base::FilePath::StringType normalized_path = path.value(); |
127 const size_t num_separators = base::FilePath::StringType( | 127 const size_t num_separators = |
128 base::FilePath::kSeparators).length(); | 128 base::FilePath::StringType(base::FilePath::kSeparators).length(); |
129 for (size_t i = 0; i < num_separators; ++i) { | 129 for (size_t i = 0; i < num_separators; ++i) { |
130 std::replace(normalized_path.begin(), normalized_path.end(), | 130 std::replace(normalized_path.begin(), |
131 base::FilePath::kSeparators[i], kSeparator); | 131 normalized_path.end(), |
| 132 base::FilePath::kSeparators[i], |
| 133 kSeparator); |
132 } | 134 } |
133 | 135 |
134 return (IsAbsolute(normalized_path)) ? | 136 return (IsAbsolute(normalized_path)) |
135 normalized_path : base::FilePath::StringType(kRoot) + normalized_path; | 137 ? normalized_path |
| 138 : base::FilePath::StringType(kRoot) + normalized_path; |
136 } | 139 } |
137 | 140 |
138 bool VirtualPath::IsAbsolute(const base::FilePath::StringType& path) { | 141 bool VirtualPath::IsAbsolute(const base::FilePath::StringType& path) { |
139 return path.find(kRoot) == 0; | 142 return path.find(kRoot) == 0; |
140 } | 143 } |
141 | 144 |
142 bool VirtualPath::IsRootPath(const base::FilePath& path) { | 145 bool VirtualPath::IsRootPath(const base::FilePath& path) { |
143 std::vector<base::FilePath::StringType> components; | 146 std::vector<base::FilePath::StringType> components; |
144 VirtualPath::GetComponents(path, &components); | 147 VirtualPath::GetComponents(path, &components); |
145 return (path.empty() || components.empty() || | 148 return (path.empty() || components.empty() || |
146 (components.size() == 1 && | 149 (components.size() == 1 && components[0] == VirtualPath::kRoot)); |
147 components[0] == VirtualPath::kRoot)); | |
148 } | 150 } |
149 | 151 |
150 bool ParseFileSystemSchemeURL(const GURL& url, | 152 bool ParseFileSystemSchemeURL(const GURL& url, |
151 GURL* origin_url, | 153 GURL* origin_url, |
152 FileSystemType* type, | 154 FileSystemType* type, |
153 base::FilePath* virtual_path) { | 155 base::FilePath* virtual_path) { |
154 GURL origin; | 156 GURL origin; |
155 FileSystemType file_system_type = kFileSystemTypeUnknown; | 157 FileSystemType file_system_type = kFileSystemTypeUnknown; |
156 | 158 |
157 if (!url.is_valid() || !url.SchemeIsFileSystem()) | 159 if (!url.is_valid() || !url.SchemeIsFileSystem()) |
158 return false; | 160 return false; |
159 | 161 |
160 const struct { | 162 const struct { |
161 FileSystemType type; | 163 FileSystemType type; |
162 const char* dir; | 164 const char* dir; |
163 } kValidTypes[] = { | 165 } kValidTypes[] = { |
164 { kFileSystemTypePersistent, kPersistentDir }, | 166 {kFileSystemTypePersistent, kPersistentDir}, |
165 { kFileSystemTypeTemporary, kTemporaryDir }, | 167 {kFileSystemTypeTemporary, kTemporaryDir}, |
166 { kFileSystemTypeIsolated, kIsolatedDir }, | 168 {kFileSystemTypeIsolated, kIsolatedDir}, |
167 { kFileSystemTypeExternal, kExternalDir }, | 169 {kFileSystemTypeExternal, kExternalDir}, |
168 { kFileSystemTypeTest, kTestDir }, | 170 {kFileSystemTypeTest, kTestDir}, |
169 }; | 171 }; |
170 | 172 |
171 // A path of the inner_url contains only mount type part (e.g. "/temporary"). | 173 // A path of the inner_url contains only mount type part (e.g. "/temporary"). |
172 DCHECK(url.inner_url()); | 174 DCHECK(url.inner_url()); |
173 std::string inner_path = url.inner_url()->path(); | 175 std::string inner_path = url.inner_url()->path(); |
174 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kValidTypes); ++i) { | 176 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kValidTypes); ++i) { |
175 if (inner_path == kValidTypes[i].dir) { | 177 if (inner_path == kValidTypes[i].dir) { |
176 file_system_type = kValidTypes[i].type; | 178 file_system_type = kValidTypes[i].type; |
177 break; | 179 break; |
178 } | 180 } |
179 } | 181 } |
180 | 182 |
181 if (file_system_type == kFileSystemTypeUnknown) | 183 if (file_system_type == kFileSystemTypeUnknown) |
182 return false; | 184 return false; |
183 | 185 |
184 std::string path = net::UnescapeURLComponent(url.path(), | 186 std::string path = net::UnescapeURLComponent( |
| 187 url.path(), |
185 net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS | | 188 net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS | |
186 net::UnescapeRule::CONTROL_CHARS); | 189 net::UnescapeRule::CONTROL_CHARS); |
187 | 190 |
188 // Ensure the path is relative. | 191 // Ensure the path is relative. |
189 while (!path.empty() && path[0] == '/') | 192 while (!path.empty() && path[0] == '/') |
190 path.erase(0, 1); | 193 path.erase(0, 1); |
191 | 194 |
192 base::FilePath converted_path = base::FilePath::FromUTF8Unsafe(path); | 195 base::FilePath converted_path = base::FilePath::FromUTF8Unsafe(path); |
193 | 196 |
194 // All parent references should have been resolved in the renderer. | 197 // All parent references should have been resolved in the renderer. |
195 if (converted_path.ReferencesParent()) | 198 if (converted_path.ReferencesParent()) |
196 return false; | 199 return false; |
197 | 200 |
198 if (origin_url) | 201 if (origin_url) |
199 *origin_url = url.GetOrigin(); | 202 *origin_url = url.GetOrigin(); |
200 if (type) | 203 if (type) |
201 *type = file_system_type; | 204 *type = file_system_type; |
202 if (virtual_path) | 205 if (virtual_path) |
203 *virtual_path = converted_path.NormalizePathSeparators(). | 206 *virtual_path = |
204 StripTrailingSeparators(); | 207 converted_path.NormalizePathSeparators().StripTrailingSeparators(); |
205 | 208 |
206 return true; | 209 return true; |
207 } | 210 } |
208 | 211 |
209 GURL GetFileSystemRootURI(const GURL& origin_url, FileSystemType type) { | 212 GURL GetFileSystemRootURI(const GURL& origin_url, FileSystemType type) { |
210 // origin_url is based on a security origin, so http://foo.com or file:/// | 213 // origin_url is based on a security origin, so http://foo.com or file:/// |
211 // instead of the corresponding filesystem URL. | 214 // instead of the corresponding filesystem URL. |
212 DCHECK(!origin_url.SchemeIsFileSystem()); | 215 DCHECK(!origin_url.SchemeIsFileSystem()); |
213 | 216 |
214 std::string url = "filesystem:" + origin_url.GetWithEmptyPath().spec(); | 217 std::string url = "filesystem:" + origin_url.GetWithEmptyPath().spec(); |
215 switch (type) { | 218 switch (type) { |
216 case kFileSystemTypeTemporary: | 219 case kFileSystemTypeTemporary: |
217 url += (kTemporaryDir + 1); // We don't want the leading slash. | 220 url += (kTemporaryDir + 1); // We don't want the leading slash. |
218 return GURL(url + "/"); | 221 return GURL(url + "/"); |
219 case kFileSystemTypePersistent: | 222 case kFileSystemTypePersistent: |
220 url += (kPersistentDir + 1); // We don't want the leading slash. | 223 url += (kPersistentDir + 1); // We don't want the leading slash. |
221 return GURL(url + "/"); | 224 return GURL(url + "/"); |
222 case kFileSystemTypeExternal: | 225 case kFileSystemTypeExternal: |
223 url += (kExternalDir + 1); // We don't want the leading slash. | 226 url += (kExternalDir + 1); // We don't want the leading slash. |
224 return GURL(url + "/"); | 227 return GURL(url + "/"); |
225 case kFileSystemTypeIsolated: | 228 case kFileSystemTypeIsolated: |
226 url += (kIsolatedDir + 1); // We don't want the leading slash. | 229 url += (kIsolatedDir + 1); // We don't want the leading slash. |
227 return GURL(url + "/"); | 230 return GURL(url + "/"); |
228 case kFileSystemTypeTest: | 231 case kFileSystemTypeTest: |
229 url += (kTestDir + 1); // We don't want the leading slash. | 232 url += (kTestDir + 1); // We don't want the leading slash. |
230 return GURL(url + "/"); | 233 return GURL(url + "/"); |
231 // Internal types are always pointed via isolated or external URLs. | 234 // Internal types are always pointed via isolated or external URLs. |
232 default: | 235 default: |
233 NOTREACHED(); | 236 NOTREACHED(); |
234 } | 237 } |
235 NOTREACHED(); | 238 NOTREACHED(); |
236 return GURL(); | 239 return GURL(); |
237 } | 240 } |
238 | 241 |
239 std::string GetFileSystemName(const GURL& origin_url, FileSystemType type) { | 242 std::string GetFileSystemName(const GURL& origin_url, FileSystemType type) { |
240 std::string origin_identifier = | 243 std::string origin_identifier = |
241 webkit_database::GetIdentifierFromOrigin(origin_url); | 244 webkit_database::GetIdentifierFromOrigin(origin_url); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 return "PluginPrivate"; | 320 return "PluginPrivate"; |
318 case kFileSystemTypeCloudDevice: | 321 case kFileSystemTypeCloudDevice: |
319 return "CloudDevice"; | 322 return "CloudDevice"; |
320 case kFileSystemTypeProvided: | 323 case kFileSystemTypeProvided: |
321 return "Provided"; | 324 return "Provided"; |
322 case kFileSystemTypeDeviceMediaAsFileStorage: | 325 case kFileSystemTypeDeviceMediaAsFileStorage: |
323 return "DeviceMediaStorage"; | 326 return "DeviceMediaStorage"; |
324 case kFileSystemInternalTypeEnumStart: | 327 case kFileSystemInternalTypeEnumStart: |
325 case kFileSystemInternalTypeEnumEnd: | 328 case kFileSystemInternalTypeEnumEnd: |
326 NOTREACHED(); | 329 NOTREACHED(); |
327 // Fall through. | 330 // Fall through. |
328 case kFileSystemTypeUnknown: | 331 case kFileSystemTypeUnknown: |
329 return "Unknown"; | 332 return "Unknown"; |
330 } | 333 } |
331 NOTREACHED(); | 334 NOTREACHED(); |
332 return std::string(); | 335 return std::string(); |
333 } | 336 } |
334 | 337 |
335 std::string FilePathToString(const base::FilePath& file_path) { | 338 std::string FilePathToString(const base::FilePath& file_path) { |
336 #if defined(OS_WIN) | 339 #if defined(OS_WIN) |
337 return base::UTF16ToUTF8(file_path.value()); | 340 return base::UTF16ToUTF8(file_path.value()); |
338 #elif defined(OS_POSIX) | 341 #elif defined(OS_POSIX) |
339 return file_path.value(); | 342 return file_path.value(); |
340 #endif | 343 #endif |
341 } | 344 } |
342 | 345 |
343 base::FilePath StringToFilePath(const std::string& file_path_string) { | 346 base::FilePath StringToFilePath(const std::string& file_path_string) { |
344 #if defined(OS_WIN) | 347 #if defined(OS_WIN) |
345 return base::FilePath(base::UTF8ToUTF16(file_path_string)); | 348 return base::FilePath(base::UTF8ToUTF16(file_path_string)); |
346 #elif defined(OS_POSIX) | 349 #elif defined(OS_POSIX) |
347 return base::FilePath(file_path_string); | 350 return base::FilePath(file_path_string); |
348 #endif | 351 #endif |
349 } | 352 } |
350 | 353 |
351 blink::WebFileError FileErrorToWebFileError( | 354 blink::WebFileError FileErrorToWebFileError(base::File::Error error_code) { |
352 base::File::Error error_code) { | |
353 switch (error_code) { | 355 switch (error_code) { |
354 case base::File::FILE_ERROR_NOT_FOUND: | 356 case base::File::FILE_ERROR_NOT_FOUND: |
355 return blink::WebFileErrorNotFound; | 357 return blink::WebFileErrorNotFound; |
356 case base::File::FILE_ERROR_INVALID_OPERATION: | 358 case base::File::FILE_ERROR_INVALID_OPERATION: |
357 case base::File::FILE_ERROR_EXISTS: | 359 case base::File::FILE_ERROR_EXISTS: |
358 case base::File::FILE_ERROR_NOT_EMPTY: | 360 case base::File::FILE_ERROR_NOT_EMPTY: |
359 return blink::WebFileErrorInvalidModification; | 361 return blink::WebFileErrorInvalidModification; |
360 case base::File::FILE_ERROR_NOT_A_DIRECTORY: | 362 case base::File::FILE_ERROR_NOT_A_DIRECTORY: |
361 case base::File::FILE_ERROR_NOT_A_FILE: | 363 case base::File::FILE_ERROR_NOT_A_FILE: |
362 return blink::WebFileErrorTypeMismatch; | 364 return blink::WebFileErrorTypeMismatch; |
363 case base::File::FILE_ERROR_ACCESS_DENIED: | 365 case base::File::FILE_ERROR_ACCESS_DENIED: |
364 return blink::WebFileErrorNoModificationAllowed; | 366 return blink::WebFileErrorNoModificationAllowed; |
365 case base::File::FILE_ERROR_FAILED: | 367 case base::File::FILE_ERROR_FAILED: |
366 return blink::WebFileErrorInvalidState; | 368 return blink::WebFileErrorInvalidState; |
367 case base::File::FILE_ERROR_ABORT: | 369 case base::File::FILE_ERROR_ABORT: |
368 return blink::WebFileErrorAbort; | 370 return blink::WebFileErrorAbort; |
369 case base::File::FILE_ERROR_SECURITY: | 371 case base::File::FILE_ERROR_SECURITY: |
370 return blink::WebFileErrorSecurity; | 372 return blink::WebFileErrorSecurity; |
371 case base::File::FILE_ERROR_NO_SPACE: | 373 case base::File::FILE_ERROR_NO_SPACE: |
372 return blink::WebFileErrorQuotaExceeded; | 374 return blink::WebFileErrorQuotaExceeded; |
373 case base::File::FILE_ERROR_INVALID_URL: | 375 case base::File::FILE_ERROR_INVALID_URL: |
374 return blink::WebFileErrorEncoding; | 376 return blink::WebFileErrorEncoding; |
375 default: | 377 default: |
376 return blink::WebFileErrorInvalidModification; | 378 return blink::WebFileErrorInvalidModification; |
377 } | 379 } |
378 } | 380 } |
379 | 381 |
380 bool GetFileSystemPublicType( | 382 bool GetFileSystemPublicType(const std::string type_string, |
381 const std::string type_string, | 383 blink::WebFileSystemType* type) { |
382 blink::WebFileSystemType* type) { | |
383 DCHECK(type); | 384 DCHECK(type); |
384 if (type_string == "Temporary") { | 385 if (type_string == "Temporary") { |
385 *type = blink::WebFileSystemTypeTemporary; | 386 *type = blink::WebFileSystemTypeTemporary; |
386 return true; | 387 return true; |
387 } | 388 } |
388 if (type_string == "Persistent") { | 389 if (type_string == "Persistent") { |
389 *type = blink::WebFileSystemTypePersistent; | 390 *type = blink::WebFileSystemTypePersistent; |
390 return true; | 391 return true; |
391 } | 392 } |
392 if (type_string == "Isolated") { | 393 if (type_string == "Isolated") { |
393 *type = blink::WebFileSystemTypeIsolated; | 394 *type = blink::WebFileSystemTypeIsolated; |
394 return true; | 395 return true; |
395 } | 396 } |
396 if (type_string == "External") { | 397 if (type_string == "External") { |
397 *type = blink::WebFileSystemTypeExternal; | 398 *type = blink::WebFileSystemTypeExternal; |
398 return true; | 399 return true; |
399 } | 400 } |
400 NOTREACHED(); | 401 NOTREACHED(); |
401 return false; | 402 return false; |
402 } | 403 } |
403 | 404 |
404 std::string GetIsolatedFileSystemName(const GURL& origin_url, | 405 std::string GetIsolatedFileSystemName(const GURL& origin_url, |
405 const std::string& filesystem_id) { | 406 const std::string& filesystem_id) { |
406 std::string name(fileapi::GetFileSystemName( | 407 std::string name( |
407 origin_url, fileapi::kFileSystemTypeIsolated)); | 408 storage::GetFileSystemName(origin_url, storage::kFileSystemTypeIsolated)); |
408 name.append("_"); | 409 name.append("_"); |
409 name.append(filesystem_id); | 410 name.append(filesystem_id); |
410 return name; | 411 return name; |
411 } | 412 } |
412 | 413 |
413 bool CrackIsolatedFileSystemName(const std::string& filesystem_name, | 414 bool CrackIsolatedFileSystemName(const std::string& filesystem_name, |
414 std::string* filesystem_id) { | 415 std::string* filesystem_id) { |
415 DCHECK(filesystem_id); | 416 DCHECK(filesystem_id); |
416 | 417 |
417 // |filesystem_name| is of the form {origin}:isolated_{filesystem_id}. | 418 // |filesystem_name| is of the form {origin}:isolated_{filesystem_id}. |
418 std::string start_token(":"); | 419 std::string start_token(":"); |
419 start_token = start_token.append( | 420 start_token = |
420 GetFileSystemTypeString(kFileSystemTypeIsolated)).append("_"); | 421 start_token.append(GetFileSystemTypeString(kFileSystemTypeIsolated)) |
| 422 .append("_"); |
421 // WebKit uses different case in its constant for isolated file system | 423 // WebKit uses different case in its constant for isolated file system |
422 // names, so we do a case insensitive compare by converting both strings | 424 // names, so we do a case insensitive compare by converting both strings |
423 // to uppercase. | 425 // to uppercase. |
424 // TODO(benwells): Remove this when WebKit uses the same constant. | 426 // TODO(benwells): Remove this when WebKit uses the same constant. |
425 start_token = StringToUpperASCII(start_token); | 427 start_token = StringToUpperASCII(start_token); |
426 std::string filesystem_name_upper = StringToUpperASCII(filesystem_name); | 428 std::string filesystem_name_upper = StringToUpperASCII(filesystem_name); |
427 size_t pos = filesystem_name_upper.find(start_token); | 429 size_t pos = filesystem_name_upper.find(start_token); |
428 if (pos == std::string::npos) | 430 if (pos == std::string::npos) |
429 return false; | 431 return false; |
430 if (pos == 0) | 432 if (pos == 0) |
431 return false; | 433 return false; |
432 | 434 |
433 *filesystem_id = filesystem_name.substr(pos + start_token.length(), | 435 *filesystem_id = |
434 std::string::npos); | 436 filesystem_name.substr(pos + start_token.length(), std::string::npos); |
435 if (filesystem_id->empty()) | 437 if (filesystem_id->empty()) |
436 return false; | 438 return false; |
437 | 439 |
438 return true; | 440 return true; |
439 } | 441 } |
440 | 442 |
441 bool ValidateIsolatedFileSystemId(const std::string& filesystem_id) { | 443 bool ValidateIsolatedFileSystemId(const std::string& filesystem_id) { |
442 const size_t kExpectedFileSystemIdSize = 32; | 444 const size_t kExpectedFileSystemIdSize = 32; |
443 if (filesystem_id.size() != kExpectedFileSystemIdSize) | 445 if (filesystem_id.size() != kExpectedFileSystemIdSize) |
444 return false; | 446 return false; |
445 const std::string kExpectedChars("ABCDEF0123456789"); | 447 const std::string kExpectedChars("ABCDEF0123456789"); |
446 return base::ContainsOnlyChars(filesystem_id, kExpectedChars); | 448 return base::ContainsOnlyChars(filesystem_id, kExpectedChars); |
447 } | 449 } |
448 | 450 |
449 std::string GetIsolatedFileSystemRootURIString( | 451 std::string GetIsolatedFileSystemRootURIString( |
450 const GURL& origin_url, | 452 const GURL& origin_url, |
451 const std::string& filesystem_id, | 453 const std::string& filesystem_id, |
452 const std::string& optional_root_name) { | 454 const std::string& optional_root_name) { |
453 std::string root = GetFileSystemRootURI(origin_url, | 455 std::string root = |
454 kFileSystemTypeIsolated).spec(); | 456 GetFileSystemRootURI(origin_url, kFileSystemTypeIsolated).spec(); |
455 if (base::FilePath::FromUTF8Unsafe(filesystem_id).ReferencesParent()) | 457 if (base::FilePath::FromUTF8Unsafe(filesystem_id).ReferencesParent()) |
456 return std::string(); | 458 return std::string(); |
457 root.append(net::EscapePath(filesystem_id)); | 459 root.append(net::EscapePath(filesystem_id)); |
458 root.append("/"); | 460 root.append("/"); |
459 if (!optional_root_name.empty()) { | 461 if (!optional_root_name.empty()) { |
460 if (base::FilePath::FromUTF8Unsafe(optional_root_name).ReferencesParent()) | 462 if (base::FilePath::FromUTF8Unsafe(optional_root_name).ReferencesParent()) |
461 return std::string(); | 463 return std::string(); |
462 root.append(net::EscapePath(optional_root_name)); | 464 root.append(net::EscapePath(optional_root_name)); |
463 root.append("/"); | 465 root.append("/"); |
464 } | 466 } |
465 return root; | 467 return root; |
466 } | 468 } |
467 | 469 |
468 std::string GetExternalFileSystemRootURIString( | 470 std::string GetExternalFileSystemRootURIString(const GURL& origin_url, |
469 const GURL& origin_url, | 471 const std::string& mount_name) { |
470 const std::string& mount_name) { | 472 std::string root = |
471 std::string root = GetFileSystemRootURI(origin_url, | 473 GetFileSystemRootURI(origin_url, kFileSystemTypeExternal).spec(); |
472 kFileSystemTypeExternal).spec(); | |
473 if (base::FilePath::FromUTF8Unsafe(mount_name).ReferencesParent()) | 474 if (base::FilePath::FromUTF8Unsafe(mount_name).ReferencesParent()) |
474 return std::string(); | 475 return std::string(); |
475 root.append(net::EscapePath(mount_name)); | 476 root.append(net::EscapePath(mount_name)); |
476 root.append("/"); | 477 root.append("/"); |
477 return root; | 478 return root; |
478 } | 479 } |
479 | 480 |
480 base::File::Error NetErrorToFileError(int error) { | 481 base::File::Error NetErrorToFileError(int error) { |
481 switch (error) { | 482 switch (error) { |
482 case net::OK: | 483 case net::OK: |
(...skipping 19 matching lines...) Expand all Loading... |
502 case net::ERR_CONNECTION_ABORTED: | 503 case net::ERR_CONNECTION_ABORTED: |
503 return base::File::FILE_ERROR_ABORT; | 504 return base::File::FILE_ERROR_ABORT; |
504 case net::ERR_ADDRESS_INVALID: | 505 case net::ERR_ADDRESS_INVALID: |
505 case net::ERR_INVALID_URL: | 506 case net::ERR_INVALID_URL: |
506 return base::File::FILE_ERROR_INVALID_URL; | 507 return base::File::FILE_ERROR_INVALID_URL; |
507 default: | 508 default: |
508 return base::File::FILE_ERROR_FAILED; | 509 return base::File::FILE_ERROR_FAILED; |
509 } | 510 } |
510 } | 511 } |
511 | 512 |
512 } // namespace fileapi | 513 } // namespace storage |
OLD | NEW |