blob: dcb6a5a30215f2021df1511cf8ca93e4745fd9fe [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
5#ifndef CHROME_RENDERER_RENDER_PROCESS_IMPL_H_
6#define CHROME_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"
10#include "chrome/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();
23 ~RenderProcessImpl();
24
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;
30 virtual bool HasInitializedMediaLibrary() const;
31
32 // Like UseInProcessPlugins(), but called before RenderProcess is created
33 // and does not allow overriding by tests. This just checks the command line
34 // each time.
35 static bool InProcessPlugins();
36
37 private:
38 // Look in the shared memory cache for a suitable object to reuse.
39 // result: (output) the memory found
40 // size: the resulting memory will be >= this size, in bytes
41 // returns: false if a suitable DIB memory could not be found
42 bool GetTransportDIBFromCache(TransportDIB** result, size_t size);
43
44 // Maybe put the given shared memory into the shared memory cache. Returns
45 // true if the SharedMemory object was stored in the cache; otherwise, false
46 // is returned.
47 bool PutSharedMemInCache(TransportDIB* memory);
48
49 void ClearTransportDIBCache();
50
51 // Return the index of a free cache slot in which to install a transport DIB
52 // of the given size. If all entries in the cache are larger than the given
53 // size, this doesn't free any slots and returns -1.
54 int FindFreeCacheSlot(size_t size);
55
56 // Create a new transport DIB of, at least, the given size. Return NULL on
57 // error.
58 TransportDIB* CreateTransportDIB(size_t size);
59 void FreeTransportDIB(TransportDIB*);
60
61 // A very simplistic and small cache. If an entry in this array is non-null,
62 // then it points to a SharedMemory object that is available for reuse.
63 TransportDIB* shared_mem_cache_[2];
64
65 // This DelayTimer cleans up our cache 5 seconds after the last use.
66 base::DelayTimer<RenderProcessImpl> shared_mem_cache_cleaner_;
67
68 // TransportDIB sequence number
69 uint32 transport_dib_next_sequence_number_;
70
71 bool in_process_plugins_;
72 bool initialized_media_library_;
73
74 DISALLOW_COPY_AND_ASSIGN(RenderProcessImpl);
75};
76
77#endif // CHROME_RENDERER_RENDER_PROCESS_IMPL_H_