[email protected] | 396c3a46 | 2010-03-03 05:03:22 | [diff] [blame] | 1 | // 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] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame^] | 7 | #pragma once |
[email protected] | 396c3a46 | 2010-03-03 05:03:22 | [diff] [blame] | 8 | |
| 9 | #include "base/timer.h" |
| 10 | #include "chrome/renderer/render_process.h" |
| 11 | #include "chrome/renderer/render_thread.h" |
| 12 | #include "native_client/src/shared/imc/nacl_imc.h" |
| 13 | #include "skia/ext/platform_canvas.h" |
| 14 | |
| 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 { |
| 19 | public: |
| 20 | RenderProcessImpl(); |
| 21 | ~RenderProcessImpl(); |
| 22 | |
| 23 | // RenderProcess implementation. |
| 24 | virtual skia::PlatformCanvas* GetDrawingCanvas(TransportDIB** memory, |
| 25 | const gfx::Rect& rect); |
| 26 | virtual void ReleaseTransportDIB(TransportDIB* memory); |
| 27 | virtual bool UseInProcessPlugins() const; |
| 28 | virtual bool HasInitializedMediaLibrary() const; |
| 29 | |
| 30 | // Like UseInProcessPlugins(), but called before RenderProcess is created |
| 31 | // and does not allow overriding by tests. This just checks the command line |
| 32 | // each time. |
| 33 | static bool InProcessPlugins(); |
| 34 | |
| 35 | private: |
| 36 | // Look in the shared memory cache for a suitable object to reuse. |
| 37 | // result: (output) the memory found |
| 38 | // size: the resulting memory will be >= this size, in bytes |
| 39 | // returns: false if a suitable DIB memory could not be found |
| 40 | bool GetTransportDIBFromCache(TransportDIB** result, size_t size); |
| 41 | |
| 42 | // Maybe put the given shared memory into the shared memory cache. Returns |
| 43 | // true if the SharedMemory object was stored in the cache; otherwise, false |
| 44 | // is returned. |
| 45 | bool PutSharedMemInCache(TransportDIB* memory); |
| 46 | |
| 47 | void ClearTransportDIBCache(); |
| 48 | |
| 49 | // Return the index of a free cache slot in which to install a transport DIB |
| 50 | // of the given size. If all entries in the cache are larger than the given |
| 51 | // size, this doesn't free any slots and returns -1. |
| 52 | int FindFreeCacheSlot(size_t size); |
| 53 | |
| 54 | // Create a new transport DIB of, at least, the given size. Return NULL on |
| 55 | // error. |
| 56 | TransportDIB* CreateTransportDIB(size_t size); |
| 57 | void FreeTransportDIB(TransportDIB*); |
| 58 | |
| 59 | // A very simplistic and small cache. If an entry in this array is non-null, |
| 60 | // then it points to a SharedMemory object that is available for reuse. |
| 61 | TransportDIB* shared_mem_cache_[2]; |
| 62 | |
| 63 | // This DelayTimer cleans up our cache 5 seconds after the last use. |
| 64 | base::DelayTimer<RenderProcessImpl> shared_mem_cache_cleaner_; |
| 65 | |
| 66 | // TransportDIB sequence number |
| 67 | uint32 transport_dib_next_sequence_number_; |
| 68 | |
| 69 | bool in_process_plugins_; |
| 70 | bool initialized_media_library_; |
| 71 | |
| 72 | DISALLOW_COPY_AND_ASSIGN(RenderProcessImpl); |
| 73 | }; |
| 74 | |
| 75 | #endif // CHROME_RENDERER_RENDER_PROCESS_IMPL_H_ |