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

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: few nits 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) 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_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 registers a remote file system
kinuko 2013/01/10 05:47:31 nit: but registers -> but also registers
tonibarzic 2013/01/11 01:50:04 Done.
65 // 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 // Retrieves the remote file system proxy for the registered file system.
72 // Returns NULL if there is no file system with given name, or if the file
73 // system does not have a remote file system proxy.
74 RemoteFileSystemProxyInterface* GetRemoteFileSystemProxy(
75 const std::string& mount_name) const;
76
77 // Returns a list of registered MountPointInfos (of <mount_name, path>).
78 void AddMountPointInfosTo(std::vector<MountPointInfo>* mount_points) const;
79
80 // MountPoints overrides.
81 virtual bool RevokeFileSystem(const std::string& mount_name) OVERRIDE;
82 virtual bool GetRegisteredPath(const std::string& mount_name,
83 FilePath* path) const OVERRIDE;
84 virtual bool CrackVirtualPath(const FilePath& virtual_path,
85 std::string* mount_name,
86 FileSystemType* type,
87 FilePath* path) const OVERRIDE;
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 bool GetVirtualPath(const FilePath& absolute_path, FilePath* virtual_path);
95
96 // Returns the virtual root path that looks like /<mount_name>.
97 FilePath CreateVirtualRootPath(const std::string& mount_name) const;
98
99 private:
100 friend class base::RefCountedThreadSafe<ExternalMountPoints>;
101
102 // Represents each file system instance (defined in the .cc).
103 class Instance;
104
105 typedef std::map<std::string, Instance*> NameToInstance;
106
107 // Reverse map from registered path to its corresponding mount name.
108 typedef std::map<FilePath, std::string> PathToName;
109
110 // Use |GetSystemInstance| of |CreateRefCounted| to get an instance.
111 explicit ExternalMountPoints();
112 virtual ~ExternalMountPoints();
113
114 // Performs sanity checks on the new mount point.
115 // Checks following:
116 // - there is no registered mount point with mount_name
117 // - path does not reference parent
118 // - path is absolute
119 // - path does not overlap with an existing mount point path.
120 //
121 // |lock_| should be taken before calling this method.
122 bool ValidateNewMountPoint(const std::string& mount_name,
123 const FilePath& path);
124
125 // This lock needs to be obtained when accessing the instance_map_.
126 mutable base::Lock lock_;
127
128 NameToInstance instance_map_;
129 PathToName path_to_name_map_;
130
131 DISALLOW_COPY_AND_ASSIGN(ExternalMountPoints);
132 };
133
134 // Registers a scoped external filesystem which gets revoked when it scopes out.
135 class WEBKIT_STORAGE_EXPORT ScopedExternalFileSystem {
136 public:
137 ScopedExternalFileSystem(const std::string& mount_name,
138 FileSystemType type,
139 const FilePath& path);
140 ~ScopedExternalFileSystem();
141
142 FilePath GetVirtualRootPath() const;
143
144 private:
145 const std::string mount_name_;
146 };
147
148 } // namespace fileapi
149
150 #endif // WEBKIT_FILEAPI_EXTERNAL_MOUNT_POINTS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698