blob: 7b74d6f6bd073a47560a301308f719cba82e3504 [file] [log] [blame]
[email protected]396c3a462010-03-03 05:03:221// Copyright (c) 2010 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
[email protected]8704f89b2011-04-15 00:30:055#ifndef CONTENT_RENDERER_RENDER_PROCESS_IMPL_H_
6#define CONTENT_RENDERER_RENDER_PROCESS_IMPL_H_
[email protected]32b76ef2010-07-26 23:08:247#pragma once
[email protected]396c3a462010-03-03 05:03:228
9#include "base/timer.h"
[email protected]8704f89b2011-04-15 00:30:0510#include "content/renderer/render_process.h"
[email protected]396c3a462010-03-03 05:03:2211#include "native_client/src/shared/imc/nacl_imc.h"
[email protected]46f36a492010-07-28 19:36:4112
13namespace skia {
14class PlatformCanvas;
15}
[email protected]396c3a462010-03-03 05:03:2216
17// Implementation of the RenderProcess interface for the regular browser.
18// See also MockRenderProcess which implements the active "RenderProcess" when
19// running under certain unit tests.
20class RenderProcessImpl : public RenderProcess {
21 public:
22 RenderProcessImpl();
[email protected]3690ebe02011-05-25 09:08:1923 virtual ~RenderProcessImpl();
[email protected]396c3a462010-03-03 05:03:2224
25 // RenderProcess implementation.
26 virtual skia::PlatformCanvas* GetDrawingCanvas(TransportDIB** memory,
27 const gfx::Rect& rect);
28 virtual void ReleaseTransportDIB(TransportDIB* memory);
29 virtual bool UseInProcessPlugins() const;
[email protected]396c3a462010-03-03 05:03:2230
31 // Like UseInProcessPlugins(), but called before RenderProcess is created
32 // and does not allow overriding by tests. This just checks the command line
33 // each time.
34 static bool InProcessPlugins();
35
36 private:
37 // Look in the shared memory cache for a suitable object to reuse.
38 // result: (output) the memory found
39 // size: the resulting memory will be >= this size, in bytes
40 // returns: false if a suitable DIB memory could not be found
41 bool GetTransportDIBFromCache(TransportDIB** result, size_t size);
42
43 // Maybe put the given shared memory into the shared memory cache. Returns
44 // true if the SharedMemory object was stored in the cache; otherwise, false
45 // is returned.
46 bool PutSharedMemInCache(TransportDIB* memory);
47
48 void ClearTransportDIBCache();
49
50 // Return the index of a free cache slot in which to install a transport DIB
51 // of the given size. If all entries in the cache are larger than the given
52 // size, this doesn't free any slots and returns -1.
53 int FindFreeCacheSlot(size_t size);
54
55 // Create a new transport DIB of, at least, the given size. Return NULL on
56 // error.
57 TransportDIB* CreateTransportDIB(size_t size);
58 void FreeTransportDIB(TransportDIB*);
59
60 // A very simplistic and small cache. If an entry in this array is non-null,
61 // then it points to a SharedMemory object that is available for reuse.
62 TransportDIB* shared_mem_cache_[2];
63
64 // This DelayTimer cleans up our cache 5 seconds after the last use.
65 base::DelayTimer<RenderProcessImpl> shared_mem_cache_cleaner_;
66
67 // TransportDIB sequence number
68 uint32 transport_dib_next_sequence_number_;
69
70 bool in_process_plugins_;
[email protected]396c3a462010-03-03 05:03:2271
72 DISALLOW_COPY_AND_ASSIGN(RenderProcessImpl);
73};
74
[email protected]8704f89b2011-04-15 00:30:0575#endif // CONTENT_RENDERER_RENDER_PROCESS_IMPL_H_