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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 // Later if the context is asked to crack a virtual path like '/<fsid>/foo' | 46 // Later if the context is asked to crack a virtual path like '/<fsid>/foo' |
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 // Adds a reference to a filesystem specified by the given filesystem_id. |
57 void RevokeIsolatedFileSystem(const std::string& filesystem_id); | 57 void AddReference(const std::string& filesystem_id); |
| 58 |
| 59 // Removes a reference to a filesystem specified by the given filesystem_id. |
| 60 // If the reference count reaches 0 the isolated context gets destroyed. |
| 61 void RemoveReference(const std::string& filesystem_id); |
58 | 62 |
59 // Cracks the given |virtual_path| (which should look like | 63 // Cracks the given |virtual_path| (which should look like |
60 // "/<filesystem_id>/<relative_path>") and populates the |filesystem_id| | 64 // "/<filesystem_id>/<relative_path>") and populates the |filesystem_id| |
61 // and |platform_path| if the embedded <filesystem_id> is registerred | 65 // and |platform_path| if the embedded <filesystem_id> is registerred |
62 // to this context. |root_path| is also populated to have the platform | 66 // to this context. |root_path| is also populated to have the platform |
63 // root (toplevel) path for the |virtual_path| | 67 // root (toplevel) path for the |virtual_path| |
64 // (i.e. |platform_path| = |root_path| + <relative_path>). | 68 // (i.e. |platform_path| = |root_path| + <relative_path>). |
65 // | 69 // |
66 // Returns false if the given virtual_path or the cracked filesystem_id | 70 // Returns false if the given virtual_path or the cracked filesystem_id |
67 // is not valid. | 71 // is not valid. |
(...skipping 27 matching lines...) Expand all Loading... |
95 friend struct base::DefaultLazyInstanceTraits<IsolatedContext>; | 99 friend struct base::DefaultLazyInstanceTraits<IsolatedContext>; |
96 | 100 |
97 // Maps from filesystem id to a path conversion map for top-level entries. | 101 // Maps from filesystem id to a path conversion map for top-level entries. |
98 typedef std::map<FilePath, FilePath> PathMap; | 102 typedef std::map<FilePath, FilePath> PathMap; |
99 typedef std::map<std::string, PathMap> IDToPathMap; | 103 typedef std::map<std::string, PathMap> IDToPathMap; |
100 | 104 |
101 // Obtain an instance of this class via GetInstance(). | 105 // Obtain an instance of this class via GetInstance(). |
102 IsolatedContext(); | 106 IsolatedContext(); |
103 ~IsolatedContext(); | 107 ~IsolatedContext(); |
104 | 108 |
| 109 // Removes the given filesystem without locking. |
| 110 // (The caller must hold a lock) |
| 111 void RevokeWithoutLocking(const std::string& filesystem_id); |
| 112 |
105 // Returns a new filesystem_id. Called with lock. | 113 // Returns a new filesystem_id. Called with lock. |
106 std::string GetNewFileSystemId() const; | 114 std::string GetNewFileSystemId() const; |
107 | 115 |
108 // This lock needs to be obtained when accessing the toplevel_map_. | 116 // This lock needs to be obtained when accessing the toplevel_map_. |
109 mutable base::Lock lock_; | 117 mutable base::Lock lock_; |
110 | 118 |
111 // Maps the toplevel entries to the filesystem id. | 119 // Maps the toplevel entries to the filesystem id. |
112 IDToPathMap toplevel_map_; | 120 IDToPathMap toplevel_map_; |
113 | 121 |
114 // Holds a set of writable ids. | 122 // Holds a set of writable ids. |
115 // Isolated file systems are created read-only by default, and this set | 123 // Isolated file systems are created read-only by default, and this set |
116 // holds a list of exceptions. | 124 // holds a list of exceptions. |
117 // Detailed filesystem permission may be provided by an external | 125 // Detailed filesystem permission may be provided by an external |
118 // security policy manager, e.g. ChildProcessSecurityPolicy. | 126 // security policy manager, e.g. ChildProcessSecurityPolicy. |
119 std::set<std::string> writable_ids_; | 127 std::set<std::string> writable_ids_; |
120 | 128 |
| 129 // Reference counts. An isolated filesystem is created with ref==0, |
| 130 // and will get deleted when the ref count reaches <=0. |
| 131 std::map<std::string, int> ref_counts_; |
| 132 |
121 DISALLOW_COPY_AND_ASSIGN(IsolatedContext); | 133 DISALLOW_COPY_AND_ASSIGN(IsolatedContext); |
122 }; | 134 }; |
123 | 135 |
124 } // namespace fileapi | 136 } // namespace fileapi |
125 | 137 |
126 #endif // WEBKIT_FILEAPI_ISOLATED_CONTEXT_H_ | 138 #endif // WEBKIT_FILEAPI_ISOLATED_CONTEXT_H_ |
OLD | NEW |