| 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_LEVELDB_LEVELDB_FILE_THREAD_H_ | 5 #ifndef COMPONENTS_LEVELDB_LEVELDB_FILE_THREAD_H_ |
| 6 #define COMPONENTS_LEVELDB_LEVELDB_FILE_THREAD_H_ | 6 #define COMPONENTS_LEVELDB_LEVELDB_FILE_THREAD_H_ |
| 7 | 7 |
| 8 #include <map> |
| 8 #include <string> | 9 #include <string> |
| 10 #include <utility> |
| 11 #include <vector> |
| 9 | 12 |
| 10 #include "base/files/file.h" | 13 #include "base/files/file.h" |
| 11 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 12 #include "base/synchronization/waitable_event.h" | 15 #include "base/synchronization/waitable_event.h" |
| 13 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
| 14 #include "components/filesystem/public/interfaces/directory.mojom.h" | 17 #include "components/filesystem/public/interfaces/directory.mojom.h" |
| 15 | 18 |
| 16 namespace leveldb { | 19 namespace leveldb { |
| 17 | 20 |
| 18 // The thread which services file requests from leveldb. | 21 // The thread which services file requests from leveldb. |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 | 92 |
| 90 // Unlocks a file. LevelDBFileThread takes ownership of lock. (We don't make | 93 // Unlocks a file. LevelDBFileThread takes ownership of lock. (We don't make |
| 91 // this a scoped_ptr because exporting the ctor/dtor for this struct publicly | 94 // this a scoped_ptr because exporting the ctor/dtor for this struct publicly |
| 92 // defeats the purpose of the struct.) | 95 // defeats the purpose of the struct.) |
| 93 filesystem::FileError UnlockFile(OpaqueLock* lock); | 96 filesystem::FileError UnlockFile(OpaqueLock* lock); |
| 94 | 97 |
| 95 private: | 98 private: |
| 96 friend class base::RefCountedThreadSafe<LevelDBFileThread>; | 99 friend class base::RefCountedThreadSafe<LevelDBFileThread>; |
| 97 ~LevelDBFileThread() override; | 100 ~LevelDBFileThread() override; |
| 98 | 101 |
| 102 // Called from the beginning of most impls which take an OpaqueDir. Returns |
| 103 // true if the directory was unbound between the time the task was posted and |
| 104 // the task was run on this thread. If it was, no further processing should |
| 105 // be done (and the waitable event will be Signal()ed). |
| 106 bool RegisterDirAndWaitableEvent(OpaqueDir* dir, |
| 107 base::WaitableEvent* done_event); |
| 108 |
| 109 // Cleans up internal state related to the waitable event before Signal()ing |
| 110 // it. |
| 111 void CompleteWaitableEvent(base::WaitableEvent* done_event); |
| 112 |
| 113 // Called when one of our directory or files has a connection error. This |
| 114 // will find all the outstanding waitable events that depend on it and signal |
| 115 // them. |
| 116 void OnConnectionError(); |
| 117 |
| 99 void RegisterDirectoryImpl( | 118 void RegisterDirectoryImpl( |
| 100 base::WaitableEvent* done_event, | 119 base::WaitableEvent* done_event, |
| 101 mojo::InterfacePtrInfo<filesystem::Directory> directory_info, | 120 mojo::InterfacePtrInfo<filesystem::Directory> directory_info, |
| 102 OpaqueDir** out_dir); | 121 OpaqueDir** out_dir); |
| 103 void UnregisterDirectoryImpl(base::WaitableEvent* done_event, | 122 void UnregisterDirectoryImpl(base::WaitableEvent* done_event, |
| 104 OpaqueDir* dir); | 123 OpaqueDir* dir); |
| 105 | 124 |
| 106 // Shared callback function which signals for the methods that only return an | 125 // Shared callback function which signals for the methods that only return an |
| 107 // error code. | 126 // error code. |
| 108 void OnSimpleComplete(base::WaitableEvent* done_event, | 127 void OnSimpleComplete(base::WaitableEvent* done_event, |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 base::WaitableEvent* done_event, | 229 base::WaitableEvent* done_event, |
| 211 filesystem::FileError* out_error, | 230 filesystem::FileError* out_error, |
| 212 filesystem::FileError in_error); | 231 filesystem::FileError in_error); |
| 213 | 232 |
| 214 // Overridden from base::Thread: | 233 // Overridden from base::Thread: |
| 215 void Init() override; | 234 void Init() override; |
| 216 void CleanUp() override; | 235 void CleanUp() override; |
| 217 | 236 |
| 218 int outstanding_opaque_dirs_; | 237 int outstanding_opaque_dirs_; |
| 219 | 238 |
| 239 // When our public methods are called, we create a WaitableEvent on their |
| 240 // thread so that we can block their thread on the LevelDBFileThread. We then |
| 241 // need to track what DirectoryPtrs and FilePtrs, which if they get closed, |
| 242 // should immediately trigger the waitable event. |
| 243 struct WaitableEventDependencies; |
| 244 std::map<base::WaitableEvent*, WaitableEventDependencies> |
| 245 waitable_event_dependencies_; |
| 246 |
| 220 DISALLOW_COPY_AND_ASSIGN(LevelDBFileThread); | 247 DISALLOW_COPY_AND_ASSIGN(LevelDBFileThread); |
| 221 }; | 248 }; |
| 222 | 249 |
| 223 } // namespace leveldb | 250 } // namespace leveldb |
| 224 | 251 |
| 225 #endif // COMPONENTS_LEVELDB_LEVELDB_FILE_THREAD_H_ | 252 #endif // COMPONENTS_LEVELDB_LEVELDB_FILE_THREAD_H_ |
| OLD | NEW |