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

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

Issue 10536200: Manage IsolatedContext with reference counts (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: win test fix Created 8 years, 5 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 // it can properly return the original path '/a/b/foo' by looking up the 47 // it can properly return the original path '/a/b/foo' by looking up the
48 // internal mapping. Similarly if a dropped entry is a directory and its 48 // internal mapping. Similarly if a dropped entry is a directory and its
49 // path is like '/a/b/dir' a virtual path like '/<fsid>/dir/foo' can be 49 // path is like '/a/b/dir' a virtual path like '/<fsid>/dir/foo' can be
50 // cracked into '/a/b/dir/foo'. 50 // cracked into '/a/b/dir/foo'.
51 // 51 //
52 // This may return an empty string (thus invalid as an ID) if the given 52 // This may return an empty string (thus invalid as an ID) if the given
53 // file set contains non absolute paths. 53 // file set contains non absolute paths.
54 std::string RegisterIsolatedFileSystem(const std::set<FilePath>& fileset); 54 std::string RegisterIsolatedFileSystem(const std::set<FilePath>& fileset);
55 55
56 // Revokes filesystem specified by the given filesystem_id. 56 // Revokes filesystem specified by the given filesystem_id.
57 // Note that this revokes the filesystem no matter how many references it has.
58 // It is ok to call this on the filesystem that has been already deleted
59 // (if its reference count had reached 0).
57 void RevokeIsolatedFileSystem(const std::string& filesystem_id); 60 void RevokeIsolatedFileSystem(const std::string& filesystem_id);
58 61
62 // Adds a reference to a filesystem specified by the given filesystem_id.
63 void AddReference(const std::string& filesystem_id);
64
65 // Removes a reference to a filesystem specified by the given filesystem_id.
66 // If the reference count reaches 0 the isolated context gets destroyed.
67 // It is ok to call this on the filesystem that has been already deleted
68 // (e.g. by RevokeIsolatedFileSystem).
69 void RemoveReference(const std::string& filesystem_id);
70
59 // Cracks the given |virtual_path| (which should look like 71 // Cracks the given |virtual_path| (which should look like
60 // "/<filesystem_id>/<relative_path>") and populates the |filesystem_id| 72 // "/<filesystem_id>/<relative_path>") and populates the |filesystem_id|
61 // and |platform_path| if the embedded <filesystem_id> is registerred 73 // and |platform_path| if the embedded <filesystem_id> is registerred
62 // to this context. |root_path| is also populated to have the platform 74 // to this context. |root_path| is also populated to have the platform
63 // root (toplevel) path for the |virtual_path| 75 // root (toplevel) path for the |virtual_path|
64 // (i.e. |platform_path| = |root_path| + <relative_path>). 76 // (i.e. |platform_path| = |root_path| + <relative_path>).
65 // 77 //
66 // Returns false if the given virtual_path or the cracked filesystem_id 78 // Returns false if the given virtual_path or the cracked filesystem_id
67 // is not valid. 79 // is not valid.
68 // 80 //
(...skipping 26 matching lines...) Expand all
95 friend struct base::DefaultLazyInstanceTraits<IsolatedContext>; 107 friend struct base::DefaultLazyInstanceTraits<IsolatedContext>;
96 108
97 // Maps from filesystem id to a path conversion map for top-level entries. 109 // Maps from filesystem id to a path conversion map for top-level entries.
98 typedef std::map<FilePath, FilePath> PathMap; 110 typedef std::map<FilePath, FilePath> PathMap;
99 typedef std::map<std::string, PathMap> IDToPathMap; 111 typedef std::map<std::string, PathMap> IDToPathMap;
100 112
101 // Obtain an instance of this class via GetInstance(). 113 // Obtain an instance of this class via GetInstance().
102 IsolatedContext(); 114 IsolatedContext();
103 ~IsolatedContext(); 115 ~IsolatedContext();
104 116
117 // Removes the given filesystem without locking.
118 // (The caller must hold a lock)
119 void RevokeWithoutLocking(const std::string& filesystem_id);
120
105 // Returns a new filesystem_id. Called with lock. 121 // Returns a new filesystem_id. Called with lock.
106 std::string GetNewFileSystemId() const; 122 std::string GetNewFileSystemId() const;
107 123
108 // This lock needs to be obtained when accessing the toplevel_map_. 124 // This lock needs to be obtained when accessing the toplevel_map_.
109 mutable base::Lock lock_; 125 mutable base::Lock lock_;
110 126
111 // Maps the toplevel entries to the filesystem id. 127 // Maps the toplevel entries to the filesystem id.
112 IDToPathMap toplevel_map_; 128 IDToPathMap toplevel_map_;
113 129
114 // Holds a set of writable ids. 130 // Holds a set of writable ids.
115 // Isolated file systems are created read-only by default, and this set 131 // Isolated file systems are created read-only by default, and this set
116 // holds a list of exceptions. 132 // holds a list of exceptions.
117 // Detailed filesystem permission may be provided by an external 133 // Detailed filesystem permission may be provided by an external
118 // security policy manager, e.g. ChildProcessSecurityPolicy. 134 // security policy manager, e.g. ChildProcessSecurityPolicy.
119 std::set<std::string> writable_ids_; 135 std::set<std::string> writable_ids_;
120 136
137 // Reference counts. Note that an isolated filesystem is created with ref==0.
138 // and will get deleted when the ref count reaches <=0.
139 std::map<std::string, int> ref_counts_;
140
121 DISALLOW_COPY_AND_ASSIGN(IsolatedContext); 141 DISALLOW_COPY_AND_ASSIGN(IsolatedContext);
122 }; 142 };
123 143
124 } // namespace fileapi 144 } // namespace fileapi
125 145
126 #endif // WEBKIT_FILEAPI_ISOLATED_CONTEXT_H_ 146 #endif // WEBKIT_FILEAPI_ISOLATED_CONTEXT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698