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

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

Issue 15994002: Move more browser-specific webkit/fileapi code to webkit/browser/fileapi (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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
OLDNEW
(Empty)
1 // Copyright (c) 2013 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_EXTERNAL_MOUNT_POINTS_H_
6 #define WEBKIT_FILEAPI_EXTERNAL_MOUNT_POINTS_H_
7
8 #include <map>
9 #include <string>
10 #include <vector>
11
12 #include "base/memory/ref_counted.h"
13 #include "base/synchronization/lock.h"
14 #include "webkit/fileapi/file_system_types.h"
15 #include "webkit/fileapi/mount_points.h"
16 #include "webkit/storage/webkit_storage_export.h"
17
18 namespace base {
19 class FilePath;
20 }
21
22 namespace fileapi {
23 class FileSystemURL;
24 class RemoteFileSystemProxyInterface;
25 }
26
27 namespace fileapi {
28
29 // Manages external filesystem namespaces that are identified by 'mount name'
30 // and are persisted until RevokeFileSystem is called.
31 // Files in an external filesystem are identified by a filesystem URL like:
32 //
33 // filesystem:<origin>/external/<mount_name>/relative/path
34 //
35 class WEBKIT_STORAGE_EXPORT ExternalMountPoints
36 : public base::RefCountedThreadSafe<ExternalMountPoints>,
37 public MountPoints {
38 public:
39 static ExternalMountPoints* GetSystemInstance();
40 static scoped_refptr<ExternalMountPoints> CreateRefCounted();
41
42 // Registers a new named external filesystem.
43 // The |path| is registered as the root path of the mount point which
44 // is identified by a URL "filesystem:.../external/mount_name".
45 //
46 // For example, if the path "/media/removable" is registered with
47 // the mount_name "removable", a filesystem URL like
48 // "filesystem:.../external/removable/a/b" will be resolved as
49 // "/media/removable/a/b".
50 //
51 // The |mount_name| should NOT contain a path separator '/'.
52 // Returns false if the given name is already registered.
53 //
54 // Overlapping mount points in a single MountPoints instance are not allowed.
55 // Adding mount point whose path overlaps with an existing mount point will
56 // fail.
57 //
58 // If not empty, |path| must be absolute. It is allowed for the path to be
59 // empty, but |GetVirtualPath| will not work for those mount points.
60 //
61 // An external file system registered by this method can be revoked
62 // by calling RevokeFileSystem with |mount_name|.
63 bool RegisterFileSystem(const std::string& mount_name,
64 FileSystemType type,
65 const base::FilePath& path);
66
67 // Same as |RegisterExternalFileSystem|, but also registers a remote file
68 // system proxy for the file system.
69 bool RegisterRemoteFileSystem(const std::string& mount_name,
70 FileSystemType type,
71 RemoteFileSystemProxyInterface* remote_proxy,
72 const base::FilePath& path);
73
74 // MountPoints overrides.
75 virtual bool HandlesFileSystemMountType(FileSystemType type) const OVERRIDE;
76 virtual bool RevokeFileSystem(const std::string& mount_name) OVERRIDE;
77 virtual bool GetRegisteredPath(const std::string& mount_name,
78 base::FilePath* path) const OVERRIDE;
79 virtual bool CrackVirtualPath(const base::FilePath& virtual_path,
80 std::string* mount_name,
81 FileSystemType* type,
82 base::FilePath* path) const OVERRIDE;
83 virtual FileSystemURL CrackURL(const GURL& url) const OVERRIDE;
84 virtual FileSystemURL CreateCrackedFileSystemURL(
85 const GURL& origin,
86 FileSystemType type,
87 const base::FilePath& path) const OVERRIDE;
88
89 // Retrieves the remote file system proxy for the registered file system.
90 // Returns NULL if there is no file system with the given name, or if the file
91 // system does not have a remote file system proxy.
92 RemoteFileSystemProxyInterface* GetRemoteFileSystemProxy(
93 const std::string& mount_name) const;
94
95 // Returns a list of registered MountPointInfos (of <mount_name, path>).
96 void AddMountPointInfosTo(std::vector<MountPointInfo>* mount_points) const;
97
98 // Converts a path on a registered file system to virtual path relative to the
99 // file system root. E.g. if 'Downloads' file system is mapped to
100 // '/usr/local/home/Downloads', and |absolute| path is set to
101 // '/usr/local/home/Downloads/foo', the method will set |virtual_path| to
102 // 'Downloads/foo'.
103 // Returns false if the path cannot be resolved (e.g. if the path is not
104 // part of any registered filesystem).
105 //
106 // Returned virtual_path will have normalized path separators.
107 bool GetVirtualPath(const base::FilePath& absolute_path,
108 base::FilePath* virtual_path) const;
109
110 // Returns the virtual root path that looks like /<mount_name>.
111 base::FilePath CreateVirtualRootPath(const std::string& mount_name) const;
112
113 private:
114 friend class base::RefCountedThreadSafe<ExternalMountPoints>;
115
116 // Represents each file system instance (defined in the .cc).
117 class Instance;
118
119 typedef std::map<std::string, Instance*> NameToInstance;
120
121 // Reverse map from registered path to its corresponding mount name.
122 typedef std::map<base::FilePath, std::string> PathToName;
123
124 // Use |GetSystemInstance| of |CreateRefCounted| to get an instance.
125 ExternalMountPoints();
126 virtual ~ExternalMountPoints();
127
128 // MountPoint overrides.
129 virtual FileSystemURL CrackFileSystemURL(
130 const FileSystemURL& url) const OVERRIDE;
131
132 // Performs sanity checks on the new mount point.
133 // Checks the following:
134 // - there is no registered mount point with mount_name
135 // - path does not contain a reference to a parent
136 // - path is absolute
137 // - path does not overlap with an existing mount point path.
138 //
139 // |lock_| should be taken before calling this method.
140 bool ValidateNewMountPoint(const std::string& mount_name,
141 const base::FilePath& path);
142
143 // This lock needs to be obtained when accessing the instance_map_.
144 mutable base::Lock lock_;
145
146 NameToInstance instance_map_;
147 PathToName path_to_name_map_;
148
149 DISALLOW_COPY_AND_ASSIGN(ExternalMountPoints);
150 };
151
152 // Registers a scoped external filesystem which gets revoked when it scopes out.
153 class WEBKIT_STORAGE_EXPORT ScopedExternalFileSystem {
154 public:
155 ScopedExternalFileSystem(const std::string& mount_name,
156 FileSystemType type,
157 const base::FilePath& path);
158 ~ScopedExternalFileSystem();
159
160 base::FilePath GetVirtualRootPath() const;
161
162 private:
163 const std::string mount_name_;
164 };
165
166 } // namespace fileapi
167
168 #endif // WEBKIT_FILEAPI_EXTERNAL_MOUNT_POINTS_H_
169
OLDNEW
« no previous file with comments | « webkit/chromeos/fileapi/cros_mount_point_provider_unittest.cc ('k') | webkit/fileapi/external_mount_points.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698