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

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

Issue 539143002: Migrate webkit/browser/ to storage/browser/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix android build Created 6 years, 3 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_BROWSER_FILEAPI_FILE_SYSTEM_URL_H_ 5 #include "storage/browser/fileapi/file_system_url.h"
6 #define WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_URL_H_
7
8 #include <set>
9 #include <string>
10
11 #include "base/files/file_path.h"
12 #include "url/gurl.h"
13 #include "webkit/browser/storage_browser_export.h"
14 #include "webkit/common/fileapi/file_system_mount_option.h"
15 #include "webkit/common/fileapi/file_system_types.h"
16
17 namespace storage {
18
19 // A class representing a filesystem URL which consists of origin URL,
20 // type and an internal path used inside the filesystem.
21 //
22 // When a FileSystemURL instance is created for a GURL (for filesystem: scheme),
23 // each accessor method would return following values:
24 //
25 // Example: For a URL 'filesystem:http://foo.com/temporary/foo/bar':
26 // origin() returns 'http://foo.com',
27 // mount_type() returns kFileSystemTypeTemporary,
28 // virtual_path() returns 'foo/bar',
29 // type() returns the same value as mount_type(),
30 // path() returns the same value as virtual_path(),
31 //
32 // All other accessors return empty or invalid value.
33 //
34 // FileSystemURL can also be created to represent a 'cracked' filesystem URL if
35 // the original URL's type/path is pointing to a mount point which can be
36 // further resolved to a lower filesystem type/path.
37 //
38 // Example: Assume a path '/media/removable' is mounted at mount name
39 // 'mount_name' with type kFileSystemTypeFoo as an external file system.
40 //
41 // The original URL would look like:
42 // 'filesystem:http://bar.com/external/mount_name/foo/bar':
43 //
44 // FileSystemURL('http://bar.com',
45 // kFileSystemTypeExternal,
46 // 'mount_name/foo/bar'
47 // 'mount_name',
48 // kFileSystemTypeFoo,
49 // '/media/removable/foo/bar');
50 // would create a FileSystemURL whose accessors return:
51 //
52 // origin() returns 'http://bar.com',
53 // mount_type() returns kFileSystemTypeExternal,
54 // virtual_path() returns 'mount_name/foo/bar',
55 // type() returns the kFileSystemTypeFoo,
56 // path() returns '/media/removable/foo/bar',
57 //
58 // Note that in either case virtual_path() always returns the path part after
59 // 'type' part in the original URL, and mount_type() always returns the 'type'
60 // part in the original URL.
61 //
62 // Additionally, following accessors would return valid values:
63 // filesystem_id() returns 'mount_name'.
64 //
65 // It is impossible to directly create a valid FileSystemURL instance (except by
66 // using CreatedForTest methods, which should not be used in production code).
67 // To get a valid FileSystemURL, one of the following methods can be used:
68 // <Friend>::CrackURL, <Friend>::CreateCrackedFileSystemURL, where <Friend> is
69 // one of the friended classes.
70 //
71 // TODO(ericu): Look into making virtual_path() [and all FileSystem API virtual
72 // paths] just an std::string, to prevent platform-specific base::FilePath
73 // behavior from getting invoked by accident. Currently the base::FilePath
74 // returned here needs special treatment, as it may contain paths that are
75 // illegal on the current platform.
76 // To avoid problems, use VirtualPath::BaseName and
77 // VirtualPath::GetComponents instead of the base::FilePath methods.
78 class STORAGE_EXPORT FileSystemURL {
79 public:
80 FileSystemURL();
81 ~FileSystemURL();
82
83 // Methods for creating FileSystemURL without attempting to crack them.
84 // Should be used only in tests.
85 static FileSystemURL CreateForTest(const GURL& url);
86 static FileSystemURL CreateForTest(const GURL& origin,
87 FileSystemType mount_type,
88 const base::FilePath& virtual_path);
89
90 // Returns true if this instance represents a valid FileSystem URL.
91 bool is_valid() const { return is_valid_; }
92
93 // Returns the origin part of this URL. See the class comment for details.
94 const GURL& origin() const { return origin_; }
95
96 // Returns the type part of this URL. See the class comment for details.
97 FileSystemType type() const { return type_; }
98
99 // Returns the cracked path of this URL. See the class comment for details.
100 const base::FilePath& path() const { return path_; }
101
102 // Returns the original path part of this URL.
103 // See the class comment for details.
104 // TODO(kinuko): this must return std::string.
105 const base::FilePath& virtual_path() const { return virtual_path_; }
106
107 // Returns the filesystem ID/mount name for isolated/external filesystem URLs.
108 // See the class comment for details.
109 const std::string& filesystem_id() const { return filesystem_id_; }
110 const std::string& mount_filesystem_id() const {
111 return mount_filesystem_id_;
112 }
113
114 FileSystemType mount_type() const { return mount_type_; }
115
116 const FileSystemMountOption& mount_option() const { return mount_option_; }
117
118 // Returns the formatted URL of this instance.
119 GURL ToGURL() const;
120
121 std::string DebugString() const;
122
123 // Returns true if this URL is a strict parent of the |child|.
124 bool IsParent(const FileSystemURL& child) const;
125
126 bool IsInSameFileSystem(const FileSystemURL& other) const;
127
128 bool operator==(const FileSystemURL& that) const;
129
130 bool operator!=(const FileSystemURL& that) const {
131 return !(*this == that);
132 }
133
134 struct STORAGE_EXPORT Comparator {
135 bool operator() (const FileSystemURL& lhs, const FileSystemURL& rhs) const;
136 };
137
138 private:
139 friend class FileSystemContext;
140 friend class ExternalMountPoints;
141 friend class IsolatedContext;
142
143 explicit FileSystemURL(const GURL& filesystem_url);
144 FileSystemURL(const GURL& origin,
145 FileSystemType mount_type,
146 const base::FilePath& virtual_path);
147 // Creates a cracked FileSystemURL.
148 FileSystemURL(const GURL& origin,
149 FileSystemType mount_type,
150 const base::FilePath& virtual_path,
151 const std::string& mount_filesystem_id,
152 FileSystemType cracked_type,
153 const base::FilePath& cracked_path,
154 const std::string& filesystem_id,
155 const FileSystemMountOption& mount_option);
156
157 bool is_valid_;
158
159 // Values parsed from the original URL.
160 GURL origin_;
161 FileSystemType mount_type_;
162 base::FilePath virtual_path_;
163
164 // Values obtained by cracking URLs.
165 // |mount_filesystem_id_| is retrieved from the first round of cracking,
166 // and the rest of the fields are from recursive cracking. Permission
167 // checking on the top-level mount information should be done with the former,
168 // and the low-level file operation should be implemented with the latter.
169 std::string mount_filesystem_id_;
170 FileSystemType type_;
171 base::FilePath path_;
172 std::string filesystem_id_;
173 FileSystemMountOption mount_option_;
174 };
175
176 typedef std::set<FileSystemURL, FileSystemURL::Comparator> FileSystemURLSet;
177
178 } // namespace storage
179
180 #endif // WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_URL_H_
OLDNEW
« no previous file with comments | « webkit/browser/fileapi/file_system_quota_util.h ('k') | webkit/browser/fileapi/file_system_url.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698