exclude GcdPrivateAPITest.AddRemove from browser_tests Dr.Memory bot
[chromium-blink-merge.git] / content / common / host_shared_bitmap_manager.h
blob08245b368b58191e5288576840db6c117ce2b84f
1 // Copyright (c) 2013 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 CONTENT_COMMON_HOST_SHARED_BITMAP_MANAGER_H_
6 #define CONTENT_COMMON_HOST_SHARED_BITMAP_MANAGER_H_
8 #include <map>
9 #include <set>
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "base/containers/hash_tables.h"
14 #include "base/hash.h"
15 #include "base/memory/ref_counted.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "base/memory/shared_memory.h"
18 #include "base/synchronization/lock.h"
19 #include "cc/resources/shared_bitmap_manager.h"
20 #include "content/common/content_export.h"
22 namespace BASE_HASH_NAMESPACE {
23 #if defined(COMPILER_GCC)
24 template <>
25 struct hash<cc::SharedBitmapId> {
26 size_t operator()(const cc::SharedBitmapId& id) const {
27 return base::Hash(reinterpret_cast<const char*>(id.name), sizeof(id.name));
30 #elif defined(COMPILER_MSVC)
31 inline std::size_t hash_value(const cc::SharedBitmapId& id) {
32 return base::Hash(reinterpret_cast<const char*>(id.name), sizeof(id.name));
34 #endif // COMPILER
35 } // namespace BASE_HASH_NAMESPACE
37 namespace content {
38 class BitmapData;
40 class CONTENT_EXPORT HostSharedBitmapManager : public cc::SharedBitmapManager {
41 public:
42 HostSharedBitmapManager();
43 virtual ~HostSharedBitmapManager();
45 static HostSharedBitmapManager* current();
47 // cc::SharedBitmapManager implementation.
48 virtual scoped_ptr<cc::SharedBitmap> AllocateSharedBitmap(
49 const gfx::Size& size) OVERRIDE;
50 virtual scoped_ptr<cc::SharedBitmap> GetSharedBitmapFromId(
51 const gfx::Size& size,
52 const cc::SharedBitmapId&) OVERRIDE;
53 virtual scoped_ptr<cc::SharedBitmap> GetBitmapForSharedMemory(
54 base::SharedMemory*) OVERRIDE;
56 void AllocateSharedBitmapForChild(
57 base::ProcessHandle process_handle,
58 size_t buffer_size,
59 const cc::SharedBitmapId& id,
60 base::SharedMemoryHandle* shared_memory_handle);
61 void ChildAllocatedSharedBitmap(size_t buffer_size,
62 const base::SharedMemoryHandle& handle,
63 base::ProcessHandle process_handle,
64 const cc::SharedBitmapId& id);
65 void ChildDeletedSharedBitmap(const cc::SharedBitmapId& id);
66 void ProcessRemoved(base::ProcessHandle process_handle);
68 size_t AllocatedBitmapCount() const { return handle_map_.size(); }
70 private:
71 void FreeSharedMemoryFromMap(cc::SharedBitmap* bitmap);
73 base::Lock lock_;
75 typedef base::hash_map<cc::SharedBitmapId, scoped_refptr<BitmapData> >
76 BitmapMap;
77 BitmapMap handle_map_;
79 typedef base::hash_map<base::ProcessHandle,
80 base::hash_set<cc::SharedBitmapId> > ProcessMap;
81 ProcessMap process_map_;
84 } // namespace content
86 #endif // CONTENT_COMMON_HOST_SHARED_BITMAP_MANAGER_H_