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

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

Issue 10829136: Adding RevokeFileSystemByPath (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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
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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 // Registers a new isolated filesystem for a given |path| of filesystem 94 // Registers a new isolated filesystem for a given |path| of filesystem
95 // |type| filesystem and returns a new filesystem ID. 95 // |type| filesystem and returns a new filesystem ID.
96 // |path| must be an absolute path which has no parent references ('..'). 96 // |path| must be an absolute path which has no parent references ('..').
97 // If |register_name| is non-null and has non-empty string the path is 97 // If |register_name| is non-null and has non-empty string the path is
98 // registered as the given |register_name|, otherwise it is populated 98 // registered as the given |register_name|, otherwise it is populated
99 // with the name internally assigned to the path. 99 // with the name internally assigned to the path.
100 std::string RegisterFileSystemForPath(FileSystemType type, 100 std::string RegisterFileSystemForPath(FileSystemType type,
101 const FilePath& path, 101 const FilePath& path,
102 std::string* register_name); 102 std::string* register_name);
103 103
104 // Revokes filesystem specified by the given filesystem_id. 104 // Revokes all filesystem(s) registerred for the given path.
kmadhusu 2012/08/02 20:07:03 nit: typo "registered"
kinuko 2012/08/02 20:36:22 Done.
105 // This is assumed to be called when the registerred path becomes
106 // globally invalid, e.g. when a device for the path is detached.
107 //
105 // Note that this revokes the filesystem no matter how many references it has. 108 // Note that this revokes the filesystem no matter how many references it has.
106 // It is ok to call this on the filesystem that has been already deleted 109 // It is ok to call this for the path that has no associated filesystems.
107 // (if its reference count had reached 0). 110 // Note that this only works for the filesystems registered by
108 void RevokeFileSystem(const std::string& filesystem_id); 111 // |RegisterFileSystemForPath|.
112 void RevokeFileSystemByPath(const FilePath& path);
109 113
110 // Adds a reference to a filesystem specified by the given filesystem_id. 114 // Adds a reference to a filesystem specified by the given filesystem_id.
111 void AddReference(const std::string& filesystem_id); 115 void AddReference(const std::string& filesystem_id);
112 116
113 // Removes a reference to a filesystem specified by the given filesystem_id. 117 // Removes a reference to a filesystem specified by the given filesystem_id.
114 // If the reference count reaches 0 the isolated context gets destroyed. 118 // If the reference count reaches 0 the isolated context gets destroyed.
115 // It is ok to call this on the filesystem that has been already deleted 119 // It is ok to call this on the filesystem that has been already deleted
116 // (e.g. by RevokeFileSystem). 120 // (e.g. by RevokeFileSystemByPath).
117 void RemoveReference(const std::string& filesystem_id); 121 void RemoveReference(const std::string& filesystem_id);
118 122
119 // Cracks the given |virtual_path| (which should look like 123 // Cracks the given |virtual_path| (which should look like
120 // "/<filesystem_id>/<registered_name>/<relative_path>") and populates 124 // "/<filesystem_id>/<registered_name>/<relative_path>") and populates
121 // the |filesystem_id| and |path| if the embedded <filesystem_id> 125 // the |filesystem_id| and |path| if the embedded <filesystem_id>
122 // is registerred to this context. |root_path| is also populated to have 126 // is registerred to this context. |root_path| is also populated to have
123 // the registered root (toplevel) file info for the |virtual_path|. 127 // the registered root (toplevel) file info for the |virtual_path|.
124 // 128 //
125 // Returns false if the given virtual_path or the cracked filesystem_id 129 // Returns false if the given virtual_path or the cracked filesystem_id
126 // is not valid. 130 // is not valid.
(...skipping 22 matching lines...) Expand all
149 // Returns the virtual root path that looks like /<filesystem_id>. 153 // Returns the virtual root path that looks like /<filesystem_id>.
150 FilePath CreateVirtualRootPath(const std::string& filesystem_id) const; 154 FilePath CreateVirtualRootPath(const std::string& filesystem_id) const;
151 155
152 private: 156 private:
153 friend struct base::DefaultLazyInstanceTraits<IsolatedContext>; 157 friend struct base::DefaultLazyInstanceTraits<IsolatedContext>;
154 158
155 // Represents each isolated file system instance. 159 // Represents each isolated file system instance.
156 class Instance { 160 class Instance {
157 public: 161 public:
158 Instance(FileSystemType type, const FileInfo& file_info); 162 Instance(FileSystemType type, const FileInfo& file_info);
159 explicit Instance(const std::set<FileInfo>& dragged_files); 163 explicit Instance(FileSystemType type, const std::set<FileInfo>& files);
160 ~Instance(); 164 ~Instance();
161 165
162 FileSystemType type() const { return type_; } 166 FileSystemType type() const { return type_; }
163 const FileInfo& file_info() const { return file_info_; } 167 const FileInfo& file_info() const { return file_info_; }
164 const std::set<FileInfo>& dragged_files() const { return dragged_files_; } 168 const std::set<FileInfo>& files() const { return files_; }
165 int ref_counts() const { return ref_counts_; } 169 int ref_counts() const { return ref_counts_; }
166 170
167 void AddRef() { ++ref_counts_; } 171 void AddRef() { ++ref_counts_; }
168 void RemoveRef() { --ref_counts_; } 172 void RemoveRef() { --ref_counts_; }
169 173
170 bool ResolvePathForName(const std::string& name, FilePath* path); 174 bool ResolvePathForName(const std::string& name, FilePath* path) const;
175
176 bool IsSinglePathInstance() const {
177 return instance_type_ == kSinglePathInstance;
178 }
171 179
172 private: 180 private:
181 enum InstanceType {
182 kSinglePathInstance,
183 kMultiplePathInstance,
kmadhusu 2012/08/02 20:03:59 nit: Can you please more comments on when we will
kinuko 2012/08/02 20:36:22 I removed this type but instead added IsSinglePath
184 };
185
173 const FileSystemType type_; 186 const FileSystemType type_;
187 const InstanceType instance_type_;
188
189 // For single-path instance.
174 const FileInfo file_info_; 190 const FileInfo file_info_;
175 191
176 // For dragged file system. 192 // For multiple-path instance (e.g. dragged file system).
177 const std::set<FileInfo> dragged_files_; 193 const std::set<FileInfo> files_;
178 194
179 // Reference counts. Note that an isolated filesystem is created with ref==0 195 // Reference counts. Note that an isolated filesystem is created with ref==0
180 // and will get deleted when the ref count reaches <=0. 196 // and will get deleted when the ref count reaches <=0.
181 int ref_counts_; 197 int ref_counts_;
182 198
183 DISALLOW_COPY_AND_ASSIGN(Instance); 199 DISALLOW_COPY_AND_ASSIGN(Instance);
184 }; 200 };
185 201
186 typedef std::map<std::string, Instance*> IDToInstance; 202 typedef std::map<std::string, Instance*> IDToInstance;
187 203
204 // Reverse map from registerred path to IDs.
205 typedef std::map<FilePath, std::set<std::string> > PathToID;
206
188 // Obtain an instance of this class via GetInstance(). 207 // Obtain an instance of this class via GetInstance().
189 IsolatedContext(); 208 IsolatedContext();
190 ~IsolatedContext(); 209 ~IsolatedContext();
191 210
192 // Returns a new filesystem_id. Called with lock. 211 // Returns a new filesystem_id. Called with lock.
193 std::string GetNewFileSystemId() const; 212 std::string GetNewFileSystemId() const;
194 213
195 // This lock needs to be obtained when accessing the instance_map_. 214 // This lock needs to be obtained when accessing the instance_map_.
196 mutable base::Lock lock_; 215 mutable base::Lock lock_;
197 216
198 IDToInstance instance_map_; 217 IDToInstance instance_map_;
218 PathToID path_to_id_map_;
199 219
200 DISALLOW_COPY_AND_ASSIGN(IsolatedContext); 220 DISALLOW_COPY_AND_ASSIGN(IsolatedContext);
201 }; 221 };
202 222
203 } // namespace fileapi 223 } // namespace fileapi
204 224
205 #endif // WEBKIT_FILEAPI_ISOLATED_CONTEXT_H_ 225 #endif // WEBKIT_FILEAPI_ISOLATED_CONTEXT_H_
OLDNEW
« no previous file with comments | « chrome/browser/media_gallery/media_file_system_registry.cc ('k') | webkit/fileapi/isolated_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698