Android: Store language .pak files in res/raw rather than assets
[chromium-blink-merge.git] / content / common / host_shared_bitmap_manager.h
blobab846fb668fe243bb25c0c55bc7768dff4a310c1
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/containers/hash_tables.h"
13 #include "base/hash.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/shared_memory.h"
17 #include "base/synchronization/lock.h"
18 #include "base/trace_event/memory_dump_provider.h"
19 #include "cc/resources/shared_bitmap_manager.h"
20 #include "content/common/content_export.h"
22 namespace BASE_HASH_NAMESPACE {
23 template <>
24 struct hash<cc::SharedBitmapId> {
25 size_t operator()(const cc::SharedBitmapId& id) const {
26 return base::Hash(reinterpret_cast<const char*>(id.name), sizeof(id.name));
29 } // namespace BASE_HASH_NAMESPACE
31 namespace content {
32 class BitmapData;
33 class HostSharedBitmapManager;
35 class CONTENT_EXPORT HostSharedBitmapManagerClient {
36 public:
37 explicit HostSharedBitmapManagerClient(HostSharedBitmapManager* manager);
39 ~HostSharedBitmapManagerClient();
41 void AllocateSharedBitmapForChild(
42 base::ProcessHandle process_handle,
43 size_t buffer_size,
44 const cc::SharedBitmapId& id,
45 base::SharedMemoryHandle* shared_memory_handle);
46 void ChildAllocatedSharedBitmap(size_t buffer_size,
47 const base::SharedMemoryHandle& handle,
48 base::ProcessHandle process_handle,
49 const cc::SharedBitmapId& id);
50 void ChildDeletedSharedBitmap(const cc::SharedBitmapId& id);
52 private:
53 HostSharedBitmapManager* manager_;
54 base::hash_set<cc::SharedBitmapId> owned_bitmaps_;
56 DISALLOW_COPY_AND_ASSIGN(HostSharedBitmapManagerClient);
59 class CONTENT_EXPORT HostSharedBitmapManager
60 : public cc::SharedBitmapManager,
61 public base::trace_event::MemoryDumpProvider {
62 public:
63 HostSharedBitmapManager();
64 ~HostSharedBitmapManager() override;
66 static HostSharedBitmapManager* current();
68 // cc::SharedBitmapManager implementation.
69 scoped_ptr<cc::SharedBitmap> AllocateSharedBitmap(
70 const gfx::Size& size) override;
71 scoped_ptr<cc::SharedBitmap> GetSharedBitmapFromId(
72 const gfx::Size& size,
73 const cc::SharedBitmapId&) override;
75 // base::trace_event::MemoryDumpProvider implementation.
76 bool OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd) override;
78 size_t AllocatedBitmapCount() const;
80 void FreeSharedMemoryFromMap(const cc::SharedBitmapId& id);
82 private:
83 friend class HostSharedBitmapManagerClient;
85 void AllocateSharedBitmapForChild(
86 base::ProcessHandle process_handle,
87 size_t buffer_size,
88 const cc::SharedBitmapId& id,
89 base::SharedMemoryHandle* shared_memory_handle);
90 void ChildAllocatedSharedBitmap(size_t buffer_size,
91 const base::SharedMemoryHandle& handle,
92 base::ProcessHandle process_handle,
93 const cc::SharedBitmapId& id);
94 void ChildDeletedSharedBitmap(const cc::SharedBitmapId& id);
96 mutable base::Lock lock_;
98 typedef base::hash_map<cc::SharedBitmapId, scoped_refptr<BitmapData> >
99 BitmapMap;
100 BitmapMap handle_map_;
102 DISALLOW_COPY_AND_ASSIGN(HostSharedBitmapManager);
105 } // namespace content
107 #endif // CONTENT_COMMON_HOST_SHARED_BITMAP_MANAGER_H_