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

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

Issue 15859007: Move browser-specific FileAPI code from webkit/fileapi to webkit/browser/fileapi (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: dump_file_system build fix Created 7 years, 7 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
« no previous file with comments | « webkit/fileapi/file_system_options.cc ('k') | webkit/fileapi/file_system_url.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 IsInSameFileSystem(const FileSystemURL& other) const;
126
127 bool operator==(const FileSystemURL& that) const;
128
129 struct WEBKIT_STORAGE_EXPORT Comparator {
130 bool operator() (const FileSystemURL& lhs, const FileSystemURL& rhs) const;
131 };
132
133 private:
134 friend class FileSystemContext;
135 friend class ExternalMountPoints;
136 friend class IsolatedContext;
137
138 explicit FileSystemURL(const GURL& filesystem_url);
139 FileSystemURL(const GURL& origin,
140 FileSystemType mount_type,
141 const base::FilePath& virtual_path);
142 // Creates a cracked FileSystemURL.
143 FileSystemURL(const GURL& origin,
144 FileSystemType mount_type,
145 const base::FilePath& virtual_path,
146 const std::string& mount_filesystem_id,
147 FileSystemType cracked_type,
148 const base::FilePath& cracked_path,
149 const std::string& filesystem_id);
150
151 bool is_valid_;
152
153 // Values parsed from the original URL.
154 GURL origin_;
155 FileSystemType mount_type_;
156 base::FilePath virtual_path_;
157
158 // Values obtained by cracking URLs.
159 // |mount_filesystem_id_| is retrieved from the first round of cracking,
160 // and the rest of the fields are from recursive cracking. Permission
161 // checking on the top-level mount information should be done with the former,
162 // and the low-level file operation should be implemented with the latter.
163 std::string mount_filesystem_id_;
164 FileSystemType type_;
165 base::FilePath path_;
166 std::string filesystem_id_;
167 };
168
169 typedef std::set<FileSystemURL, FileSystemURL::Comparator> FileSystemURLSet;
170
171 } // namespace fileapi
172
173 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_URL_H_
OLDNEW
« no previous file with comments | « webkit/fileapi/file_system_options.cc ('k') | webkit/fileapi/file_system_url.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698