mapping_table.h revision a02191e04bc25c4935f804f2c080ae28663d096d
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. 4 5#ifndef MOJO_SYSTEM_MAPPING_TABLE_H_ 6#define MOJO_SYSTEM_MAPPING_TABLE_H_ 7 8#include <stdint.h> 9 10#include <vector> 11 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/core.h" 16#include "mojo/system/system_impl_export.h" 17 18namespace mojo { 19namespace system { 20 21class Core; 22class RawSharedBufferMapping; 23 24// Test-only function (defined/used in embedder/test_embedder.cc). Declared here 25// so it can be friended. 26namespace internal { 27bool ShutdownCheckNoLeaks(Core*); 28} 29 30// This class provides the (global) table of memory mappings (owned by |Core|), 31// which maps mapping base addresses to |RawSharedBuffer::Mapping|s. 32// 33// This class is NOT thread-safe; locking is left to |Core|. 34class MOJO_SYSTEM_IMPL_EXPORT MappingTable { 35 public: 36 MappingTable(); 37 ~MappingTable(); 38 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); 43 44 private: 45 friend bool internal::ShutdownCheckNoLeaks(Core*); 46 47 typedef base::hash_map<uintptr_t, RawSharedBufferMapping*> 48 AddressToMappingMap; 49 AddressToMappingMap address_to_mapping_map_; 50 51 DISALLOW_COPY_AND_ASSIGN(MappingTable); 52}; 53 54} // namespace system 55} // namespace mojo 56 57#endif // MOJO_SYSTEM_MAPPING_TABLE_H_ 58