| 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_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 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/file_path.h" | 11 #include "base/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/Source/WebKit/chromium/public/WebFileError.h" |
| 14 #include "webkit/fileapi/file_system_types.h" | 14 #include "webkit/fileapi/file_system_types.h" |
| 15 #include "webkit/fileapi/fileapi_export.h" | |
| 16 #include "webkit/quota/quota_types.h" | 15 #include "webkit/quota/quota_types.h" |
| 16 #include "webkit/storage/webkit_storage_export.h" |
| 17 | 17 |
| 18 class GURL; | 18 class GURL; |
| 19 | 19 |
| 20 namespace fileapi { | 20 namespace fileapi { |
| 21 | 21 |
| 22 extern const char kPersistentDir[]; | 22 extern const char kPersistentDir[]; |
| 23 extern const char kTemporaryDir[]; | 23 extern const char kTemporaryDir[]; |
| 24 extern const char kExternalDir[]; | 24 extern const char kExternalDir[]; |
| 25 extern const char kIsolatedDir[]; | 25 extern const char kIsolatedDir[]; |
| 26 extern const char kTestDir[]; | 26 extern const char kTestDir[]; |
| 27 | 27 |
| 28 class FILEAPI_EXPORT VirtualPath { | 28 class WEBKIT_STORAGE_EXPORT VirtualPath { |
| 29 public: | 29 public: |
| 30 // Use this instead of FilePath::BaseName when operating on virtual paths. | 30 // Use this instead of FilePath::BaseName when operating on virtual paths. |
| 31 // FilePath::BaseName will get confused by ':' on Windows when it looks like a | 31 // FilePath::BaseName will get confused by ':' on Windows when it looks like a |
| 32 // drive letter separator; this will treat it as just another character. | 32 // drive letter separator; this will treat it as just another character. |
| 33 static FilePath BaseName(const FilePath& virtual_path); | 33 static FilePath BaseName(const FilePath& virtual_path); |
| 34 | 34 |
| 35 // Likewise, use this instead of FilePath::GetComponents when operating on | 35 // Likewise, use this instead of FilePath::GetComponents when operating on |
| 36 // virtual paths. | 36 // virtual paths. |
| 37 // Note that this assumes very clean input, with no leading slash, and it will | 37 // Note that this assumes very clean input, with no leading slash, and it will |
| 38 // not evaluate '.' or '..' components. | 38 // not evaluate '.' or '..' components. |
| 39 static void GetComponents(const FilePath& path, | 39 static void GetComponents(const FilePath& path, |
| 40 std::vector<FilePath::StringType>* components); | 40 std::vector<FilePath::StringType>* components); |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 // Returns the root URI of the filesystem that can be specified by a pair of | 43 // Returns the root URI of the filesystem that can be specified by a pair of |
| 44 // |origin_url| and |type|. The returned URI can be used as a root path | 44 // |origin_url| and |type|. The returned URI can be used as a root path |
| 45 // of the filesystem (e.g. <returned_URI> + "/relative/path" will compose | 45 // of the filesystem (e.g. <returned_URI> + "/relative/path" will compose |
| 46 // a path pointing to the entry "/relative/path" in the filesystem). | 46 // a path pointing to the entry "/relative/path" in the filesystem). |
| 47 // | 47 // |
| 48 // For Isolated filesystem this returns the 'common' root part, e.g. | 48 // For Isolated filesystem this returns the 'common' root part, e.g. |
| 49 // returns URL without the filesystem ID. | 49 // returns URL without the filesystem ID. |
| 50 // | 50 // |
| 51 // |type| needs to be public type as the returned URI is given to the renderer. | 51 // |type| needs to be public type as the returned URI is given to the renderer. |
| 52 FILEAPI_EXPORT GURL GetFileSystemRootURI(const GURL& origin_url, | 52 WEBKIT_STORAGE_EXPORT GURL GetFileSystemRootURI(const GURL& origin_url, |
| 53 FileSystemType type); | 53 FileSystemType type); |
| 54 | 54 |
| 55 // Returns the name for the filesystem that is specified by a pair of | 55 // Returns the name for the filesystem that is specified by a pair of |
| 56 // |origin_url| and |type|. | 56 // |origin_url| and |type|. |
| 57 // (The name itself is neither really significant nor a formal identifier | 57 // (The name itself is neither really significant nor a formal identifier |
| 58 // but can be read as the .name field of the returned FileSystem object | 58 // but can be read as the .name field of the returned FileSystem object |
| 59 // as a user-friendly name in the javascript layer). | 59 // as a user-friendly name in the javascript layer). |
| 60 // | 60 // |
| 61 // |type| needs to be public type as the returned name is given to the renderer. | 61 // |type| needs to be public type as the returned name is given to the renderer. |
| 62 // | 62 // |
| 63 // Example: | 63 // Example: |
| 64 // The name for a TEMPORARY filesystem of "http://www.example.com:80/" | 64 // The name for a TEMPORARY filesystem of "http://www.example.com:80/" |
| 65 // should look like: "http_www.example.host_80:temporary" | 65 // should look like: "http_www.example.host_80:temporary" |
| 66 FILEAPI_EXPORT std::string GetFileSystemName(const GURL& origin_url, | 66 WEBKIT_STORAGE_EXPORT std::string GetFileSystemName(const GURL& origin_url, |
| 67 FileSystemType type); | 67 FileSystemType type); |
| 68 | 68 |
| 69 // Converts FileSystemType |type| to/from the StorageType |storage_type| that | 69 // Converts FileSystemType |type| to/from the StorageType |storage_type| that |
| 70 // is used for the unified quota system. | 70 // is used for the unified quota system. |
| 71 // (Basically this naively maps TEMPORARY storage type to TEMPORARY filesystem | 71 // (Basically this naively maps TEMPORARY storage type to TEMPORARY filesystem |
| 72 // type, PERSISTENT storage type to PERSISTENT filesystem type and vice versa.) | 72 // type, PERSISTENT storage type to PERSISTENT filesystem type and vice versa.) |
| 73 FILEAPI_EXPORT FileSystemType QuotaStorageTypeToFileSystemType( | 73 WEBKIT_STORAGE_EXPORT FileSystemType QuotaStorageTypeToFileSystemType( |
| 74 quota::StorageType storage_type); | 74 quota::StorageType storage_type); |
| 75 FILEAPI_EXPORT quota::StorageType FileSystemTypeToQuotaStorageType( | 75 WEBKIT_STORAGE_EXPORT quota::StorageType FileSystemTypeToQuotaStorageType( |
| 76 FileSystemType type); | 76 FileSystemType type); |
| 77 | 77 |
| 78 // Returns the origin identifier string for the given |url| and vice versa. | 78 // Returns the origin identifier string for the given |url| and vice versa. |
| 79 // The origin identifier string is a serialized form of a security origin | 79 // The origin identifier string is a serialized form of a security origin |
| 80 // and can be used as a path name as it contains no "/" or other possibly | 80 // and can be used as a path name as it contains no "/" or other possibly |
| 81 // unsafe characters. (See WebKit's SecurityOrigin code for more details.) | 81 // unsafe characters. (See WebKit's SecurityOrigin code for more details.) |
| 82 // | 82 // |
| 83 // Example: | 83 // Example: |
| 84 // "http://www.example.com:80/"'s identifier should look like: | 84 // "http://www.example.com:80/"'s identifier should look like: |
| 85 // "http_www.example.host_80" | 85 // "http_www.example.host_80" |
| 86 FILEAPI_EXPORT std::string GetOriginIdentifierFromURL(const GURL& url); | 86 WEBKIT_STORAGE_EXPORT std::string GetOriginIdentifierFromURL(const GURL& url); |
| 87 FILEAPI_EXPORT GURL GetOriginURLFromIdentifier( | 87 WEBKIT_STORAGE_EXPORT GURL GetOriginURLFromIdentifier( |
| 88 const std::string& origin_identifier); | 88 const std::string& origin_identifier); |
| 89 | 89 |
| 90 // Returns the string representation of the given filesystem |type|. | 90 // Returns the string representation of the given filesystem |type|. |
| 91 // Returns an empty string if the |type| is invalid. | 91 // Returns an empty string if the |type| is invalid. |
| 92 FILEAPI_EXPORT std::string GetFileSystemTypeString(FileSystemType type); | 92 WEBKIT_STORAGE_EXPORT std::string GetFileSystemTypeString(FileSystemType type); |
| 93 | 93 |
| 94 // Encodes |file_path| to a string. | 94 // Encodes |file_path| to a string. |
| 95 // Following conditions should be held: | 95 // Following conditions should be held: |
| 96 // - StringToFilePath(FilePathToString(path)) == path | 96 // - StringToFilePath(FilePathToString(path)) == path |
| 97 // - StringToFilePath(FilePathToString(path) + "/" + "SubDirectory") == | 97 // - StringToFilePath(FilePathToString(path) + "/" + "SubDirectory") == |
| 98 // path.AppendASCII("SubDirectory"); | 98 // path.AppendASCII("SubDirectory"); |
| 99 // | 99 // |
| 100 // TODO(tzik): Replace CreateFilePath and FilePathToString in | 100 // TODO(tzik): Replace CreateFilePath and FilePathToString in |
| 101 // third_party/leveldatabase/env_chromium.cc with them. | 101 // third_party/leveldatabase/env_chromium.cc with them. |
| 102 FILEAPI_EXPORT std::string FilePathToString(const FilePath& file_path); | 102 WEBKIT_STORAGE_EXPORT std::string FilePathToString(const FilePath& file_path); |
| 103 | 103 |
| 104 // Decode a file path from |file_path_string|. | 104 // Decode a file path from |file_path_string|. |
| 105 FILEAPI_EXPORT FilePath StringToFilePath(const std::string& file_path_string); | 105 WEBKIT_STORAGE_EXPORT FilePath StringToFilePath( |
| 106 const std::string& file_path_string); |
| 106 | 107 |
| 107 // File error conversion | 108 // File error conversion |
| 108 FILEAPI_EXPORT WebKit::WebFileError PlatformFileErrorToWebFileError( | 109 WEBKIT_STORAGE_EXPORT WebKit::WebFileError PlatformFileErrorToWebFileError( |
| 109 base::PlatformFileError error_code); | 110 base::PlatformFileError error_code); |
| 110 | 111 |
| 111 // Generate a file system name for the given arguments. Should only be used by | 112 // Generate a file system name for the given arguments. Should only be used by |
| 112 // platform apps. | 113 // platform apps. |
| 113 FILEAPI_EXPORT std::string GetIsolatedFileSystemName( | 114 WEBKIT_STORAGE_EXPORT std::string GetIsolatedFileSystemName( |
| 114 const GURL& origin_url, | 115 const GURL& origin_url, |
| 115 const std::string& filesystem_id); | 116 const std::string& filesystem_id); |
| 116 | 117 |
| 117 // Find the file system id from |filesystem_name|. Should only be used by | 118 // Find the file system id from |filesystem_name|. Should only be used by |
| 118 // platform apps. This function will return false if the file system name is | 119 // platform apps. This function will return false if the file system name is |
| 119 // not of the form {origin}:Isolated_{id}, and will also check that there is an | 120 // not of the form {origin}:Isolated_{id}, and will also check that there is an |
| 120 // origin and id present. It will not check that the origin or id are valid. | 121 // origin and id present. It will not check that the origin or id are valid. |
| 121 FILEAPI_EXPORT bool CrackIsolatedFileSystemName( | 122 WEBKIT_STORAGE_EXPORT bool CrackIsolatedFileSystemName( |
| 122 const std::string& filesystem_name, | 123 const std::string& filesystem_name, |
| 123 std::string* filesystem_id); | 124 std::string* filesystem_id); |
| 124 | 125 |
| 125 } // namespace fileapi | 126 } // namespace fileapi |
| 126 | 127 |
| 127 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_UTIL_H_ | 128 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_UTIL_H_ |
| OLD | NEW |