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 #ifndef WEBKIT_COMMON_FILEAPI_FILE_SYSTEM_UTIL_H_ | 5 #ifndef WEBKIT_COMMON_FILEAPI_FILE_SYSTEM_UTIL_H_ |
6 #define WEBKIT_COMMON_FILEAPI_FILE_SYSTEM_UTIL_H_ | 6 #define WEBKIT_COMMON_FILEAPI_FILE_SYSTEM_UTIL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/files/file.h" | 11 #include "base/files/file.h" |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "third_party/WebKit/public/platform/WebFileError.h" | 13 #include "third_party/WebKit/public/platform/WebFileError.h" |
14 #include "third_party/WebKit/public/platform/WebFileSystemType.h" | 14 #include "third_party/WebKit/public/platform/WebFileSystemType.h" |
15 #include "webkit/common/fileapi/file_system_info.h" | 15 #include "storage/common/fileapi/file_system_info.h" |
16 #include "webkit/common/fileapi/file_system_types.h" | 16 #include "storage/common/fileapi/file_system_types.h" |
17 #include "webkit/common/quota/quota_types.h" | 17 #include "storage/common/quota/quota_types.h" |
18 #include "webkit/common/webkit_storage_common_export.h" | 18 #include "storage/common/storage_export.h" |
19 | 19 |
20 class GURL; | 20 class GURL; |
21 | 21 |
22 namespace fileapi { | 22 namespace storage { |
23 | 23 |
24 WEBKIT_STORAGE_COMMON_EXPORT extern const char kPersistentDir[]; | 24 STORAGE_EXPORT extern const char kPersistentDir[]; |
25 WEBKIT_STORAGE_COMMON_EXPORT extern const char kTemporaryDir[]; | 25 STORAGE_EXPORT extern const char kTemporaryDir[]; |
26 WEBKIT_STORAGE_COMMON_EXPORT extern const char kExternalDir[]; | 26 STORAGE_EXPORT extern const char kExternalDir[]; |
27 WEBKIT_STORAGE_COMMON_EXPORT extern const char kIsolatedDir[]; | 27 STORAGE_EXPORT extern const char kIsolatedDir[]; |
28 WEBKIT_STORAGE_COMMON_EXPORT extern const char kTestDir[]; | 28 STORAGE_EXPORT extern const char kTestDir[]; |
29 | 29 |
30 class WEBKIT_STORAGE_COMMON_EXPORT VirtualPath { | 30 class STORAGE_EXPORT VirtualPath { |
31 public: | 31 public: |
32 static const base::FilePath::CharType kRoot[]; | 32 static const base::FilePath::CharType kRoot[]; |
33 static const base::FilePath::CharType kSeparator; | 33 static const base::FilePath::CharType kSeparator; |
34 | 34 |
35 // Use this instead of base::FilePath::BaseName when operating on virtual | 35 // Use this instead of base::FilePath::BaseName when operating on virtual |
36 // paths. FilePath::BaseName will get confused by ':' on Windows when it | 36 // paths. FilePath::BaseName will get confused by ':' on Windows when it |
37 // looks like a drive letter separator; this will treat it as just another | 37 // looks like a drive letter separator; this will treat it as just another |
38 // character. | 38 // character. |
39 static base::FilePath BaseName(const base::FilePath& virtual_path); | 39 static base::FilePath BaseName(const base::FilePath& virtual_path); |
40 | 40 |
41 // Use this instead of base::FilePath::DirName when operating on virtual | 41 // Use this instead of base::FilePath::DirName when operating on virtual |
42 // paths. | 42 // paths. |
43 static base::FilePath DirName(const base::FilePath& virtual_path); | 43 static base::FilePath DirName(const base::FilePath& virtual_path); |
44 | 44 |
45 // Likewise, use this instead of base::FilePath::GetComponents when | 45 // Likewise, use this instead of base::FilePath::GetComponents when |
46 // operating on virtual paths. | 46 // operating on virtual paths. |
47 // Note that this assumes very clean input, with no leading slash, and | 47 // Note that this assumes very clean input, with no leading slash, and |
48 // it will not evaluate '..' components. | 48 // it will not evaluate '..' components. |
49 static void GetComponents( | 49 static void GetComponents( |
50 const base::FilePath& path, | 50 const base::FilePath& path, |
51 std::vector<base::FilePath::StringType>* components); | 51 std::vector<base::FilePath::StringType>* components); |
52 | 52 |
53 static void GetComponentsUTF8Unsafe( | 53 static void GetComponentsUTF8Unsafe(const base::FilePath& path, |
54 const base::FilePath& path, std::vector<std::string>* components); | 54 std::vector<std::string>* components); |
55 | 55 |
56 // Returns a path name ensuring that it begins with kRoot and all path | 56 // Returns a path name ensuring that it begins with kRoot and all path |
57 // separators are forward slashes /. | 57 // separators are forward slashes /. |
58 static base::FilePath::StringType GetNormalizedFilePath( | 58 static base::FilePath::StringType GetNormalizedFilePath( |
59 const base::FilePath& path); | 59 const base::FilePath& path); |
60 | 60 |
61 // Returns true if the given path begins with kRoot. | 61 // Returns true if the given path begins with kRoot. |
62 static bool IsAbsolute(const base::FilePath::StringType& path); | 62 static bool IsAbsolute(const base::FilePath::StringType& path); |
63 | 63 |
64 // Returns true if the given path points to the root. | 64 // Returns true if the given path points to the root. |
65 static bool IsRootPath(const base::FilePath& path); | 65 static bool IsRootPath(const base::FilePath& path); |
66 }; | 66 }; |
67 | 67 |
68 // Parses filesystem scheme |url| into uncracked file system URL components. | 68 // Parses filesystem scheme |url| into uncracked file system URL components. |
69 // Example: For a URL 'filesystem:http://foo.com/temporary/foo/bar', | 69 // Example: For a URL 'filesystem:http://foo.com/temporary/foo/bar', |
70 // |origin_url| is set to 'http://foo.com', |type| is set to | 70 // |origin_url| is set to 'http://foo.com', |type| is set to |
71 // kFileSystemTypeTemporary, and |virtual_path| is set to 'foo/bar'. | 71 // kFileSystemTypeTemporary, and |virtual_path| is set to 'foo/bar'. |
72 WEBKIT_STORAGE_COMMON_EXPORT bool ParseFileSystemSchemeURL( | 72 STORAGE_EXPORT bool ParseFileSystemSchemeURL(const GURL& url, |
73 const GURL& url, | 73 GURL* origin_url, |
74 GURL* origin_url, | 74 FileSystemType* type, |
75 FileSystemType* type, | 75 base::FilePath* virtual_path); |
76 base::FilePath* virtual_path); | |
77 | 76 |
78 // Returns the root URI of the filesystem that can be specified by a pair of | 77 // Returns the root URI of the filesystem that can be specified by a pair of |
79 // |origin_url| and |type|. The returned URI can be used as a root path | 78 // |origin_url| and |type|. The returned URI can be used as a root path |
80 // of the filesystem (e.g. <returned_URI> + "/relative/path" will compose | 79 // of the filesystem (e.g. <returned_URI> + "/relative/path" will compose |
81 // a path pointing to the entry "/relative/path" in the filesystem). | 80 // a path pointing to the entry "/relative/path" in the filesystem). |
82 // | 81 // |
83 // For Isolated filesystem this returns the 'common' root part, e.g. | 82 // For Isolated filesystem this returns the 'common' root part, e.g. |
84 // returns URL without the filesystem ID. | 83 // returns URL without the filesystem ID. |
85 // | 84 // |
86 // |type| needs to be public type as the returned URI is given to the renderer. | 85 // |type| needs to be public type as the returned URI is given to the renderer. |
87 WEBKIT_STORAGE_COMMON_EXPORT GURL GetFileSystemRootURI(const GURL& origin_url, | 86 STORAGE_EXPORT GURL |
88 FileSystemType type); | 87 GetFileSystemRootURI(const GURL& origin_url, FileSystemType type); |
89 | 88 |
90 // Returns the name for the filesystem that is specified by a pair of | 89 // Returns the name for the filesystem that is specified by a pair of |
91 // |origin_url| and |type|. | 90 // |origin_url| and |type|. |
92 // (The name itself is neither really significant nor a formal identifier | 91 // (The name itself is neither really significant nor a formal identifier |
93 // but can be read as the .name field of the returned FileSystem object | 92 // but can be read as the .name field of the returned FileSystem object |
94 // as a user-friendly name in the javascript layer). | 93 // as a user-friendly name in the javascript layer). |
95 // | 94 // |
96 // |type| needs to be public type as the returned name is given to the renderer. | 95 // |type| needs to be public type as the returned name is given to the renderer. |
97 // | 96 // |
98 // Example: | 97 // Example: |
99 // The name for a TEMPORARY filesystem of "http://www.example.com:80/" | 98 // The name for a TEMPORARY filesystem of "http://www.example.com:80/" |
100 // should look like: "http_www.example.host_80:temporary" | 99 // should look like: "http_www.example.host_80:temporary" |
101 WEBKIT_STORAGE_COMMON_EXPORT std::string | 100 STORAGE_EXPORT std::string GetFileSystemName(const GURL& origin_url, |
102 GetFileSystemName(const GURL& origin_url, FileSystemType type); | 101 FileSystemType type); |
103 | 102 |
104 // Converts FileSystemType |type| to/from the StorageType |storage_type| that | 103 // Converts FileSystemType |type| to/from the StorageType |storage_type| that |
105 // is used for the unified quota system. | 104 // is used for the unified quota system. |
106 // (Basically this naively maps TEMPORARY storage type to TEMPORARY filesystem | 105 // (Basically this naively maps TEMPORARY storage type to TEMPORARY filesystem |
107 // type, PERSISTENT storage type to PERSISTENT filesystem type and vice versa.) | 106 // type, PERSISTENT storage type to PERSISTENT filesystem type and vice versa.) |
108 WEBKIT_STORAGE_COMMON_EXPORT FileSystemType | 107 STORAGE_EXPORT FileSystemType |
109 QuotaStorageTypeToFileSystemType(quota::StorageType storage_type); | 108 QuotaStorageTypeToFileSystemType(quota::StorageType storage_type); |
110 | 109 |
111 WEBKIT_STORAGE_COMMON_EXPORT quota::StorageType | 110 STORAGE_EXPORT quota::StorageType FileSystemTypeToQuotaStorageType( |
112 FileSystemTypeToQuotaStorageType(FileSystemType type); | 111 FileSystemType type); |
113 | 112 |
114 // Returns the string representation of the given filesystem |type|. | 113 // Returns the string representation of the given filesystem |type|. |
115 // Returns an empty string if the |type| is invalid. | 114 // Returns an empty string if the |type| is invalid. |
116 WEBKIT_STORAGE_COMMON_EXPORT std::string | 115 STORAGE_EXPORT std::string GetFileSystemTypeString(FileSystemType type); |
117 GetFileSystemTypeString(FileSystemType type); | |
118 | 116 |
119 // Sets type to FileSystemType enum that corresponds to the string name. | 117 // Sets type to FileSystemType enum that corresponds to the string name. |
120 // Returns false if the |type_string| is invalid. | 118 // Returns false if the |type_string| is invalid. |
121 WEBKIT_STORAGE_COMMON_EXPORT bool GetFileSystemPublicType( | 119 STORAGE_EXPORT bool GetFileSystemPublicType(std::string type_string, |
122 std::string type_string, | 120 blink::WebFileSystemType* type); |
123 blink::WebFileSystemType* type); | |
124 | 121 |
125 // Encodes |file_path| to a string. | 122 // Encodes |file_path| to a string. |
126 // Following conditions should be held: | 123 // Following conditions should be held: |
127 // - StringToFilePath(FilePathToString(path)) == path | 124 // - StringToFilePath(FilePathToString(path)) == path |
128 // - StringToFilePath(FilePathToString(path) + "/" + "SubDirectory") == | 125 // - StringToFilePath(FilePathToString(path) + "/" + "SubDirectory") == |
129 // path.AppendASCII("SubDirectory"); | 126 // path.AppendASCII("SubDirectory"); |
130 // | 127 // |
131 // TODO(tzik): Replace CreateFilePath and FilePathToString in | 128 // TODO(tzik): Replace CreateFilePath and FilePathToString in |
132 // third_party/leveldatabase/env_chromium.cc with them. | 129 // third_party/leveldatabase/env_chromium.cc with them. |
133 WEBKIT_STORAGE_COMMON_EXPORT std::string FilePathToString( | 130 STORAGE_EXPORT std::string FilePathToString(const base::FilePath& file_path); |
134 const base::FilePath& file_path); | |
135 | 131 |
136 // Decode a file path from |file_path_string|. | 132 // Decode a file path from |file_path_string|. |
137 WEBKIT_STORAGE_COMMON_EXPORT base::FilePath StringToFilePath( | 133 STORAGE_EXPORT base::FilePath StringToFilePath( |
138 const std::string& file_path_string); | 134 const std::string& file_path_string); |
139 | 135 |
140 // File error conversion | 136 // File error conversion |
141 WEBKIT_STORAGE_COMMON_EXPORT blink::WebFileError | 137 STORAGE_EXPORT blink::WebFileError FileErrorToWebFileError( |
142 FileErrorToWebFileError(base::File::Error error_code); | 138 base::File::Error error_code); |
143 | 139 |
144 // Generate a file system name for the given arguments. Should only be used by | 140 // Generate a file system name for the given arguments. Should only be used by |
145 // platform apps. | 141 // platform apps. |
146 WEBKIT_STORAGE_COMMON_EXPORT std::string GetIsolatedFileSystemName( | 142 STORAGE_EXPORT std::string GetIsolatedFileSystemName( |
147 const GURL& origin_url, | 143 const GURL& origin_url, |
148 const std::string& filesystem_id); | 144 const std::string& filesystem_id); |
149 | 145 |
150 // Find the file system id from |filesystem_name|. Should only be used by | 146 // Find the file system id from |filesystem_name|. Should only be used by |
151 // platform apps. This function will return false if the file system name is | 147 // platform apps. This function will return false if the file system name is |
152 // not of the form {origin}:Isolated_{id}, and will also check that there is an | 148 // not of the form {origin}:Isolated_{id}, and will also check that there is an |
153 // origin and id present. It will not check that the origin or id are valid. | 149 // origin and id present. It will not check that the origin or id are valid. |
154 WEBKIT_STORAGE_COMMON_EXPORT bool CrackIsolatedFileSystemName( | 150 STORAGE_EXPORT bool CrackIsolatedFileSystemName( |
155 const std::string& filesystem_name, | 151 const std::string& filesystem_name, |
156 std::string* filesystem_id); | 152 std::string* filesystem_id); |
157 | 153 |
158 // Validates the given isolated file system id. | 154 // Validates the given isolated file system id. |
159 WEBKIT_STORAGE_COMMON_EXPORT bool ValidateIsolatedFileSystemId( | 155 STORAGE_EXPORT bool ValidateIsolatedFileSystemId( |
160 const std::string& filesystem_id); | 156 const std::string& filesystem_id); |
161 | 157 |
162 // Returns the root URI for an isolated filesystem for origin |origin_url| | 158 // Returns the root URI for an isolated filesystem for origin |origin_url| |
163 // and |filesystem_id|. If the |optional_root_name| is given the resulting | 159 // and |filesystem_id|. If the |optional_root_name| is given the resulting |
164 // root URI will point to the subfolder within the isolated filesystem. | 160 // root URI will point to the subfolder within the isolated filesystem. |
165 WEBKIT_STORAGE_COMMON_EXPORT std::string GetIsolatedFileSystemRootURIString( | 161 STORAGE_EXPORT std::string GetIsolatedFileSystemRootURIString( |
166 const GURL& origin_url, | 162 const GURL& origin_url, |
167 const std::string& filesystem_id, | 163 const std::string& filesystem_id, |
168 const std::string& optional_root_name); | 164 const std::string& optional_root_name); |
169 | 165 |
170 // Returns the root URI for an external filesystem for origin |origin_url| | 166 // Returns the root URI for an external filesystem for origin |origin_url| |
171 // and |mount_name|. | 167 // and |mount_name|. |
172 WEBKIT_STORAGE_COMMON_EXPORT std::string GetExternalFileSystemRootURIString( | 168 STORAGE_EXPORT std::string GetExternalFileSystemRootURIString( |
173 const GURL& origin_url, | 169 const GURL& origin_url, |
174 const std::string& mount_name); | 170 const std::string& mount_name); |
175 | 171 |
176 // Translates the net::Error to base::File::Error. | 172 // Translates the net::Error to base::File::Error. |
177 WEBKIT_STORAGE_COMMON_EXPORT base::File::Error | 173 STORAGE_EXPORT base::File::Error NetErrorToFileError(int error); |
178 NetErrorToFileError(int error); | |
179 | 174 |
180 } // namespace fileapi | 175 } // namespace storage |
181 | 176 |
182 #endif // WEBKIT_COMMON_FILEAPI_FILE_SYSTEM_UTIL_H_ | 177 #endif // WEBKIT_COMMON_FILEAPI_FILE_SYSTEM_UTIL_H_ |
OLD | NEW |