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

Side by Side Diff: webkit/fileapi/file_system_util.cc

Issue 12163003: Add FilePath to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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
« no previous file with comments | « webkit/fileapi/file_system_util.h ('k') | webkit/fileapi/file_system_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "webkit/fileapi/file_system_util.h" 5 #include "webkit/fileapi/file_system_util.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "base/sys_string_conversions.h" 12 #include "base/sys_string_conversions.h"
13 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
14 #include "googleurl/src/gurl.h" 14 #include "googleurl/src/gurl.h"
15 #include "third_party/WebKit/Source/Platform/chromium/public/WebCString.h" 15 #include "third_party/WebKit/Source/Platform/chromium/public/WebCString.h"
16 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" 16 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
18 #include "webkit/fileapi/file_system_types.h" 18 #include "webkit/fileapi/file_system_types.h"
19 19
20 namespace fileapi { 20 namespace fileapi {
21 21
22 const char kPersistentDir[] = "/persistent"; 22 const char kPersistentDir[] = "/persistent";
23 const char kTemporaryDir[] = "/temporary"; 23 const char kTemporaryDir[] = "/temporary";
24 const char kIsolatedDir[] = "/isolated"; 24 const char kIsolatedDir[] = "/isolated";
25 const char kExternalDir[] = "/external"; 25 const char kExternalDir[] = "/external";
26 const char kTestDir[] = "/test"; 26 const char kTestDir[] = "/test";
27 27
28 // TODO(ericu): Consider removing support for '\', even on Windows, if possible. 28 // TODO(ericu): Consider removing support for '\', even on Windows, if possible.
29 // There's a lot of test code that will need reworking, and we may have trouble 29 // There's a lot of test code that will need reworking, and we may have trouble
30 // with FilePath elsewhere [e.g. DirName and other methods may also need 30 // with base::FilePath elsewhere [e.g. DirName and other methods may also need
31 // replacement]. 31 // replacement].
32 FilePath VirtualPath::BaseName(const FilePath& virtual_path) { 32 base::FilePath VirtualPath::BaseName(const base::FilePath& virtual_path) {
33 FilePath::StringType path = virtual_path.value(); 33 base::FilePath::StringType path = virtual_path.value();
34 34
35 // Keep everything after the final separator, but if the pathname is only 35 // Keep everything after the final separator, but if the pathname is only
36 // one character and it's a separator, leave it alone. 36 // one character and it's a separator, leave it alone.
37 while (path.size() > 1 && FilePath::IsSeparator(path[path.size() - 1])) 37 while (path.size() > 1 && base::FilePath::IsSeparator(path[path.size() - 1]))
38 path.resize(path.size() - 1); 38 path.resize(path.size() - 1);
39 FilePath::StringType::size_type last_separator = 39 base::FilePath::StringType::size_type last_separator =
40 path.find_last_of(FilePath::kSeparators); 40 path.find_last_of(base::FilePath::kSeparators);
41 if (last_separator != FilePath::StringType::npos && 41 if (last_separator != base::FilePath::StringType::npos &&
42 last_separator < path.size() - 1) 42 last_separator < path.size() - 1)
43 path.erase(0, last_separator + 1); 43 path.erase(0, last_separator + 1);
44 44
45 return FilePath(path); 45 return base::FilePath(path);
46 } 46 }
47 47
48 void VirtualPath::GetComponents( 48 void VirtualPath::GetComponents(
49 const FilePath& path, std::vector<FilePath::StringType>* components) { 49 const base::FilePath& path, std::vector<base::FilePath::StringType>* compone nts) {
50 DCHECK(components); 50 DCHECK(components);
51 if (!components) 51 if (!components)
52 return; 52 return;
53 components->clear(); 53 components->clear();
54 if (path.value().empty()) 54 if (path.value().empty())
55 return; 55 return;
56 56
57 std::vector<FilePath::StringType> ret_val; 57 std::vector<base::FilePath::StringType> ret_val;
58 FilePath current = path; 58 base::FilePath current = path;
59 FilePath base; 59 base::FilePath base;
60 60
61 // Due to the way things are implemented, FilePath::DirName works here, 61 // Due to the way things are implemented, base::FilePath::DirName works here,
62 // whereas FilePath::BaseName doesn't. 62 // whereas base::FilePath::BaseName doesn't.
63 while (current != current.DirName()) { 63 while (current != current.DirName()) {
64 base = BaseName(current); 64 base = BaseName(current);
65 ret_val.push_back(base.value()); 65 ret_val.push_back(base.value());
66 current = current.DirName(); 66 current = current.DirName();
67 } 67 }
68 68
69 *components = 69 *components =
70 std::vector<FilePath::StringType>(ret_val.rbegin(), ret_val.rend()); 70 std::vector<base::FilePath::StringType>(ret_val.rbegin(), ret_val.rend());
71 } 71 }
72 72
73 GURL GetFileSystemRootURI(const GURL& origin_url, FileSystemType type) { 73 GURL GetFileSystemRootURI(const GURL& origin_url, FileSystemType type) {
74 // origin_url is based on a security origin, so http://foo.com or file:/// 74 // origin_url is based on a security origin, so http://foo.com or file:///
75 // instead of the corresponding filesystem URL. 75 // instead of the corresponding filesystem URL.
76 DCHECK(!origin_url.SchemeIsFileSystem()); 76 DCHECK(!origin_url.SchemeIsFileSystem());
77 77
78 std::string url = "filesystem:" + origin_url.GetWithEmptyPath().spec(); 78 std::string url = "filesystem:" + origin_url.GetWithEmptyPath().spec();
79 switch (type) { 79 switch (type) {
80 case kFileSystemTypeTemporary: 80 case kFileSystemTypeTemporary:
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 return "Drive"; 186 return "Drive";
187 case kFileSystemTypeSyncable: 187 case kFileSystemTypeSyncable:
188 return "Syncable"; 188 return "Syncable";
189 case kFileSystemTypeUnknown: 189 case kFileSystemTypeUnknown:
190 return "Unknown"; 190 return "Unknown";
191 } 191 }
192 NOTREACHED(); 192 NOTREACHED();
193 return std::string(); 193 return std::string();
194 } 194 }
195 195
196 std::string FilePathToString(const FilePath& file_path) { 196 std::string FilePathToString(const base::FilePath& file_path) {
197 #if defined(OS_WIN) 197 #if defined(OS_WIN)
198 return UTF16ToUTF8(file_path.value()); 198 return UTF16ToUTF8(file_path.value());
199 #elif defined(OS_POSIX) 199 #elif defined(OS_POSIX)
200 return file_path.value(); 200 return file_path.value();
201 #endif 201 #endif
202 } 202 }
203 203
204 FilePath StringToFilePath(const std::string& file_path_string) { 204 base::FilePath StringToFilePath(const std::string& file_path_string) {
205 #if defined(OS_WIN) 205 #if defined(OS_WIN)
206 return FilePath(UTF8ToUTF16(file_path_string)); 206 return base::FilePath(UTF8ToUTF16(file_path_string));
207 #elif defined(OS_POSIX) 207 #elif defined(OS_POSIX)
208 return FilePath(file_path_string); 208 return base::FilePath(file_path_string);
209 #endif 209 #endif
210 } 210 }
211 211
212 WebKit::WebFileError PlatformFileErrorToWebFileError( 212 WebKit::WebFileError PlatformFileErrorToWebFileError(
213 base::PlatformFileError error_code) { 213 base::PlatformFileError error_code) {
214 switch (error_code) { 214 switch (error_code) {
215 case base::PLATFORM_FILE_ERROR_NOT_FOUND: 215 case base::PLATFORM_FILE_ERROR_NOT_FOUND:
216 return WebKit::WebFileErrorNotFound; 216 return WebKit::WebFileErrorNotFound;
217 case base::PLATFORM_FILE_ERROR_INVALID_OPERATION: 217 case base::PLATFORM_FILE_ERROR_INVALID_OPERATION:
218 case base::PLATFORM_FILE_ERROR_EXISTS: 218 case base::PLATFORM_FILE_ERROR_EXISTS:
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 275
276 std::string GetIsolatedFileSystemRootURIString( 276 std::string GetIsolatedFileSystemRootURIString(
277 const GURL& origin_url, 277 const GURL& origin_url,
278 const std::string& filesystem_id, 278 const std::string& filesystem_id,
279 const std::string& optional_root_name) { 279 const std::string& optional_root_name) {
280 std::string root = GetFileSystemRootURI(origin_url, 280 std::string root = GetFileSystemRootURI(origin_url,
281 kFileSystemTypeIsolated).spec(); 281 kFileSystemTypeIsolated).spec();
282 root.append(filesystem_id); 282 root.append(filesystem_id);
283 root.append("/"); 283 root.append("/");
284 if (!optional_root_name.empty()) { 284 if (!optional_root_name.empty()) {
285 DCHECK(!FilePath::FromUTF8Unsafe(optional_root_name).ReferencesParent()); 285 DCHECK(!base::FilePath::FromUTF8Unsafe(optional_root_name).ReferencesParent( ));
286 root.append(optional_root_name); 286 root.append(optional_root_name);
287 root.append("/"); 287 root.append("/");
288 } 288 }
289 return root; 289 return root;
290 } 290 }
291 291
292 } // namespace fileapi 292 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/file_system_util.h ('k') | webkit/fileapi/file_system_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698