1 // Copyright (c) 2012 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_RENDERER_RENDER_PROCESS_IMPL_H_
6 #define CONTENT_RENDERER_RENDER_PROCESS_IMPL_H_
8 #include "base/timer/timer.h"
9 #include "content/renderer/render_process.h"
15 // Implementation of the RenderProcess interface for the regular browser.
16 // See also MockRenderProcess which implements the active "RenderProcess" when
17 // running under certain unit tests.
18 class RenderProcessImpl
: public RenderProcess
{
21 virtual ~RenderProcessImpl();
23 // RenderProcess implementation.
24 virtual SkCanvas
* GetDrawingCanvas(
25 TransportDIB
** memory
,
26 const gfx::Rect
& rect
) OVERRIDE
;
27 virtual void ReleaseTransportDIB(TransportDIB
* memory
) OVERRIDE
;
28 virtual void AddBindings(int bindings
) OVERRIDE
;
29 virtual int GetEnabledBindings() const OVERRIDE
;
30 virtual TransportDIB
* CreateTransportDIB(size_t size
) OVERRIDE
;
31 virtual void FreeTransportDIB(TransportDIB
*) OVERRIDE
;
34 // Look in the shared memory cache for a suitable object to reuse.
35 // result: (output) the memory found
36 // size: the resulting memory will be >= this size, in bytes
37 // returns: false if a suitable DIB memory could not be found
38 bool GetTransportDIBFromCache(TransportDIB
** result
, size_t size
);
40 // Maybe put the given shared memory into the shared memory cache. Returns
41 // true if the SharedMemory object was stored in the cache; otherwise, false
43 bool PutSharedMemInCache(TransportDIB
* memory
);
45 void ClearTransportDIBCache();
47 // Return the index of a free cache slot in which to install a transport DIB
48 // of the given size. If all entries in the cache are larger than the given
49 // size, this doesn't free any slots and returns -1.
50 int FindFreeCacheSlot(size_t size
);
52 // A very simplistic and small cache. If an entry in this array is non-null,
53 // then it points to a SharedMemory object that is available for reuse.
54 TransportDIB
* shared_mem_cache_
[2];
56 // This DelayTimer cleans up our cache 5 seconds after the last use.
57 base::DelayTimer
<RenderProcessImpl
> shared_mem_cache_cleaner_
;
59 // TransportDIB sequence number
60 uint32 transport_dib_next_sequence_number_
;
62 // Bitwise-ORed set of extra bindings that have been enabled anywhere in this
63 // process. See BindingsPolicy for details.
64 int enabled_bindings_
;
66 DISALLOW_COPY_AND_ASSIGN(RenderProcessImpl
);
69 } // namespace content
71 #endif // CONTENT_RENDERER_RENDER_PROCESS_IMPL_H_