| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef WEBKIT_FILEAPI_FILE_SYSTEM_URL_H_ | |
| 6 #define WEBKIT_FILEAPI_FILE_SYSTEM_URL_H_ | |
| 7 | |
| 8 #include <set> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/platform_file.h" | |
| 12 #include "googleurl/src/gurl.h" | |
| 13 #include "webkit/fileapi/file_system_types.h" | |
| 14 #include "webkit/storage/webkit_storage_export.h" | |
| 15 | |
| 16 namespace fileapi { | |
| 17 | |
| 18 // A class representing a filesystem URL which consists of origin URL, | |
| 19 // type and an internal path used inside the filesystem. | |
| 20 // | |
| 21 // When a FileSystemURL instance is created for a GURL (for filesystem: scheme), | |
| 22 // each accessor method would return following values: | |
| 23 // | |
| 24 // Example: For a URL 'filesystem:http://foo.com/temporary/foo/bar': | |
| 25 // origin() returns 'http://foo.com', | |
| 26 // mount_type() returns kFileSystemTypeTemporary, | |
| 27 // virtual_path() returns 'foo/bar', | |
| 28 // type() returns the same value as mount_type(), | |
| 29 // path() returns the same value as virtual_path(), | |
| 30 // | |
| 31 // All other accessors return empty or invalid value. | |
| 32 // | |
| 33 // FileSystemURL can also be created to represent a 'cracked' filesystem URL if | |
| 34 // the original URL's type/path is pointing to a mount point which can be | |
| 35 // further resolved to a lower filesystem type/path. | |
| 36 // | |
| 37 // Example: Assume a path '/media/removable' is mounted at mount name | |
| 38 // 'mount_name' with type kFileSystemTypeFoo as an external file system. | |
| 39 // | |
| 40 // The original URL would look like: | |
| 41 // 'filesystem:http://bar.com/external/mount_name/foo/bar': | |
| 42 // | |
| 43 // FileSystemURL('http://bar.com', | |
| 44 // kFileSystemTypeExternal, | |
| 45 // 'mount_name/foo/bar' | |
| 46 // 'mount_name', | |
| 47 // kFileSystemTypeFoo, | |
| 48 // '/media/removable/foo/bar'); | |
| 49 // would create a FileSystemURL whose accessors return: | |
| 50 // | |
| 51 // origin() returns 'http://bar.com', | |
| 52 // mount_type() returns kFileSystemTypeExternal, | |
| 53 // virtual_path() returns 'mount_name/foo/bar', | |
| 54 // type() returns the kFileSystemTypeFoo, | |
| 55 // path() returns '/media/removable/foo/bar', | |
| 56 // | |
| 57 // Note that in either case virtual_path() always returns the path part after | |
| 58 // 'type' part in the original URL, and mount_type() always returns the 'type' | |
| 59 // part in the original URL. | |
| 60 // | |
| 61 // Additionally, following accessors would return valid values: | |
| 62 // filesystem_id() returns 'mount_name'. | |
| 63 // | |
| 64 // It is impossible to directly create a valid FileSystemURL instance (except by | |
| 65 // using CreatedForTest methods, which should not be used in production code). | |
| 66 // To get a valid FileSystemURL, one of the following methods can be used: | |
| 67 // <Friend>::CrackURL, <Friend>::CreateCrackedFileSystemURL, where <Friend> is | |
| 68 // one of the friended classes. | |
| 69 // | |
| 70 // TODO(ericu): Look into making virtual_path() [and all FileSystem API virtual | |
| 71 // paths] just an std::string, to prevent platform-specific base::FilePath behav
ior | |
| 72 // from getting invoked by accident. Currently the base::FilePath returned here
needs | |
| 73 // special treatment, as it may contain paths that are illegal on the current | |
| 74 // platform. To avoid problems, use VirtualPath::BaseName and | |
| 75 // VirtualPath::GetComponents instead of the base::FilePath methods. | |
| 76 class WEBKIT_STORAGE_EXPORT FileSystemURL { | |
| 77 public: | |
| 78 FileSystemURL(); | |
| 79 ~FileSystemURL(); | |
| 80 | |
| 81 // Methods for creating FileSystemURL without attempting to crack them. | |
| 82 // Should be used only in tests. | |
| 83 static FileSystemURL CreateForTest(const GURL& url); | |
| 84 static FileSystemURL CreateForTest(const GURL& origin, | |
| 85 FileSystemType mount_type, | |
| 86 const base::FilePath& virtual_path); | |
| 87 | |
| 88 // Parses filesystem scheme |url| into uncracked FileSystemURL components. | |
| 89 static bool ParseFileSystemSchemeURL(const GURL& url, | |
| 90 GURL* origin, | |
| 91 FileSystemType* mount_type, | |
| 92 base::FilePath* virtual_path); | |
| 93 | |
| 94 // Returns true if this instance represents a valid FileSystem URL. | |
| 95 bool is_valid() const { return is_valid_; } | |
| 96 | |
| 97 // Returns the origin part of this URL. See the class comment for details. | |
| 98 const GURL& origin() const { return origin_; } | |
| 99 | |
| 100 // Returns the type part of this URL. See the class comment for details. | |
| 101 FileSystemType type() const { return type_; } | |
| 102 | |
| 103 // Returns the cracked path of this URL. See the class comment for details. | |
| 104 const base::FilePath& path() const { return path_; } | |
| 105 | |
| 106 // Returns the original path part of this URL. | |
| 107 // See the class comment for details. | |
| 108 // TODO(kinuko): this must return std::string. | |
| 109 const base::FilePath& virtual_path() const { return virtual_path_; } | |
| 110 | |
| 111 // Returns the filesystem ID/mount name for isolated/external filesystem URLs. | |
| 112 // See the class comment for details. | |
| 113 const std::string& filesystem_id() const { return filesystem_id_; } | |
| 114 const std::string& mount_filesystem_id() const { | |
| 115 return mount_filesystem_id_; | |
| 116 } | |
| 117 | |
| 118 FileSystemType mount_type() const { return mount_type_; } | |
| 119 | |
| 120 std::string DebugString() const; | |
| 121 | |
| 122 // Returns true if this URL is a strict parent of the |child|. | |
| 123 bool IsParent(const FileSystemURL& child) const; | |
| 124 | |
| 125 bool operator==(const FileSystemURL& that) const; | |
| 126 | |
| 127 struct WEBKIT_STORAGE_EXPORT Comparator { | |
| 128 bool operator() (const FileSystemURL& lhs, const FileSystemURL& rhs) const; | |
| 129 }; | |
| 130 | |
| 131 private: | |
| 132 friend class FileSystemContext; | |
| 133 friend class ExternalMountPoints; | |
| 134 friend class IsolatedContext; | |
| 135 | |
| 136 explicit FileSystemURL(const GURL& filesystem_url); | |
| 137 FileSystemURL(const GURL& origin, | |
| 138 FileSystemType mount_type, | |
| 139 const base::FilePath& virtual_path); | |
| 140 // Creates a cracked FileSystemURL. | |
| 141 FileSystemURL(const GURL& origin, | |
| 142 FileSystemType mount_type, | |
| 143 const base::FilePath& virtual_path, | |
| 144 const std::string& mount_filesystem_id, | |
| 145 FileSystemType cracked_type, | |
| 146 const base::FilePath& cracked_path, | |
| 147 const std::string& filesystem_id); | |
| 148 | |
| 149 bool is_valid_; | |
| 150 | |
| 151 // Values parsed from the original URL. | |
| 152 GURL origin_; | |
| 153 FileSystemType mount_type_; | |
| 154 base::FilePath virtual_path_; | |
| 155 | |
| 156 // Values obtained by cracking URLs. | |
| 157 // |mount_filesystem_id_| is retrieved from the first round of cracking, | |
| 158 // and the rest of the fields are from recursive cracking. Permission | |
| 159 // checking on the top-level mount information should be done with the former, | |
| 160 // and the low-level file operation should be implemented with the latter. | |
| 161 std::string mount_filesystem_id_; | |
| 162 FileSystemType type_; | |
| 163 base::FilePath path_; | |
| 164 std::string filesystem_id_; | |
| 165 }; | |
| 166 | |
| 167 typedef std::set<FileSystemURL, FileSystemURL::Comparator> FileSystemURLSet; | |
| 168 | |
| 169 } // namespace fileapi | |
| 170 | |
| 171 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_URL_H_ | |
| OLD | NEW |