blob: 4c682dce1a9228dd2227e9a77d414626596a1906 [file] [log] [blame]
license.botbf09a502008-08-24 00:55:551// 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.commit09911bf2008-07-26 23:55:294
5#ifndef CHROME_RENDERER_RENDER_PROCESS_H__
6#define CHROME_RENDERER_RENDER_PROCESS_H__
7
[email protected]e68e62fa2009-02-20 02:00:048#include "base/timer.h"
initial.commit09911bf2008-07-26 23:55:299#include "chrome/common/child_process.h"
10#include "chrome/renderer/render_thread.h"
[email protected]d032f492009-09-29 00:33:4611#include "native_client/src/shared/imc/nacl_imc.h"
[email protected]e68e62fa2009-02-20 02:00:0412#include "skia/ext/platform_canvas.h"
initial.commit09911bf2008-07-26 23:55:2913
[email protected]e68e62fa2009-02-20 02:00:0414namespace gfx {
15class Rect;
[email protected]39008c02009-02-11 23:59:2516}
17
[email protected]e68e62fa2009-02-20 02:00:0418class TransportDIB;
19
initial.commit09911bf2008-07-26 23:55:2920// 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.
23class RenderProcess : public ChildProcess {
24 public:
[email protected]8930d472009-02-21 08:05:2825 RenderProcess();
[email protected]8930d472009-02-21 08:05:2826 ~RenderProcess();
initial.commit09911bf2008-07-26 23:55:2927
[email protected]e68e62fa2009-02-20 02:00:0428 // 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]8930d472009-02-21 08:05:2835 skia::PlatformCanvas* GetDrawingCanvas(
[email protected]e68e62fa2009-02-20 02:00:0436 TransportDIB** memory, const gfx::Rect& rect);
initial.commit09911bf2008-07-26 23:55:2937
38 // Frees shared memory allocated by AllocSharedMemory. You should only use
39 // this function to free the SharedMemory object.
[email protected]8930d472009-02-21 08:05:2840 void ReleaseTransportDIB(TransportDIB* memory);
[email protected]514e7112009-02-20 05:23:3641
[email protected]8930d472009-02-21 08:05:2842 // Returns true if plugins should be loaded in-process.
43 bool in_process_plugins() const { return in_process_plugins_; }
[email protected]ea51de32009-02-20 07:15:1744
[email protected]b08eebe2009-05-18 22:37:2145 bool initialized_media_library() const { return initialized_media_library_; }
46
[email protected]8930d472009-02-21 08:05:2847 // Returns a pointer to the RenderProcess singleton instance.
48 static RenderProcess* current() {
49 return static_cast<RenderProcess*>(ChildProcess::current());
[email protected]ea51de32009-02-20 07:15:1750 }
51
[email protected]8930d472009-02-21 08:05:2852 // Just like in_process_plugins(), but called before RenderProcess is created.
53 static bool InProcessPlugins();
54
[email protected]d032f492009-09-29 00:33:4655 // Sends a message to the browser process asking to launch a new NaCl process.
56 // Called from NaCl plugin code.
[email protected]f08e47d2009-10-15 21:46:1557 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]d032f492009-09-29 00:33:4662
[email protected]8930d472009-02-21 08:05:2863 private:
[email protected]e68e62fa2009-02-20 02:00:0464 // 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.commit09911bf2008-07-26 23:55:2969
[email protected]e68e62fa2009-02-20 02:00:0470 // Maybe put the given shared memory into the shared memory cache. Returns
initial.commit09911bf2008-07-26 23:55:2971 // true if the SharedMemory object was stored in the cache; otherwise, false
72 // is returned.
[email protected]e68e62fa2009-02-20 02:00:0473 bool PutSharedMemInCache(TransportDIB* memory);
initial.commit09911bf2008-07-26 23:55:2974
[email protected]e68e62fa2009-02-20 02:00:0475 void ClearTransportDIBCache();
initial.commit09911bf2008-07-26 23:55:2976
[email protected]e68e62fa2009-02-20 02:00:0477 // 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.commit09911bf2008-07-26 23:55:2986
initial.commit09911bf2008-07-26 23:55:2987 // 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]e68e62fa2009-02-20 02:00:0489 TransportDIB* shared_mem_cache_[2];
initial.commit09911bf2008-07-26 23:55:2990
[email protected]e68e62fa2009-02-20 02:00:0491 // 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.commit09911bf2008-07-26 23:55:2996
[email protected]8930d472009-02-21 08:05:2897 bool in_process_plugins_;
[email protected]b08eebe2009-05-18 22:37:2198 bool initialized_media_library_;
initial.commit09911bf2008-07-26 23:55:2999
[email protected]1bc83062009-02-06 00:16:37100 DISALLOW_COPY_AND_ASSIGN(RenderProcess);
initial.commit09911bf2008-07-26 23:55:29101};
102
103#endif // CHROME_RENDERER_RENDER_PROCESS_H__