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_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/platform_file.h" | 12 #include "base/platform_file.h" |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileError.h" |
13 #include "third_party/WebKit/public/platform/WebFileSystemType.h" | 14 #include "third_party/WebKit/public/platform/WebFileSystemType.h" |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileError.h" | |
15 #include "webkit/common/fileapi/file_system_types.h" | 15 #include "webkit/common/fileapi/file_system_types.h" |
16 #include "webkit/common/quota/quota_types.h" | 16 #include "webkit/common/quota/quota_types.h" |
17 #include "webkit/common/webkit_common_export.h" | 17 #include "webkit/common/webkit_storage_common_export.h" |
18 | 18 |
19 class GURL; | 19 class GURL; |
20 | 20 |
21 namespace fileapi { | 21 namespace fileapi { |
22 | 22 |
23 WEBKIT_COMMON_EXPORT extern const char kPersistentDir[]; | 23 WEBKIT_STORAGE_COMMON_EXPORT extern const char kPersistentDir[]; |
24 WEBKIT_COMMON_EXPORT extern const char kTemporaryDir[]; | 24 WEBKIT_STORAGE_COMMON_EXPORT extern const char kTemporaryDir[]; |
25 WEBKIT_COMMON_EXPORT extern const char kExternalDir[]; | 25 WEBKIT_STORAGE_COMMON_EXPORT extern const char kExternalDir[]; |
26 WEBKIT_COMMON_EXPORT extern const char kIsolatedDir[]; | 26 WEBKIT_STORAGE_COMMON_EXPORT extern const char kIsolatedDir[]; |
27 WEBKIT_COMMON_EXPORT extern const char kTestDir[]; | 27 WEBKIT_STORAGE_COMMON_EXPORT extern const char kTestDir[]; |
28 | 28 |
29 class WEBKIT_COMMON_EXPORT VirtualPath { | 29 class WEBKIT_STORAGE_COMMON_EXPORT VirtualPath { |
30 public: | 30 public: |
31 static const base::FilePath::CharType kRoot[]; | 31 static const base::FilePath::CharType kRoot[]; |
32 static const base::FilePath::CharType kSeparator; | 32 static const base::FilePath::CharType kSeparator; |
33 | 33 |
34 // Use this instead of base::FilePath::BaseName when operating on virtual | 34 // Use this instead of base::FilePath::BaseName when operating on virtual |
35 // paths. FilePath::BaseName will get confused by ':' on Windows when it | 35 // paths. FilePath::BaseName will get confused by ':' on Windows when it |
36 // looks like a drive letter separator; this will treat it as just another | 36 // looks like a drive letter separator; this will treat it as just another |
37 // character. | 37 // character. |
38 static base::FilePath BaseName(const base::FilePath& virtual_path); | 38 static base::FilePath BaseName(const base::FilePath& virtual_path); |
39 | 39 |
(...skipping 20 matching lines...) Expand all Loading... |
60 | 60 |
61 // Returns the root URI of the filesystem that can be specified by a pair of | 61 // Returns the root URI of the filesystem that can be specified by a pair of |
62 // |origin_url| and |type|. The returned URI can be used as a root path | 62 // |origin_url| and |type|. The returned URI can be used as a root path |
63 // of the filesystem (e.g. <returned_URI> + "/relative/path" will compose | 63 // of the filesystem (e.g. <returned_URI> + "/relative/path" will compose |
64 // a path pointing to the entry "/relative/path" in the filesystem). | 64 // a path pointing to the entry "/relative/path" in the filesystem). |
65 // | 65 // |
66 // For Isolated filesystem this returns the 'common' root part, e.g. | 66 // For Isolated filesystem this returns the 'common' root part, e.g. |
67 // returns URL without the filesystem ID. | 67 // returns URL without the filesystem ID. |
68 // | 68 // |
69 // |type| needs to be public type as the returned URI is given to the renderer. | 69 // |type| needs to be public type as the returned URI is given to the renderer. |
70 WEBKIT_COMMON_EXPORT GURL GetFileSystemRootURI(const GURL& origin_url, | 70 WEBKIT_STORAGE_COMMON_EXPORT GURL GetFileSystemRootURI(const GURL& origin_url, |
71 FileSystemType type); | 71 FileSystemType type); |
72 | 72 |
73 // 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 |
74 // |origin_url| and |type|. | 74 // |origin_url| and |type|. |
75 // (The name itself is neither really significant nor a formal identifier | 75 // (The name itself is neither really significant nor a formal identifier |
76 // 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 |
77 // as a user-friendly name in the javascript layer). | 77 // as a user-friendly name in the javascript layer). |
78 // | 78 // |
79 // |type| needs to be public type as the returned name is given to the renderer. | 79 // |type| needs to be public type as the returned name is given to the renderer. |
80 // | 80 // |
81 // Example: | 81 // Example: |
82 // The name for a TEMPORARY filesystem of "http://www.example.com:80/" | 82 // The name for a TEMPORARY filesystem of "http://www.example.com:80/" |
83 // should look like: "http_www.example.host_80:temporary" | 83 // should look like: "http_www.example.host_80:temporary" |
84 WEBKIT_COMMON_EXPORT std::string GetFileSystemName(const GURL& origin_url, | 84 WEBKIT_STORAGE_COMMON_EXPORT std::string |
85 FileSystemType type); | 85 GetFileSystemName(const GURL& origin_url, FileSystemType type); |
86 | 86 |
87 // Converts FileSystemType |type| to/from the StorageType |storage_type| that | 87 // Converts FileSystemType |type| to/from the StorageType |storage_type| that |
88 // is used for the unified quota system. | 88 // is used for the unified quota system. |
89 // (Basically this naively maps TEMPORARY storage type to TEMPORARY filesystem | 89 // (Basically this naively maps TEMPORARY storage type to TEMPORARY filesystem |
90 // type, PERSISTENT storage type to PERSISTENT filesystem type and vice versa.) | 90 // type, PERSISTENT storage type to PERSISTENT filesystem type and vice versa.) |
91 WEBKIT_COMMON_EXPORT FileSystemType QuotaStorageTypeToFileSystemType( | 91 WEBKIT_STORAGE_COMMON_EXPORT FileSystemType |
92 quota::StorageType storage_type); | 92 QuotaStorageTypeToFileSystemType(quota::StorageType storage_type); |
93 WEBKIT_COMMON_EXPORT quota::StorageType FileSystemTypeToQuotaStorageType( | 93 |
94 FileSystemType type); | 94 WEBKIT_STORAGE_COMMON_EXPORT quota::StorageType |
| 95 FileSystemTypeToQuotaStorageType(FileSystemType type); |
95 | 96 |
96 // Returns the string representation of the given filesystem |type|. | 97 // Returns the string representation of the given filesystem |type|. |
97 // Returns an empty string if the |type| is invalid. | 98 // Returns an empty string if the |type| is invalid. |
98 WEBKIT_COMMON_EXPORT std::string GetFileSystemTypeString(FileSystemType type); | 99 WEBKIT_STORAGE_COMMON_EXPORT std::string |
| 100 GetFileSystemTypeString(FileSystemType type); |
99 | 101 |
100 // Sets type to FileSystemType enum that corresponds to the string name. | 102 // Sets type to FileSystemType enum that corresponds to the string name. |
101 // Returns false if the |type_string| is invalid. | 103 // Returns false if the |type_string| is invalid. |
102 WEBKIT_COMMON_EXPORT bool GetFileSystemPublicType( | 104 WEBKIT_STORAGE_COMMON_EXPORT bool GetFileSystemPublicType( |
103 std::string type_string, | 105 std::string type_string, |
104 WebKit::WebFileSystemType* type); | 106 WebKit::WebFileSystemType* type); |
105 | 107 |
106 // Encodes |file_path| to a string. | 108 // Encodes |file_path| to a string. |
107 // Following conditions should be held: | 109 // Following conditions should be held: |
108 // - StringToFilePath(FilePathToString(path)) == path | 110 // - StringToFilePath(FilePathToString(path)) == path |
109 // - StringToFilePath(FilePathToString(path) + "/" + "SubDirectory") == | 111 // - StringToFilePath(FilePathToString(path) + "/" + "SubDirectory") == |
110 // path.AppendASCII("SubDirectory"); | 112 // path.AppendASCII("SubDirectory"); |
111 // | 113 // |
112 // TODO(tzik): Replace CreateFilePath and FilePathToString in | 114 // TODO(tzik): Replace CreateFilePath and FilePathToString in |
113 // third_party/leveldatabase/env_chromium.cc with them. | 115 // third_party/leveldatabase/env_chromium.cc with them. |
114 WEBKIT_COMMON_EXPORT std::string FilePathToString( | 116 WEBKIT_STORAGE_COMMON_EXPORT std::string FilePathToString( |
115 const base::FilePath& file_path); | 117 const base::FilePath& file_path); |
116 | 118 |
117 // Decode a file path from |file_path_string|. | 119 // Decode a file path from |file_path_string|. |
118 WEBKIT_COMMON_EXPORT base::FilePath StringToFilePath( | 120 WEBKIT_STORAGE_COMMON_EXPORT base::FilePath StringToFilePath( |
119 const std::string& file_path_string); | 121 const std::string& file_path_string); |
120 | 122 |
121 // File error conversion | 123 // File error conversion |
122 WEBKIT_COMMON_EXPORT WebKit::WebFileError PlatformFileErrorToWebFileError( | 124 WEBKIT_STORAGE_COMMON_EXPORT WebKit::WebFileError |
123 base::PlatformFileError error_code); | 125 PlatformFileErrorToWebFileError(base::PlatformFileError error_code); |
124 | 126 |
125 // Generate a file system name for the given arguments. Should only be used by | 127 // Generate a file system name for the given arguments. Should only be used by |
126 // platform apps. | 128 // platform apps. |
127 WEBKIT_COMMON_EXPORT std::string GetIsolatedFileSystemName( | 129 WEBKIT_STORAGE_COMMON_EXPORT std::string GetIsolatedFileSystemName( |
128 const GURL& origin_url, | 130 const GURL& origin_url, |
129 const std::string& filesystem_id); | 131 const std::string& filesystem_id); |
130 | 132 |
131 // Find the file system id from |filesystem_name|. Should only be used by | 133 // Find the file system id from |filesystem_name|. Should only be used by |
132 // platform apps. This function will return false if the file system name is | 134 // platform apps. This function will return false if the file system name is |
133 // not of the form {origin}:Isolated_{id}, and will also check that there is an | 135 // not of the form {origin}:Isolated_{id}, and will also check that there is an |
134 // origin and id present. It will not check that the origin or id are valid. | 136 // origin and id present. It will not check that the origin or id are valid. |
135 WEBKIT_COMMON_EXPORT bool CrackIsolatedFileSystemName( | 137 WEBKIT_STORAGE_COMMON_EXPORT bool CrackIsolatedFileSystemName( |
136 const std::string& filesystem_name, | 138 const std::string& filesystem_name, |
137 std::string* filesystem_id); | 139 std::string* filesystem_id); |
138 | 140 |
139 // Returns the root URI for an isolated filesystem for origin |origin_url| | 141 // Returns the root URI for an isolated filesystem for origin |origin_url| |
140 // and |filesystem_id|. If the |optional_root_name| is given the resulting | 142 // and |filesystem_id|. If the |optional_root_name| is given the resulting |
141 // root URI will point to the subfolder within the isolated filesystem. | 143 // root URI will point to the subfolder within the isolated filesystem. |
142 WEBKIT_COMMON_EXPORT std::string GetIsolatedFileSystemRootURIString( | 144 WEBKIT_STORAGE_COMMON_EXPORT std::string GetIsolatedFileSystemRootURIString( |
143 const GURL& origin_url, | 145 const GURL& origin_url, |
144 const std::string& filesystem_id, | 146 const std::string& filesystem_id, |
145 const std::string& optional_root_name); | 147 const std::string& optional_root_name); |
146 | 148 |
147 // Returns the root URI for an external filesystem for origin |origin_url| | 149 // Returns the root URI for an external filesystem for origin |origin_url| |
148 // and |mount_name|. | 150 // and |mount_name|. |
149 WEBKIT_COMMON_EXPORT std::string GetExternalFileSystemRootURIString( | 151 WEBKIT_STORAGE_COMMON_EXPORT std::string GetExternalFileSystemRootURIString( |
150 const GURL& origin_url, | 152 const GURL& origin_url, |
151 const std::string& mount_name); | 153 const std::string& mount_name); |
152 | 154 |
153 } // namespace fileapi | 155 } // namespace fileapi |
154 | 156 |
155 #endif // WEBKIT_COMMON_FILEAPI_FILE_SYSTEM_UTIL_H_ | 157 #endif // WEBKIT_COMMON_FILEAPI_FILE_SYSTEM_UTIL_H_ |
OLD | NEW |