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