OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_FILEAPI_ISOLATED_CONTEXT_H_ | 5 #ifndef WEBKIT_FILEAPI_ISOLATED_CONTEXT_H_ |
6 #define WEBKIT_FILEAPI_ISOLATED_CONTEXT_H_ | 6 #define WEBKIT_FILEAPI_ISOLATED_CONTEXT_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 30 matching lines...) Expand all Loading... |
41 public: | 41 public: |
42 class WEBKIT_STORAGE_EXPORT FileInfoSet { | 42 class WEBKIT_STORAGE_EXPORT FileInfoSet { |
43 public: | 43 public: |
44 FileInfoSet(); | 44 FileInfoSet(); |
45 ~FileInfoSet(); | 45 ~FileInfoSet(); |
46 | 46 |
47 // Add the given |path| to the set and populates |registered_name| with | 47 // Add the given |path| to the set and populates |registered_name| with |
48 // the registered name assigned for the path. |path| needs to be | 48 // the registered name assigned for the path. |path| needs to be |
49 // absolute and should not contain parent references. | 49 // absolute and should not contain parent references. |
50 // Return false if the |path| is not valid and could not be added. | 50 // Return false if the |path| is not valid and could not be added. |
51 bool AddPath(const FilePath& path, std::string* registered_name); | 51 bool AddPath(const base::FilePath& path, std::string* registered_name); |
52 | 52 |
53 // Add the given |path| with the |name|. | 53 // Add the given |path| with the |name|. |
54 // Return false if the |name| is already registered in the set or | 54 // Return false if the |name| is already registered in the set or |
55 // is not valid and could not be added. | 55 // is not valid and could not be added. |
56 bool AddPathWithName(const FilePath& path, const std::string& name); | 56 bool AddPathWithName(const base::FilePath& path, const std::string& name); |
57 | 57 |
58 const std::set<MountPointInfo>& fileset() const { return fileset_; } | 58 const std::set<MountPointInfo>& fileset() const { return fileset_; } |
59 | 59 |
60 private: | 60 private: |
61 std::set<MountPointInfo> fileset_; | 61 std::set<MountPointInfo> fileset_; |
62 }; | 62 }; |
63 | 63 |
64 // The instance is lazily created per browser process. | 64 // The instance is lazily created per browser process. |
65 static IsolatedContext* GetInstance(); | 65 static IsolatedContext* GetInstance(); |
66 | 66 |
(...skipping 25 matching lines...) Expand all Loading... |
92 // absolute path is skipped and is not registered. | 92 // absolute path is skipped and is not registered. |
93 std::string RegisterDraggedFileSystem(const FileInfoSet& files); | 93 std::string RegisterDraggedFileSystem(const FileInfoSet& files); |
94 | 94 |
95 // Registers a new isolated filesystem for a given |path| of filesystem | 95 // Registers a new isolated filesystem for a given |path| of filesystem |
96 // |type| filesystem and returns a new filesystem ID. | 96 // |type| filesystem and returns a new filesystem ID. |
97 // |path| must be an absolute path which has no parent references ('..'). | 97 // |path| must be an absolute path which has no parent references ('..'). |
98 // If |register_name| is non-null and has non-empty string the path is | 98 // If |register_name| is non-null and has non-empty string the path is |
99 // registered as the given |register_name|, otherwise it is populated | 99 // registered as the given |register_name|, otherwise it is populated |
100 // with the name internally assigned to the path. | 100 // with the name internally assigned to the path. |
101 std::string RegisterFileSystemForPath(FileSystemType type, | 101 std::string RegisterFileSystemForPath(FileSystemType type, |
102 const FilePath& path, | 102 const base::FilePath& path, |
103 std::string* register_name); | 103 std::string* register_name); |
104 | 104 |
105 // Revokes all filesystem(s) registered for the given path. | 105 // Revokes all filesystem(s) registered for the given path. |
106 // This is assumed to be called when the registered path becomes | 106 // This is assumed to be called when the registered path becomes |
107 // globally invalid, e.g. when a device for the path is detached. | 107 // globally invalid, e.g. when a device for the path is detached. |
108 // | 108 // |
109 // Note that this revokes the filesystem no matter how many references it has. | 109 // Note that this revokes the filesystem no matter how many references it has. |
110 // It is ok to call this for the path that has no associated filesystems. | 110 // It is ok to call this for the path that has no associated filesystems. |
111 // Note that this only works for the filesystems registered by | 111 // Note that this only works for the filesystems registered by |
112 // |RegisterFileSystemForPath|. | 112 // |RegisterFileSystemForPath|. |
113 void RevokeFileSystemByPath(const FilePath& path); | 113 void RevokeFileSystemByPath(const base::FilePath& path); |
114 | 114 |
115 // Adds a reference to a filesystem specified by the given filesystem_id. | 115 // Adds a reference to a filesystem specified by the given filesystem_id. |
116 void AddReference(const std::string& filesystem_id); | 116 void AddReference(const std::string& filesystem_id); |
117 | 117 |
118 // Removes a reference to a filesystem specified by the given filesystem_id. | 118 // Removes a reference to a filesystem specified by the given filesystem_id. |
119 // If the reference count reaches 0 the isolated context gets destroyed. | 119 // If the reference count reaches 0 the isolated context gets destroyed. |
120 // It is OK to call this on the filesystem that has been already deleted | 120 // It is OK to call this on the filesystem that has been already deleted |
121 // (e.g. by RevokeFileSystemByPath). | 121 // (e.g. by RevokeFileSystemByPath). |
122 void RemoveReference(const std::string& filesystem_id); | 122 void RemoveReference(const std::string& filesystem_id); |
123 | 123 |
124 // Returns a set of dragged MountPointInfos registered for the | 124 // Returns a set of dragged MountPointInfos registered for the |
125 // |filesystem_id|. | 125 // |filesystem_id|. |
126 // The filesystem_id must be pointing to a dragged file system | 126 // The filesystem_id must be pointing to a dragged file system |
127 // (i.e. must be the one registered by RegisterDraggedFileSystem). | 127 // (i.e. must be the one registered by RegisterDraggedFileSystem). |
128 // Returns false if the |filesystem_id| is not valid. | 128 // Returns false if the |filesystem_id| is not valid. |
129 bool GetDraggedFileInfo(const std::string& filesystem_id, | 129 bool GetDraggedFileInfo(const std::string& filesystem_id, |
130 std::vector<MountPointInfo>* files) const; | 130 std::vector<MountPointInfo>* files) const; |
131 | 131 |
132 // MountPoints overrides. | 132 // MountPoints overrides. |
133 virtual bool HandlesFileSystemMountType(FileSystemType type) const OVERRIDE; | 133 virtual bool HandlesFileSystemMountType(FileSystemType type) const OVERRIDE; |
134 virtual bool RevokeFileSystem(const std::string& filesystem_id) OVERRIDE; | 134 virtual bool RevokeFileSystem(const std::string& filesystem_id) OVERRIDE; |
135 virtual bool GetRegisteredPath(const std::string& filesystem_id, | 135 virtual bool GetRegisteredPath(const std::string& filesystem_id, |
136 FilePath* path) const OVERRIDE; | 136 base::FilePath* path) const OVERRIDE; |
137 virtual bool CrackVirtualPath(const FilePath& virtual_path, | 137 virtual bool CrackVirtualPath(const base::FilePath& virtual_path, |
138 std::string* filesystem_id, | 138 std::string* filesystem_id, |
139 FileSystemType* type, | 139 FileSystemType* type, |
140 FilePath* path) const OVERRIDE; | 140 base::FilePath* path) const OVERRIDE; |
141 virtual FileSystemURL CrackURL(const GURL& url) const OVERRIDE; | 141 virtual FileSystemURL CrackURL(const GURL& url) const OVERRIDE; |
142 virtual FileSystemURL CreateCrackedFileSystemURL( | 142 virtual FileSystemURL CreateCrackedFileSystemURL( |
143 const GURL& origin, | 143 const GURL& origin, |
144 FileSystemType type, | 144 FileSystemType type, |
145 const FilePath& path) const OVERRIDE; | 145 const base::FilePath& path) const OVERRIDE; |
146 | 146 |
147 // Returns the virtual root path that looks like /<filesystem_id>. | 147 // Returns the virtual root path that looks like /<filesystem_id>. |
148 FilePath CreateVirtualRootPath(const std::string& filesystem_id) const; | 148 base::FilePath CreateVirtualRootPath(const std::string& filesystem_id) const; |
149 | 149 |
150 private: | 150 private: |
151 friend struct base::DefaultLazyInstanceTraits<IsolatedContext>; | 151 friend struct base::DefaultLazyInstanceTraits<IsolatedContext>; |
152 | 152 |
153 // Represents each file system instance (defined in the .cc). | 153 // Represents each file system instance (defined in the .cc). |
154 class Instance; | 154 class Instance; |
155 | 155 |
156 typedef std::map<std::string, Instance*> IDToInstance; | 156 typedef std::map<std::string, Instance*> IDToInstance; |
157 | 157 |
158 // Reverse map from registered path to IDs. | 158 // Reverse map from registered path to IDs. |
159 typedef std::map<FilePath, std::set<std::string> > PathToID; | 159 typedef std::map<base::FilePath, std::set<std::string> > PathToID; |
160 | 160 |
161 // Obtain an instance of this class via GetInstance(). | 161 // Obtain an instance of this class via GetInstance(). |
162 IsolatedContext(); | 162 IsolatedContext(); |
163 virtual ~IsolatedContext(); | 163 virtual ~IsolatedContext(); |
164 | 164 |
165 // Unregisters a file system of given |filesystem_id|. Must be called with | 165 // Unregisters a file system of given |filesystem_id|. Must be called with |
166 // lock_ held. Returns true if the file system is unregistered. | 166 // lock_ held. Returns true if the file system is unregistered. |
167 bool UnregisterFileSystem(const std::string& filesystem_id); | 167 bool UnregisterFileSystem(const std::string& filesystem_id); |
168 | 168 |
169 // Returns a new filesystem_id. Called with lock. | 169 // Returns a new filesystem_id. Called with lock. |
170 std::string GetNewFileSystemId() const; | 170 std::string GetNewFileSystemId() const; |
171 | 171 |
172 // This lock needs to be obtained when accessing the instance_map_. | 172 // This lock needs to be obtained when accessing the instance_map_. |
173 mutable base::Lock lock_; | 173 mutable base::Lock lock_; |
174 | 174 |
175 IDToInstance instance_map_; | 175 IDToInstance instance_map_; |
176 PathToID path_to_id_map_; | 176 PathToID path_to_id_map_; |
177 | 177 |
178 DISALLOW_COPY_AND_ASSIGN(IsolatedContext); | 178 DISALLOW_COPY_AND_ASSIGN(IsolatedContext); |
179 }; | 179 }; |
180 | 180 |
181 } // namespace fileapi | 181 } // namespace fileapi |
182 | 182 |
183 #endif // WEBKIT_FILEAPI_ISOLATED_CONTEXT_H_ | 183 #endif // WEBKIT_FILEAPI_ISOLATED_CONTEXT_H_ |
OLD | NEW |