| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 MOJO_EDK_SYSTEM_HANDLE_TABLE_H_ | 5 #ifndef MOJO_EDK_SYSTEM_HANDLE_TABLE_H_ |
| 6 #define MOJO_EDK_SYSTEM_HANDLE_TABLE_H_ | 6 #define MOJO_EDK_SYSTEM_HANDLE_TABLE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/containers/hash_tables.h" | 12 #include "base/containers/hash_tables.h" |
| 13 #include "base/gtest_prod_util.h" |
| 13 #include "base/macros.h" | 14 #include "base/macros.h" |
| 14 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
| 15 #include "base/trace_event/memory_dump_provider.h" | 16 #include "base/trace_event/memory_dump_provider.h" |
| 16 #include "mojo/edk/system/dispatcher.h" | 17 #include "mojo/edk/system/dispatcher.h" |
| 18 #include "mojo/edk/system/system_impl_export.h" |
| 17 #include "mojo/public/c/system/types.h" | 19 #include "mojo/public/c/system/types.h" |
| 18 | 20 |
| 19 namespace mojo { | 21 namespace mojo { |
| 20 namespace edk { | 22 namespace edk { |
| 21 | 23 |
| 22 class HandleTable : public base::trace_event::MemoryDumpProvider { | 24 class MOJO_SYSTEM_IMPL_EXPORT HandleTable |
| 25 : public base::trace_event::MemoryDumpProvider { |
| 23 public: | 26 public: |
| 24 HandleTable(); | 27 HandleTable(); |
| 25 ~HandleTable() override; | 28 ~HandleTable() override; |
| 26 | 29 |
| 27 // HandleTable is thread-hostile. All access should be gated by GetLock(). | 30 // HandleTable is thread-hostile. All access should be gated by GetLock(). |
| 28 base::Lock& GetLock(); | 31 base::Lock& GetLock(); |
| 29 | 32 |
| 30 MojoHandle AddDispatcher(scoped_refptr<Dispatcher> dispatcher); | 33 MojoHandle AddDispatcher(scoped_refptr<Dispatcher> dispatcher); |
| 31 | 34 |
| 32 // Inserts multiple dispatchers received from message transit, populating | 35 // Inserts multiple dispatchers received from message transit, populating |
| (...skipping 15 matching lines...) Expand all Loading... |
| 48 std::vector<Dispatcher::DispatcherInTransit>* dispatchers); | 51 std::vector<Dispatcher::DispatcherInTransit>* dispatchers); |
| 49 | 52 |
| 50 void CompleteTransitAndClose( | 53 void CompleteTransitAndClose( |
| 51 const std::vector<Dispatcher::DispatcherInTransit>& dispatchers); | 54 const std::vector<Dispatcher::DispatcherInTransit>& dispatchers); |
| 52 void CancelTransit( | 55 void CancelTransit( |
| 53 const std::vector<Dispatcher::DispatcherInTransit>& dispatchers); | 56 const std::vector<Dispatcher::DispatcherInTransit>& dispatchers); |
| 54 | 57 |
| 55 void GetActiveHandlesForTest(std::vector<MojoHandle> *handles); | 58 void GetActiveHandlesForTest(std::vector<MojoHandle> *handles); |
| 56 | 59 |
| 57 private: | 60 private: |
| 61 FRIEND_TEST_ALL_PREFIXES(HandleTableTest, OnMemoryDump); |
| 62 |
| 58 // MemoryDumpProvider implementation. | 63 // MemoryDumpProvider implementation. |
| 59 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, | 64 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, |
| 60 base::trace_event::ProcessMemoryDump* pmd) override; | 65 base::trace_event::ProcessMemoryDump* pmd) override; |
| 61 | 66 |
| 62 struct Entry { | 67 struct Entry { |
| 63 Entry(); | 68 Entry(); |
| 64 explicit Entry(scoped_refptr<Dispatcher> dispatcher); | 69 explicit Entry(scoped_refptr<Dispatcher> dispatcher); |
| 65 Entry(const Entry& other); | 70 Entry(const Entry& other); |
| 66 ~Entry(); | 71 ~Entry(); |
| 67 | 72 |
| 68 scoped_refptr<Dispatcher> dispatcher; | 73 scoped_refptr<Dispatcher> dispatcher; |
| 69 bool busy = false; | 74 bool busy = false; |
| 70 }; | 75 }; |
| 71 | 76 |
| 72 using HandleMap = base::hash_map<MojoHandle, Entry>; | 77 using HandleMap = base::hash_map<MojoHandle, Entry>; |
| 73 | 78 |
| 74 HandleMap handles_; | 79 HandleMap handles_; |
| 75 base::Lock lock_; | 80 base::Lock lock_; |
| 76 | 81 |
| 77 uint32_t next_available_handle_ = 1; | 82 uint32_t next_available_handle_ = 1; |
| 78 | 83 |
| 79 DISALLOW_COPY_AND_ASSIGN(HandleTable); | 84 DISALLOW_COPY_AND_ASSIGN(HandleTable); |
| 80 }; | 85 }; |
| 81 | 86 |
| 82 } // namespace edk | 87 } // namespace edk |
| 83 } // namespace mojo | 88 } // namespace mojo |
| 84 | 89 |
| 85 #endif // MOJO_EDK_SYSTEM_HANDLE_TABLE_H_ | 90 #endif // MOJO_EDK_SYSTEM_HANDLE_TABLE_H_ |
| OLD | NEW |