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. | 28 // is_cracked() returns false. |
29 // | 29 // |
30 // path() and virtual_path() usually return the same value, but they | 30 // All other accessors return empty or invalid value. |
31 // have different values if an instance is created for Isolated or External | 31 // |
32 // FileSystem URL, for which we may mount different paths from its exposed | 32 // FileSystemURL can also be created to represent a 'cracked' filesystem URL if |
33 // virtual paths. | 33 // the original URL's type/path is pointing to a mount point which can be |
34 // further resolved to a lower filesystem type/path. This type of FileSystemURL | |
35 // can only be created by a special static create method: CreateForCrackedURL. | |
36 // It is advised not to use this method directly, but to crack URLs using | |
37 // FileSystemContext::CrackURL/CrackFileSystemURL, or, in case it is clear which | |
38 // MountPoints implementation contains target path, MountPoints::CrackURL. | |
34 // | 39 // |
35 // Example: Assume a path '/media/removable' is mounted at mount name | 40 // Example: Assume a path '/media/removable' is mounted at mount name |
36 // 'mount_name' with type kFileSystemTypeFoo as an external file system. | 41 // 'mount_name' with type kFileSystemTypeFoo as an external file system. |
37 // For a URL 'filesystem:http://bar.com/external/mount_name/foo/bar': | 42 // |
43 // The original URL would look like: | |
44 // 'filesystem:http://bar.com/external/mount_name/foo/bar': | |
45 // | |
46 // CrateForCrackedURL(original_filesystem_url, | |
47 // "mount_name", | |
48 // kFileSystemTypeFoo, | |
49 // "/media/removable/foo/bar"); | |
50 // would create a FileSystemURL whose accessors return: | |
51 // | |
38 // origin() returns 'http://bar.com', | 52 // origin() returns 'http://bar.com', |
39 // type() returns the kFileSystemTypeFoo, | 53 // type() returns the kFileSystemTypeFoo, |
40 // path() returns '/media/removable/foo/bar', | 54 // path() returns '/media/removable/foo/bar', |
41 // virtual_path() returns 'mount_name/foo/bar', | 55 // is_cracked() returns false. |
56 // | |
57 // Additionally, following accessors would return valid values: | |
42 // filesystem_id() returns 'mount_name', and | 58 // filesystem_id() returns 'mount_name', and |
43 // mount_type() returns kFileSystemTypeExternal. | 59 // virtual_path() returns 'mount_name/foo/bar' (original url's path()), |
60 // mount_type() returns kFileSystemTypeExternal (original url's type()). | |
44 // | 61 // |
45 // TODO(ericu): Look into making path() [and all FileSystem API virtual | 62 // TODO(ericu): Look into making path() [and all FileSystem API virtual |
46 // paths] just an std::string, to prevent platform-specific FilePath behavior | 63 // paths] just an std::string, to prevent platform-specific FilePath behavior |
47 // from getting invoked by accident. Currently the FilePath returned here needs | 64 // 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 | 65 // special treatment, as it may contain paths that are illegal on the current |
49 // platform. To avoid problems, use VirtualPath::BaseName and | 66 // platform. To avoid problems, use VirtualPath::BaseName and |
50 // VirtualPath::GetComponents instead of the FilePath methods. | 67 // VirtualPath::GetComponents instead of the FilePath methods. |
51 class WEBKIT_STORAGE_EXPORT FileSystemURL { | 68 class WEBKIT_STORAGE_EXPORT FileSystemURL { |
52 public: | 69 public: |
53 FileSystemURL(); | 70 FileSystemURL(); |
54 explicit FileSystemURL(const GURL& filesystem_url); | 71 explicit FileSystemURL(const GURL& filesystem_url); |
kinuko
2013/01/16 04:05:18
How hard it will be if we drop this constructor or
tbarzic
2013/01/16 04:43:23
I guess we could get away with making it private t
| |
55 FileSystemURL(const GURL& origin, | 72 FileSystemURL(const GURL& origin, |
56 FileSystemType type, | 73 FileSystemType type, |
57 const FilePath& internal_path); | 74 const FilePath& internal_path); |
58 ~FileSystemURL(); | 75 ~FileSystemURL(); |
59 | 76 |
77 // Creates a cracked URL. Generally, this method should not be used directly. | |
78 // See class comment for details. | |
79 static FileSystemURL CreateForCrackedURL(const FileSystemURL& original, | |
80 const std::string& filesystem_id, | |
81 FileSystemType cracked_type, | |
82 const FilePath& cracked_path); | |
83 | |
60 // Returns true if this instance represents a valid FileSystem URL. | 84 // Returns true if this instance represents a valid FileSystem URL. |
61 bool is_valid() const { return is_valid_; } | 85 bool is_valid() const { return is_valid_; } |
62 | 86 |
87 // Returns true if this instance is created by CreateForCrackedURL. | |
88 bool is_cracked() const { return is_cracked_; } | |
89 | |
63 // Returns the origin part of this URL. See the class comment for details. | 90 // Returns the origin part of this URL. See the class comment for details. |
64 const GURL& origin() const { return origin_; } | 91 const GURL& origin() const { return origin_; } |
65 | 92 |
66 // Returns the type part of this URL. See the class comment for details. | 93 // Returns the type part of this URL. See the class comment for details. |
67 FileSystemType type() const { return type_; } | 94 FileSystemType type() const { return type_; } |
68 | 95 |
69 // Returns the path part of this URL. See the class comment for details. | 96 // Returns the path part of this URL. See the class comment for details. |
70 // TODO(kinuko): this must return std::string. | 97 // TODO(kinuko): this must return std::string. |
71 const FilePath& path() const { return path_; } | 98 const FilePath& path() const { return path_; } |
72 | 99 |
73 // Returns the original path part of this URL. | 100 // Returns the original path part of this URL. |
74 // See the class comment for details. | 101 // See the class comment for details. |
75 // TODO(kinuko): this must return std::string. | 102 // TODO(kinuko): this must return std::string. |
76 const FilePath& virtual_path() const { return virtual_path_; } | 103 const FilePath& virtual_path() const { return virtual_path_; } |
77 | 104 |
78 // Returns the filesystem ID/name for isolated/external file system URLs. | 105 // Returns the filesystem ID/mount name for isolated/external filesystem URLs. |
79 // See the class comment for details. | 106 // See the class comment for details. |
80 const std::string& filesystem_id() const { return filesystem_id_; } | 107 const std::string& filesystem_id() const { return filesystem_id_; } |
81 | 108 |
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_; } | 109 FileSystemType mount_type() const { return mount_type_; } |
85 | 110 |
86 std::string DebugString() const; | 111 std::string DebugString() const; |
87 | 112 |
88 // Returns a new FileSystemURL with the given path. | 113 // Returns a new FileSystemURL with the given path. |
89 // This creates a new FileSystemURL, copies all fields of this instance | 114 // 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 | 115 // to that one, resets the path_ to the given |path| and resets the |
91 // virtual_path to *empty*. | 116 // virtual_path to *empty*. |
92 // Note that the resulting FileSystemURL always has an empty virtual_path | 117 // Note that the resulting FileSystemURL loses original URL information |
93 // (as virtual_path is meant to represent the path that is given in the | 118 // if it was a cracked filesystem; i.e. virtual_path and mount_type will |
94 // original filesystem: URL in the current implementation). | 119 // be set to empty values. |
95 FileSystemURL WithPath(const FilePath& path) const; | 120 FileSystemURL WithPath(const FilePath& path) const; |
96 | 121 |
97 // Returns true if this URL is a strict parent of the |child|. | 122 // Returns true if this URL is a strict parent of the |child|. |
98 bool IsParent(const FileSystemURL& child) const; | 123 bool IsParent(const FileSystemURL& child) const; |
99 | 124 |
100 bool operator==(const FileSystemURL& that) const; | 125 bool operator==(const FileSystemURL& that) const; |
101 | 126 |
102 struct WEBKIT_STORAGE_EXPORT Comparator { | 127 struct WEBKIT_STORAGE_EXPORT Comparator { |
103 bool operator() (const FileSystemURL& lhs, const FileSystemURL& rhs) const; | 128 bool operator() (const FileSystemURL& lhs, const FileSystemURL& rhs) const; |
104 }; | 129 }; |
105 | 130 |
106 private: | 131 private: |
107 void MayCrackIsolatedPath(); | 132 FileSystemURL(const GURL& original, |
133 FileSystemType original_type, | |
134 const FilePath& original_path, | |
135 const std::string& filesystem_id, | |
136 FileSystemType cracked_type, | |
137 const FilePath& cracked_path); | |
138 | |
139 bool is_valid_; | |
140 bool is_cracked_; | |
108 | 141 |
109 GURL origin_; | 142 GURL origin_; |
110 FileSystemType type_; | 143 FileSystemType type_; |
111 FilePath path_; | 144 FilePath path_; |
112 | 145 |
113 // For isolated filesystem. | 146 // Values specific to cracked URLs. |
114 std::string filesystem_id_; | 147 std::string filesystem_id_; |
148 FileSystemType mount_type_; | |
115 FilePath virtual_path_; | 149 FilePath virtual_path_; |
116 FileSystemType mount_type_; | |
117 | 150 |
118 bool is_valid_; | |
119 }; | 151 }; |
120 | 152 |
121 typedef std::set<FileSystemURL, FileSystemURL::Comparator> FileSystemURLSet; | 153 typedef std::set<FileSystemURL, FileSystemURL::Comparator> FileSystemURLSet; |
122 | 154 |
123 } // namespace fileapi | 155 } // namespace fileapi |
124 | 156 |
125 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_URL_H_ | 157 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_URL_H_ |
OLD | NEW |