Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(296)

Side by Side Diff: webkit/fileapi/file_system_url.h

Issue 11787028: New FileSystemURL cracking (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Couple of nits I noticed Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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. This type of FileSystemURL
34 // can only be created by a special private static method: CreateForCrackedURL.
34 // 35 //
35 // Example: Assume a path '/media/removable' is mounted at mount name 36 // Example: Assume a path '/media/removable' is mounted at mount name
36 // 'mount_name' with type kFileSystemTypeFoo as an external file system. 37 // 'mount_name' with type kFileSystemTypeFoo as an external file system.
37 // For a URL 'filesystem:http://bar.com/external/mount_name/foo/bar': 38 //
39 // The original URL would look like:
40 // 'filesystem:http://bar.com/external/mount_name/foo/bar':
41 //
42 // CrateForCrackedURL(original_filesystem_url,
43 // "mount_name",
44 // kFileSystemTypeFoo,
45 // "/media/removable/foo/bar");
46 // would create a FileSystemURL whose accessors return:
47 //
38 // origin() returns 'http://bar.com', 48 // origin() returns 'http://bar.com',
39 // type() returns the kFileSystemTypeFoo, 49 // type() returns the kFileSystemTypeFoo,
40 // path() returns '/media/removable/foo/bar', 50 // path() returns '/media/removable/foo/bar',
41 // virtual_path() returns 'mount_name/foo/bar', 51 //
52 // Additionally, following accessors would return valid values:
42 // filesystem_id() returns 'mount_name', and 53 // filesystem_id() returns 'mount_name', and
43 // mount_type() returns kFileSystemTypeExternal. 54 // virtual_path() returns 'mount_name/foo/bar' (original url's path()),
55 // mount_type() returns kFileSystemTypeExternal (original url's type()).
56 //
57 // It is imposible to directly create a valid FileSystemURL instance (except by
58 // using CreatedForTest methods, which should not be used in production code).
59 // To get a valid FileSystemURL, one of the following methods can be used:
60 // <Friend>::CrackURL, <Friend>::CreateCrackedFileSystemURL, where <Friend> is
61 // one of the friended classes.
44 // 62 //
45 // TODO(ericu): Look into making path() [and all FileSystem API virtual 63 // TODO(ericu): Look into making path() [and all FileSystem API virtual
46 // paths] just an std::string, to prevent platform-specific FilePath behavior 64 // paths] just an std::string, to prevent platform-specific FilePath behavior
47 // from getting invoked by accident. Currently the FilePath returned here needs 65 // 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 66 // special treatment, as it may contain paths that are illegal on the current
49 // platform. To avoid problems, use VirtualPath::BaseName and 67 // platform. To avoid problems, use VirtualPath::BaseName and
50 // VirtualPath::GetComponents instead of the FilePath methods. 68 // VirtualPath::GetComponents instead of the FilePath methods.
51 class WEBKIT_STORAGE_EXPORT FileSystemURL { 69 class WEBKIT_STORAGE_EXPORT FileSystemURL {
52 public: 70 public:
53 FileSystemURL(); 71 FileSystemURL();
54 explicit FileSystemURL(const GURL& filesystem_url);
55 FileSystemURL(const GURL& origin,
56 FileSystemType type,
57 const FilePath& internal_path);
58 ~FileSystemURL(); 72 ~FileSystemURL();
59 73
74 // Methods for creating FileSystemURL without attempting to crack them.
75 // Should be used only in tests.
76 static FileSystemURL CreateForTest(const GURL& url);
77 static FileSystemURL CreateForTest(const GURL& origin,
78 FileSystemType type,
79 const FilePath& path);
80
60 // Returns true if this instance represents a valid FileSystem URL. 81 // Returns true if this instance represents a valid FileSystem URL.
61 bool is_valid() const { return is_valid_; } 82 bool is_valid() const { return is_valid_; }
62 83
63 // Returns the origin part of this URL. See the class comment for details. 84 // Returns the origin part of this URL. See the class comment for details.
64 const GURL& origin() const { return origin_; } 85 const GURL& origin() const { return origin_; }
65 86
66 // Returns the type part of this URL. See the class comment for details. 87 // Returns the type part of this URL. See the class comment for details.
67 FileSystemType type() const { return type_; } 88 FileSystemType type() const { return type_; }
68 89
69 // Returns the path part of this URL. See the class comment for details. 90 // Returns the path part of this URL. See the class comment for details.
70 // TODO(kinuko): this must return std::string. 91 // TODO(kinuko): this must return std::string.
71 const FilePath& path() const { return path_; } 92 const FilePath& path() const { return path_; }
72 93
73 // Returns the original path part of this URL. 94 // Returns the original path part of this URL.
74 // See the class comment for details. 95 // See the class comment for details.
75 // TODO(kinuko): this must return std::string. 96 // TODO(kinuko): this must return std::string.
76 const FilePath& virtual_path() const { return virtual_path_; } 97 const FilePath& virtual_path() const { return virtual_path_; }
77 98
78 // Returns the filesystem ID/name for isolated/external file system URLs. 99 // Returns the filesystem ID/mount name for isolated/external filesystem URLs.
79 // See the class comment for details. 100 // See the class comment for details.
80 const std::string& filesystem_id() const { return filesystem_id_; } 101 const std::string& filesystem_id() const { return filesystem_id_; }
81 102
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_; } 103 FileSystemType mount_type() const { return mount_type_; }
85 104
86 std::string DebugString() const; 105 std::string DebugString() const;
87 106
88 // Returns a new FileSystemURL with the given path. 107 // Returns a new FileSystemURL with the given path.
89 // This creates a new FileSystemURL, copies all fields of this instance 108 // 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 109 // to that one, resets the path_ to the given |path| and resets the
91 // virtual_path to *empty*. 110 // virtual_path to *empty*.
92 // Note that the resulting FileSystemURL always has an empty virtual_path 111 // Note that the resulting FileSystemURL loses original URL information
93 // (as virtual_path is meant to represent the path that is given in the 112 // if it was a cracked filesystem; i.e. virtual_path and mount_type will
94 // original filesystem: URL in the current implementation). 113 // be set to empty values.
95 FileSystemURL WithPath(const FilePath& path) const; 114 FileSystemURL WithPath(const FilePath& path) const;
96 115
97 // Returns true if this URL is a strict parent of the |child|. 116 // Returns true if this URL is a strict parent of the |child|.
98 bool IsParent(const FileSystemURL& child) const; 117 bool IsParent(const FileSystemURL& child) const;
99 118
100 bool operator==(const FileSystemURL& that) const; 119 bool operator==(const FileSystemURL& that) const;
101 120
102 struct WEBKIT_STORAGE_EXPORT Comparator { 121 struct WEBKIT_STORAGE_EXPORT Comparator {
103 bool operator() (const FileSystemURL& lhs, const FileSystemURL& rhs) const; 122 bool operator() (const FileSystemURL& lhs, const FileSystemURL& rhs) const;
104 }; 123 };
105 124
106 private: 125 private:
107 void MayCrackIsolatedPath(); 126 friend class FileSystemContext;
127 friend class ExternalMountPoints;
128 friend class IsolatedContext;
129
130 explicit FileSystemURL(const GURL& filesystem_url);
131 FileSystemURL(const GURL& origin,
132 FileSystemType type,
133 const FilePath& internal_path);
134 FileSystemURL(const GURL& original,
135 FileSystemType original_type,
136 const FilePath& original_path,
137 const std::string& filesystem_id,
138 FileSystemType cracked_type,
139 const FilePath& cracked_path);
140
141 // Creates a cracked version of the URL |original|.
142 static FileSystemURL CreateForCrackedURL(const FileSystemURL& original,
143 const std::string& filesystem_id,
144 FileSystemType cracked_type,
145 const FilePath& cracked_path);
146
147 bool is_valid_;
108 148
109 GURL origin_; 149 GURL origin_;
110 FileSystemType type_; 150 FileSystemType type_;
111 FilePath path_; 151 FilePath path_;
112 152
113 // For isolated filesystem. 153 // Values specific to cracked URLs.
114 std::string filesystem_id_; 154 std::string filesystem_id_;
155 FileSystemType mount_type_;
115 FilePath virtual_path_; 156 FilePath virtual_path_;
116 FileSystemType mount_type_;
117 157
118 bool is_valid_;
119 }; 158 };
120 159
121 typedef std::set<FileSystemURL, FileSystemURL::Comparator> FileSystemURLSet; 160 typedef std::set<FileSystemURL, FileSystemURL::Comparator> FileSystemURLSet;
122 161
123 } // namespace fileapi 162 } // namespace fileapi
124 163
125 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_URL_H_ 164 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_URL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698