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

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

Issue 10447055: Move fileapi into its own component (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup Created 8 years, 6 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_usage_cache.h ('k') | webkit/fileapi/file_system_util.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 #ifndef WEBKIT_FILEAPI_FILE_SYSTEM_UTIL_H_ 5 #ifndef WEBKIT_FILEAPI_FILE_SYSTEM_UTIL_H_
6 #define WEBKIT_FILEAPI_FILE_SYSTEM_UTIL_H_ 6 #define WEBKIT_FILEAPI_FILE_SYSTEM_UTIL_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/file_path.h" 12 #include "base/file_path.h"
13 #include "base/platform_file.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileError.h"
15 #include "webkit/fileapi/fileapi_export.h"
13 #include "webkit/fileapi/file_system_types.h" 16 #include "webkit/fileapi/file_system_types.h"
14 #include "webkit/quota/quota_types.h" 17 #include "webkit/quota/quota_types.h"
15 18
16 class GURL; 19 class GURL;
17 20
18 namespace fileapi { 21 namespace fileapi {
19 22
20 extern const char kPersistentDir[]; 23 extern const char kPersistentDir[];
21 extern const char kTemporaryDir[]; 24 extern const char kTemporaryDir[];
22 extern const char kExternalDir[]; 25 extern const char kExternalDir[];
23 extern const char kIsolatedDir[]; 26 extern const char kIsolatedDir[];
24 extern const char kPersistentName[]; 27 extern const char kPersistentName[];
25 extern const char kTemporaryName[]; 28 extern const char kTemporaryName[];
26 extern const char kExternalName[]; 29 extern const char kExternalName[];
27 extern const char kIsolatedName[]; 30 extern const char kIsolatedName[];
28 31
29 // Cracks the given filesystem |url| and populates |origin_url|, |type| 32 // Cracks the given filesystem |url| and populates |origin_url|, |type|
30 // and |file_path|. Returns true if the given |url| is a valid filesystem 33 // and |file_path|. Returns true if the given |url| is a valid filesystem
31 // url and the routine could successfully crack it, returns false otherwise. 34 // url and the routine could successfully crack it, returns false otherwise.
32 // The file_path this returns will be using '/' as a path separator, no matter 35 // The file_path this returns will be using '/' as a path separator, no matter
33 // what platform you're on. 36 // what platform you're on.
34 // TODO(ericu): Look into making file_path [and all FileSystem API virtual 37 // TODO(ericu): Look into making file_path [and all FileSystem API virtual
35 // paths] just an std::string, to prevent platform-specific FilePath behavior 38 // paths] just an std::string, to prevent platform-specific FilePath behavior
36 // from getting invoked by accident. Currently the FilePath returned here needs 39 // from getting invoked by accident. Currently the FilePath returned here needs
37 // special treatment, as it may contain paths that are illegal on the current 40 // special treatment, as it may contain paths that are illegal on the current
38 // platform. To avoid problems, use VirtualPath::BaseName and 41 // platform. To avoid problems, use VirtualPath::BaseName and
39 // VirtualPath::GetComponents instead of the FilePath methods. 42 // VirtualPath::GetComponents instead of the FilePath methods.
40 bool CrackFileSystemURL(const GURL& url, 43 FILEAPI_EXPORT bool CrackFileSystemURL(const GURL& url,
41 GURL* origin_url, 44 GURL* origin_url,
42 FileSystemType* type, 45 FileSystemType* type,
43 FilePath* file_path); 46 FilePath* file_path);
44 47
45 class VirtualPath { 48 class FILEAPI_EXPORT VirtualPath {
46 public: 49 public:
47 // Use this instead of FilePath::BaseName when operating on virtual paths. 50 // Use this instead of FilePath::BaseName when operating on virtual paths.
48 // FilePath::BaseName will get confused by ':' on Windows when it looks like a 51 // FilePath::BaseName will get confused by ':' on Windows when it looks like a
49 // drive letter separator; this will treat it as just another character. 52 // drive letter separator; this will treat it as just another character.
50 static FilePath BaseName(const FilePath& virtual_path); 53 static FilePath BaseName(const FilePath& virtual_path);
51 54
52 // Likewise, use this instead of FilePath::GetComponents when operating on 55 // Likewise, use this instead of FilePath::GetComponents when operating on
53 // virtual paths. 56 // virtual paths.
54 // Note that this assumes very clean input, with no leading slash, and it will 57 // Note that this assumes very clean input, with no leading slash, and it will
55 // not evaluate '.' or '..' components. 58 // not evaluate '.' or '..' components.
56 static void GetComponents(const FilePath& path, 59 static void GetComponents(const FilePath& path,
57 std::vector<FilePath::StringType>* components); 60 std::vector<FilePath::StringType>* components);
58 }; 61 };
59 62
60 // Returns the root URI of the filesystem that can be specified by a pair of 63 // Returns the root URI of the filesystem that can be specified by a pair of
61 // |origin_url| and |type|. The returned URI can be used as a root path 64 // |origin_url| and |type|. The returned URI can be used as a root path
62 // of the filesystem (e.g. <returned_URI> + "/relative/path" will compose 65 // of the filesystem (e.g. <returned_URI> + "/relative/path" will compose
63 // a path pointing to the entry "/relative/path" in the filesystem). 66 // a path pointing to the entry "/relative/path" in the filesystem).
64 // 67 //
65 // For Isolated filesystem this returns the 'common' root part, e.g. 68 // For Isolated filesystem this returns the 'common' root part, e.g.
66 // returns URL without the filesystem ID. 69 // returns URL without the filesystem ID.
67 GURL GetFileSystemRootURI(const GURL& origin_url, FileSystemType type); 70 FILEAPI_EXPORT GURL GetFileSystemRootURI(const GURL& origin_url,
71 FileSystemType type);
68 72
69 // Returns the name for the filesystem that is specified by a pair of 73 // Returns the name for the filesystem that is specified by a pair of
70 // |origin_url| and |type|. 74 // |origin_url| and |type|.
71 // (The name itself is neither really significant nor a formal identifier 75 // (The name itself is neither really significant nor a formal identifier
72 // but can be read as the .name field of the returned FileSystem object 76 // but can be read as the .name field of the returned FileSystem object
73 // as a user-friendly name in the javascript layer). 77 // as a user-friendly name in the javascript layer).
74 // 78 //
75 // Example: 79 // Example:
76 // The name for a TEMPORARY filesystem of "http://www.example.com:80/" 80 // The name for a TEMPORARY filesystem of "http://www.example.com:80/"
77 // should look like: "http_www.example.host_80:temporary" 81 // should look like: "http_www.example.host_80:temporary"
78 std::string GetFileSystemName(const GURL& origin_url, FileSystemType type); 82 FILEAPI_EXPORT std::string GetFileSystemName(const GURL& origin_url,
83 FileSystemType type);
79 84
80 // Converts FileSystemType |type| to/from the StorageType |storage_type| that 85 // Converts FileSystemType |type| to/from the StorageType |storage_type| that
81 // is used for the unified quota system. 86 // is used for the unified quota system.
82 // (Basically this naively maps TEMPORARY storage type to TEMPORARY filesystem 87 // (Basically this naively maps TEMPORARY storage type to TEMPORARY filesystem
83 // type, PERSISTENT storage type to PERSISTENT filesystem type and vice versa.) 88 // type, PERSISTENT storage type to PERSISTENT filesystem type and vice versa.)
84 FileSystemType QuotaStorageTypeToFileSystemType( 89 FILEAPI_EXPORT FileSystemType QuotaStorageTypeToFileSystemType(
85 quota::StorageType storage_type); 90 quota::StorageType storage_type);
86 quota::StorageType FileSystemTypeToQuotaStorageType(FileSystemType type); 91 FILEAPI_EXPORT quota::StorageType FileSystemTypeToQuotaStorageType(
92 FileSystemType type);
87 93
88 // Returns the origin identifier string for the given |url| and vice versa. 94 // Returns the origin identifier string for the given |url| and vice versa.
89 // The origin identifier string is a serialized form of a security origin 95 // The origin identifier string is a serialized form of a security origin
90 // and can be used as a path name as it contains no "/" or other possibly 96 // and can be used as a path name as it contains no "/" or other possibly
91 // unsafe characters. (See WebKit's SecurityOrigin code for more details.) 97 // unsafe characters. (See WebKit's SecurityOrigin code for more details.)
92 // 98 //
93 // Example: 99 // Example:
94 // "http://www.example.com:80/"'s identifier should look like: 100 // "http://www.example.com:80/"'s identifier should look like:
95 // "http_www.example.host_80" 101 // "http_www.example.host_80"
96 std::string GetOriginIdentifierFromURL(const GURL& url); 102 FILEAPI_EXPORT std::string GetOriginIdentifierFromURL(const GURL& url);
97 GURL GetOriginURLFromIdentifier(const std::string& origin_identifier); 103 FILEAPI_EXPORT GURL GetOriginURLFromIdentifier(
104 const std::string& origin_identifier);
98 105
99 // Returns the string representation of the given filesystem |type|. 106 // Returns the string representation of the given filesystem |type|.
100 // Returns an empty string if the |type| is invalid. 107 // Returns an empty string if the |type| is invalid.
101 std::string GetFileSystemTypeString(FileSystemType type); 108 FILEAPI_EXPORT std::string GetFileSystemTypeString(FileSystemType type);
102 109
103 // Encodes |file_path| to a string. 110 // Encodes |file_path| to a string.
104 // Following conditions should be held: 111 // Following conditions should be held:
105 // - StringToFilePath(FilePathToString(path)) == path 112 // - StringToFilePath(FilePathToString(path)) == path
106 // - StringToFilePath(FilePathToString(path) + "/" + "SubDirectory") == 113 // - StringToFilePath(FilePathToString(path) + "/" + "SubDirectory") ==
107 // path.AppendASCII("SubDirectory"); 114 // path.AppendASCII("SubDirectory");
108 // 115 //
109 // TODO(tzik): Replace CreateFilePath and FilePathToString in 116 // TODO(tzik): Replace CreateFilePath and FilePathToString in
110 // third_party/leveldatabase/env_chromium.cc with them. 117 // third_party/leveldatabase/env_chromium.cc with them.
111 std::string FilePathToString(const FilePath& file_path); 118 FILEAPI_EXPORT std::string FilePathToString(const FilePath& file_path);
112 119
113 // Decode a file path from |file_path_string|. 120 // Decode a file path from |file_path_string|.
114 FilePath StringToFilePath(const std::string& file_path_string); 121 FILEAPI_EXPORT FilePath StringToFilePath(const std::string& file_path_string);
122
123 // File error conversion
124 FILEAPI_EXPORT WebKit::WebFileError PlatformFileErrorToWebFileError(
125 base::PlatformFileError error_code);
115 126
116 } // namespace fileapi 127 } // namespace fileapi
117 128
118 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_UTIL_H_ 129 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_UTIL_H_
OLDNEW
« no previous file with comments | « webkit/fileapi/file_system_usage_cache.h ('k') | webkit/fileapi/file_system_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698