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

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

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

Powered by Google App Engine
This is Rietveld 408576698