chrome.bluetoothSocket: clean-up Listen functions
[chromium-blink-merge.git] / mojo / system / mapping_table.h
blob5268234b1fe3af2f15939ab097f99d6e00c3e6c9
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
3 // found in the LICENSE file.
5 #ifndef MOJO_SYSTEM_MAPPING_TABLE_H_
6 #define MOJO_SYSTEM_MAPPING_TABLE_H_
8 #include <stdint.h>
10 #include <vector>
12 #include "base/containers/hash_tables.h"
13 #include "base/macros.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "mojo/public/c/system/types.h"
16 #include "mojo/system/system_impl_export.h"
18 namespace mojo {
19 namespace system {
21 class Core;
22 class RawSharedBufferMapping;
24 // Test-only function (defined/used in embedder/test_embedder.cc). Declared here
25 // so it can be friended.
26 namespace internal {
27 bool ShutdownCheckNoLeaks(Core*);
30 // This class provides the (global) table of memory mappings (owned by |Core|),
31 // which maps mapping base addresses to |RawSharedBuffer::Mapping|s.
33 // This class is NOT thread-safe; locking is left to |Core|.
34 class MOJO_SYSTEM_IMPL_EXPORT MappingTable {
35 public:
36 MappingTable();
37 ~MappingTable();
39 // Tries to add a mapping. (Takes ownership of the mapping in all cases; on
40 // failure, it will be destroyed.)
41 MojoResult AddMapping(scoped_ptr<RawSharedBufferMapping> mapping);
42 MojoResult RemoveMapping(void* address);
44 private:
45 friend bool internal::ShutdownCheckNoLeaks(Core*);
47 typedef base::hash_map<uintptr_t, RawSharedBufferMapping*>
48 AddressToMappingMap;
49 AddressToMappingMap address_to_mapping_map_;
51 DISALLOW_COPY_AND_ASSIGN(MappingTable);
54 } // namespace system
55 } // namespace mojo
57 #endif // MOJO_SYSTEM_MAPPING_TABLE_H_