license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 1 | // Copyright (c) 2006-2008 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. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
| 5 | #ifndef CHROME_RENDERER_RENDER_PROCESS_H__ |
| 6 | #define CHROME_RENDERER_RENDER_PROCESS_H__ |
| 7 | |
[email protected] | e68e62fa | 2009-02-20 02:00:04 | [diff] [blame] | 8 | #include "base/timer.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 9 | #include "chrome/common/child_process.h" |
| 10 | #include "chrome/renderer/render_thread.h" |
[email protected] | d032f49 | 2009-09-29 00:33:46 | [diff] [blame] | 11 | #include "native_client/src/shared/imc/nacl_imc.h" |
[email protected] | e68e62fa | 2009-02-20 02:00:04 | [diff] [blame] | 12 | #include "skia/ext/platform_canvas.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 13 | |
[email protected] | e68e62fa | 2009-02-20 02:00:04 | [diff] [blame] | 14 | namespace gfx { |
| 15 | class Rect; |
[email protected] | 39008c0 | 2009-02-11 23:59:25 | [diff] [blame] | 16 | } |
| 17 | |
[email protected] | e68e62fa | 2009-02-20 02:00:04 | [diff] [blame] | 18 | class TransportDIB; |
| 19 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 20 | // Represents the renderer end of the browser<->renderer connection. The |
| 21 | // opposite end is the RenderProcessHost. This is a singleton object for |
| 22 | // each renderer. |
| 23 | class RenderProcess : public ChildProcess { |
| 24 | public: |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 25 | RenderProcess(); |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 26 | ~RenderProcess(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 27 | |
[email protected] | e68e62fa | 2009-02-20 02:00:04 | [diff] [blame] | 28 | // Get a canvas suitable for drawing and transporting to the browser |
| 29 | // memory: (output) the transport DIB memory |
| 30 | // rect: the rectangle which will be painted, use for sizing the canvas |
| 31 | // returns: NULL on error |
| 32 | // |
| 33 | // When no longer needed, you should pass the TransportDIB to |
| 34 | // ReleaseTransportDIB so that it can be recycled. |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 35 | skia::PlatformCanvas* GetDrawingCanvas( |
[email protected] | e68e62fa | 2009-02-20 02:00:04 | [diff] [blame] | 36 | TransportDIB** memory, const gfx::Rect& rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 37 | |
| 38 | // Frees shared memory allocated by AllocSharedMemory. You should only use |
| 39 | // this function to free the SharedMemory object. |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 40 | void ReleaseTransportDIB(TransportDIB* memory); |
[email protected] | 514e711 | 2009-02-20 05:23:36 | [diff] [blame] | 41 | |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 42 | // Returns true if plugins should be loaded in-process. |
| 43 | bool in_process_plugins() const { return in_process_plugins_; } |
[email protected] | ea51de3 | 2009-02-20 07:15:17 | [diff] [blame] | 44 | |
[email protected] | b08eebe | 2009-05-18 22:37:21 | [diff] [blame] | 45 | bool initialized_media_library() const { return initialized_media_library_; } |
| 46 | |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 47 | // Returns a pointer to the RenderProcess singleton instance. |
| 48 | static RenderProcess* current() { |
| 49 | return static_cast<RenderProcess*>(ChildProcess::current()); |
[email protected] | ea51de3 | 2009-02-20 07:15:17 | [diff] [blame] | 50 | } |
| 51 | |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 52 | // Just like in_process_plugins(), but called before RenderProcess is created. |
| 53 | static bool InProcessPlugins(); |
| 54 | |
[email protected] | d032f49 | 2009-09-29 00:33:46 | [diff] [blame] | 55 | // Sends a message to the browser process asking to launch a new NaCl process. |
| 56 | // Called from NaCl plugin code. |
[email protected] | f08e47d | 2009-10-15 21:46:15 | [diff] [blame] | 57 | static bool LaunchNaClProcess(const char* url, |
| 58 | int imc_fd, |
| 59 | nacl::Handle* imc_handle, |
| 60 | nacl::Handle* nacl_process_handle, |
| 61 | int* nacl_process_id); |
[email protected] | d032f49 | 2009-09-29 00:33:46 | [diff] [blame] | 62 | |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 63 | private: |
[email protected] | e68e62fa | 2009-02-20 02:00:04 | [diff] [blame] | 64 | // Look in the shared memory cache for a suitable object to reuse. |
| 65 | // result: (output) the memory found |
| 66 | // size: the resulting memory will be >= this size, in bytes |
| 67 | // returns: false if a suitable DIB memory could not be found |
| 68 | bool GetTransportDIBFromCache(TransportDIB** result, size_t size); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 69 | |
[email protected] | e68e62fa | 2009-02-20 02:00:04 | [diff] [blame] | 70 | // Maybe put the given shared memory into the shared memory cache. Returns |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 71 | // true if the SharedMemory object was stored in the cache; otherwise, false |
| 72 | // is returned. |
[email protected] | e68e62fa | 2009-02-20 02:00:04 | [diff] [blame] | 73 | bool PutSharedMemInCache(TransportDIB* memory); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 74 | |
[email protected] | e68e62fa | 2009-02-20 02:00:04 | [diff] [blame] | 75 | void ClearTransportDIBCache(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 76 | |
[email protected] | e68e62fa | 2009-02-20 02:00:04 | [diff] [blame] | 77 | // Return the index of a free cache slot in which to install a transport DIB |
| 78 | // of the given size. If all entries in the cache are larger than the given |
| 79 | // size, this doesn't free any slots and returns -1. |
| 80 | int FindFreeCacheSlot(size_t size); |
| 81 | |
| 82 | // Create a new transport DIB of, at least, the given size. Return NULL on |
| 83 | // error. |
| 84 | TransportDIB* CreateTransportDIB(size_t size); |
| 85 | void FreeTransportDIB(TransportDIB*); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 86 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 87 | // A very simplistic and small cache. If an entry in this array is non-null, |
| 88 | // then it points to a SharedMemory object that is available for reuse. |
[email protected] | e68e62fa | 2009-02-20 02:00:04 | [diff] [blame] | 89 | TransportDIB* shared_mem_cache_[2]; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 90 | |
[email protected] | e68e62fa | 2009-02-20 02:00:04 | [diff] [blame] | 91 | // This DelayTimer cleans up our cache 5 seconds after the last use. |
| 92 | base::DelayTimer<RenderProcess> shared_mem_cache_cleaner_; |
| 93 | |
| 94 | // TransportDIB sequence number |
| 95 | uint32 sequence_number_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 96 | |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 97 | bool in_process_plugins_; |
[email protected] | b08eebe | 2009-05-18 22:37:21 | [diff] [blame] | 98 | bool initialized_media_library_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 99 | |
[email protected] | 1bc8306 | 2009-02-06 00:16:37 | [diff] [blame] | 100 | DISALLOW_COPY_AND_ASSIGN(RenderProcess); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 101 | }; |
| 102 | |
| 103 | #endif // CHROME_RENDERER_RENDER_PROCESS_H__ |