| 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_MAPPING_TABLE_H_ | 5 #ifndef MOJO_EDK_SYSTEM_MAPPING_TABLE_H_ |
| 6 #define MOJO_EDK_SYSTEM_MAPPING_TABLE_H_ | 6 #define MOJO_EDK_SYSTEM_MAPPING_TABLE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <unordered_map> | 11 #include <unordered_map> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "mojo/edk/system/system_impl_export.h" | |
| 15 #include "mojo/public/c/system/types.h" | 14 #include "mojo/public/c/system/types.h" |
| 16 #include "mojo/public/cpp/system/macros.h" | 15 #include "mojo/public/cpp/system/macros.h" |
| 17 | 16 |
| 18 namespace mojo { | 17 namespace mojo { |
| 19 | 18 |
| 20 namespace embedder { | 19 namespace embedder { |
| 21 class PlatformSharedBufferMapping; | 20 class PlatformSharedBufferMapping; |
| 22 } | 21 } |
| 23 | 22 |
| 24 namespace system { | 23 namespace system { |
| 25 | 24 |
| 26 class Core; | 25 class Core; |
| 27 | 26 |
| 28 // Test-only function (defined/used in embedder/test_embedder.cc). Declared here | 27 // Test-only function (defined/used in embedder/test_embedder.cc). Declared here |
| 29 // so it can be friended. | 28 // so it can be friended. |
| 30 namespace internal { | 29 namespace internal { |
| 31 bool ShutdownCheckNoLeaks(Core*); | 30 bool ShutdownCheckNoLeaks(Core*); |
| 32 } | 31 } |
| 33 | 32 |
| 34 // This class provides the (global) table of memory mappings (owned by |Core|), | 33 // This class provides the (global) table of memory mappings (owned by |Core|), |
| 35 // which maps mapping base addresses to |PlatformSharedBufferMapping|s. | 34 // which maps mapping base addresses to |PlatformSharedBufferMapping|s. |
| 36 // | 35 // |
| 37 // This class is NOT thread-safe; locking is left to |Core|. | 36 // This class is NOT thread-safe; locking is left to |Core|. |
| 38 class MOJO_SYSTEM_IMPL_EXPORT MappingTable { | 37 class MappingTable { |
| 39 public: | 38 public: |
| 40 MappingTable(); | 39 MappingTable(); |
| 41 ~MappingTable(); | 40 ~MappingTable(); |
| 42 | 41 |
| 43 // Tries to add a mapping. (Takes ownership of the mapping in all cases; on | 42 // Tries to add a mapping. (Takes ownership of the mapping in all cases; on |
| 44 // failure, it will be destroyed.) | 43 // failure, it will be destroyed.) |
| 45 MojoResult AddMapping( | 44 MojoResult AddMapping( |
| 46 std::unique_ptr<embedder::PlatformSharedBufferMapping> mapping); | 45 std::unique_ptr<embedder::PlatformSharedBufferMapping> mapping); |
| 47 MojoResult RemoveMapping(uintptr_t address); | 46 MojoResult RemoveMapping(uintptr_t address); |
| 48 | 47 |
| 49 private: | 48 private: |
| 50 friend bool internal::ShutdownCheckNoLeaks(Core*); | 49 friend bool internal::ShutdownCheckNoLeaks(Core*); |
| 51 | 50 |
| 52 // TODO(vtl): Should the value type be |std::unique_ptr|? | 51 // TODO(vtl): Should the value type be |std::unique_ptr|? |
| 53 using AddressToMappingMap = | 52 using AddressToMappingMap = |
| 54 std::unordered_map<uintptr_t, embedder::PlatformSharedBufferMapping*>; | 53 std::unordered_map<uintptr_t, embedder::PlatformSharedBufferMapping*>; |
| 55 AddressToMappingMap address_to_mapping_map_; | 54 AddressToMappingMap address_to_mapping_map_; |
| 56 | 55 |
| 57 MOJO_DISALLOW_COPY_AND_ASSIGN(MappingTable); | 56 MOJO_DISALLOW_COPY_AND_ASSIGN(MappingTable); |
| 58 }; | 57 }; |
| 59 | 58 |
| 60 } // namespace system | 59 } // namespace system |
| 61 } // namespace mojo | 60 } // namespace mojo |
| 62 | 61 |
| 63 #endif // MOJO_EDK_SYSTEM_MAPPING_TABLE_H_ | 62 #endif // MOJO_EDK_SYSTEM_MAPPING_TABLE_H_ |
| OLD | NEW |