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

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: browser_tests compile 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. 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);
55 FileSystemURL(const GURL& origin,
56 FileSystemType type,
57 const FilePath& internal_path);
58 ~FileSystemURL(); 71 ~FileSystemURL();
59 72
73 // Methods for creating FileSystemURL without attempting to crack them.
74 // Should be used only in tests.
75 static FileSystemURL CreateForTest(const GURL& url);
76 static FileSystemURL CreateForTest(const GURL& origin,
77 FileSystemType type,
78 const FilePath& path);
79
60 // Returns true if this instance represents a valid FileSystem URL. 80 // Returns true if this instance represents a valid FileSystem URL.
61 bool is_valid() const { return is_valid_; } 81 bool is_valid() const { return is_valid_; }
62 82
83 // Returns true if this instance is created by CreateForCrackedURL.
84 bool is_cracked() const { return is_cracked_; }
85
63 // Returns the origin part of this URL. See the class comment for details. 86 // Returns the origin part of this URL. See the class comment for details.
64 const GURL& origin() const { return origin_; } 87 const GURL& origin() const { return origin_; }
65 88
66 // Returns the type part of this URL. See the class comment for details. 89 // Returns the type part of this URL. See the class comment for details.
67 FileSystemType type() const { return type_; } 90 FileSystemType type() const { return type_; }
68 91
69 // Returns the path part of this URL. See the class comment for details. 92 // Returns the path part of this URL. See the class comment for details.
70 // TODO(kinuko): this must return std::string. 93 // TODO(kinuko): this must return std::string.
71 const FilePath& path() const { return path_; } 94 const FilePath& path() const { return path_; }
72 95
73 // Returns the original path part of this URL. 96 // Returns the original path part of this URL.
74 // See the class comment for details. 97 // See the class comment for details.
75 // TODO(kinuko): this must return std::string. 98 // TODO(kinuko): this must return std::string.
76 const FilePath& virtual_path() const { return virtual_path_; } 99 const FilePath& virtual_path() const { return virtual_path_; }
77 100
78 // Returns the filesystem ID/name for isolated/external file system URLs. 101 // Returns the filesystem ID/mount name for isolated/external filesystem URLs.
79 // See the class comment for details. 102 // See the class comment for details.
80 const std::string& filesystem_id() const { return filesystem_id_; } 103 const std::string& filesystem_id() const { return filesystem_id_; }
81 104
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_; } 105 FileSystemType mount_type() const { return mount_type_; }
85 106
86 std::string DebugString() const; 107 std::string DebugString() const;
87 108
88 // Returns a new FileSystemURL with the given path. 109 // Returns a new FileSystemURL with the given path.
89 // This creates a new FileSystemURL, copies all fields of this instance 110 // 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 111 // to that one, resets the path_ to the given |path| and resets the
91 // virtual_path to *empty*. 112 // virtual_path to *empty*.
92 // Note that the resulting FileSystemURL always has an empty virtual_path 113 // Note that the resulting FileSystemURL loses original URL information
93 // (as virtual_path is meant to represent the path that is given in the 114 // if it was a cracked filesystem; i.e. virtual_path and mount_type will
94 // original filesystem: URL in the current implementation). 115 // be set to empty values.
95 FileSystemURL WithPath(const FilePath& path) const; 116 FileSystemURL WithPath(const FilePath& path) const;
96 117
97 // Returns true if this URL is a strict parent of the |child|. 118 // Returns true if this URL is a strict parent of the |child|.
98 bool IsParent(const FileSystemURL& child) const; 119 bool IsParent(const FileSystemURL& child) const;
99 120
100 bool operator==(const FileSystemURL& that) const; 121 bool operator==(const FileSystemURL& that) const;
101 122
102 struct WEBKIT_STORAGE_EXPORT Comparator { 123 struct WEBKIT_STORAGE_EXPORT Comparator {
103 bool operator() (const FileSystemURL& lhs, const FileSystemURL& rhs) const; 124 bool operator() (const FileSystemURL& lhs, const FileSystemURL& rhs) const;
104 }; 125 };
105 126
106 private: 127 private:
107 void MayCrackIsolatedPath(); 128 friend class FileSystemContext;
129 friend class ExternalMountPoints;
130 friend class IsolatedContext;
131
132 explicit FileSystemURL(const GURL& filesystem_url);
133 FileSystemURL(const GURL& origin,
134 FileSystemType type,
135 const FilePath& internal_path);
136 FileSystemURL(const GURL& original,
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 // Creates a cracked URL. Generally, this method should not be used directly.
144 // See class comment for details.
145 static FileSystemURL CreateForCrackedURL(const FileSystemURL& original,
kinuko 2013/01/18 07:33:32 nit: indent
tbarzic 2013/01/18 21:33:15 Done. (jeez, Eclipse is killing me with its auto-
146 const std::string& filesystem_id,
147 FileSystemType cracked_type,
148 const FilePath& cracked_path);
149
150 bool is_valid_;
151 bool is_cracked_;
108 152
109 GURL origin_; 153 GURL origin_;
110 FileSystemType type_; 154 FileSystemType type_;
111 FilePath path_; 155 FilePath path_;
112 156
113 // For isolated filesystem. 157 // Values specific to cracked URLs.
114 std::string filesystem_id_; 158 std::string filesystem_id_;
159 FileSystemType mount_type_;
115 FilePath virtual_path_; 160 FilePath virtual_path_;
116 FileSystemType mount_type_;
117 161
118 bool is_valid_;
119 }; 162 };
120 163
121 typedef std::set<FileSystemURL, FileSystemURL::Comparator> FileSystemURLSet; 164 typedef std::set<FileSystemURL, FileSystemURL::Comparator> FileSystemURLSet;
122 165
123 } // namespace fileapi 166 } // namespace fileapi
124 167
125 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_URL_H_ 168 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_URL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698