OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 COMPONENTS_FILESYSTEM_LOCK_TABLE_H_ | 5 #ifndef COMPONENTS_FILESYSTEM_LOCK_TABLE_H_ |
6 #define COMPONENTS_FILESYSTEM_LOCK_TABLE_H_ | 6 #define COMPONENTS_FILESYSTEM_LOCK_TABLE_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/files/file.h" | 10 #include "base/files/file.h" |
| 11 #include "base/memory/ref_counted.h" |
11 | 12 |
12 namespace filesystem { | 13 namespace filesystem { |
13 | 14 |
14 class FileImpl; | 15 class FileImpl; |
15 | 16 |
16 // A table of all locks held by this process. We have one global table owned by | 17 // A table of all locks held by this process. We have one global table owned by |
17 // the app, but accessible by everything just in case two connections from the | 18 // the app, but accessible by everything just in case two connections from the |
18 // same origin try to lock the same file. | 19 // same origin try to lock the same file. |
19 class LockTable { | 20 class LockTable : public base::RefCounted<LockTable> { |
20 public: | 21 public: |
21 LockTable(); | 22 LockTable(); |
22 ~LockTable(); | |
23 | 23 |
24 // Locks a file. | 24 // Locks a file. |
25 base::File::Error LockFile(FileImpl* file); | 25 base::File::Error LockFile(FileImpl* file); |
26 | 26 |
27 // Releases a lock, if there is one. | 27 // Releases a lock, if there is one. |
28 base::File::Error UnlockFile(FileImpl* file); | 28 base::File::Error UnlockFile(FileImpl* file); |
29 | 29 |
30 // Removes a path from the list of |locked_files_|. This can be called on | 30 // Removes a path from the list of |locked_files_|. This can be called on |
31 // files that were never locked, as it is called on all file closes and | 31 // files that were never locked, as it is called on all file closes and |
32 // FileImpl destruction. | 32 // FileImpl destruction. |
33 void RemoveFromLockTable(const base::FilePath& path); | 33 void RemoveFromLockTable(const base::FilePath& path); |
34 | 34 |
35 private: | 35 private: |
| 36 friend class base::RefCounted<LockTable>; |
| 37 ~LockTable(); |
| 38 |
36 // Open, locked files. We keep track of this so we quickly error when we try | 39 // Open, locked files. We keep track of this so we quickly error when we try |
37 // to double lock a file. | 40 // to double lock a file. |
38 std::set<base::FilePath> locked_files_; | 41 std::set<base::FilePath> locked_files_; |
39 | 42 |
40 DISALLOW_COPY_AND_ASSIGN(LockTable); | 43 DISALLOW_COPY_AND_ASSIGN(LockTable); |
41 }; | 44 }; |
42 | 45 |
43 } // namespace filesystem | 46 } // namespace filesystem |
44 | 47 |
45 #endif // COMPONENTS_FILESYSTEM_LOCK_TABLE_H_ | 48 #endif // COMPONENTS_FILESYSTEM_LOCK_TABLE_H_ |
OLD | NEW |