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 bool UseInProcessPlugins() const OVERRIDE
;
29 virtual void AddBindings(int bindings
) OVERRIDE
;
30 virtual int GetEnabledBindings() const OVERRIDE
;
31 virtual TransportDIB
* CreateTransportDIB(size_t size
) OVERRIDE
;
32 virtual void FreeTransportDIB(TransportDIB
*) OVERRIDE
;
34 // Like UseInProcessPlugins(), but called before RenderProcess is created
35 // and does not allow overriding by tests. This just checks the command line
37 static bool InProcessPlugins();
40 // Look in the shared memory cache for a suitable object to reuse.
41 // result: (output) the memory found
42 // size: the resulting memory will be >= this size, in bytes
43 // returns: false if a suitable DIB memory could not be found
44 bool GetTransportDIBFromCache(TransportDIB
** result
, size_t size
);
46 // Maybe put the given shared memory into the shared memory cache. Returns
47 // true if the SharedMemory object was stored in the cache; otherwise, false
49 bool PutSharedMemInCache(TransportDIB
* memory
);
51 void ClearTransportDIBCache();
53 // Return the index of a free cache slot in which to install a transport DIB
54 // of the given size. If all entries in the cache are larger than the given
55 // size, this doesn't free any slots and returns -1.
56 int FindFreeCacheSlot(size_t size
);
58 // A very simplistic and small cache. If an entry in this array is non-null,
59 // then it points to a SharedMemory object that is available for reuse.
60 TransportDIB
* shared_mem_cache_
[2];
62 // This DelayTimer cleans up our cache 5 seconds after the last use.
63 base::DelayTimer
<RenderProcessImpl
> shared_mem_cache_cleaner_
;
65 // TransportDIB sequence number
66 uint32 transport_dib_next_sequence_number_
;
68 bool in_process_plugins_
;
70 // Bitwise-ORed set of extra bindings that have been enabled anywhere in this
71 // process. See BindingsPolicy for details.
72 int enabled_bindings_
;
74 DISALLOW_COPY_AND_ASSIGN(RenderProcessImpl
);
77 } // namespace content
79 #endif // CONTENT_RENDERER_RENDER_PROCESS_IMPL_H_