| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_RENDERER_RENDER_PROCESS_H__ | 5 #ifndef CHROME_RENDERER_RENDER_PROCESS_H__ |
| 6 #define CHROME_RENDERER_RENDER_PROCESS_H__ | 6 #define CHROME_RENDERER_RENDER_PROCESS_H__ |
| 7 | 7 |
| 8 #include "base/timer.h" |
| 8 #include "chrome/common/child_process.h" | 9 #include "chrome/common/child_process.h" |
| 9 #include "chrome/renderer/render_thread.h" | 10 #include "chrome/renderer/render_thread.h" |
| 11 #include "skia/ext/platform_canvas.h" |
| 10 | 12 |
| 11 namespace base { | 13 namespace gfx { |
| 12 class SharedMemory; | 14 class Rect; |
| 13 } | 15 } |
| 14 | 16 |
| 17 class TransportDIB; |
| 18 |
| 15 // Represents the renderer end of the browser<->renderer connection. The | 19 // Represents the renderer end of the browser<->renderer connection. The |
| 16 // opposite end is the RenderProcessHost. This is a singleton object for | 20 // opposite end is the RenderProcessHost. This is a singleton object for |
| 17 // each renderer. | 21 // each renderer. |
| 18 class RenderProcess : public ChildProcess { | 22 class RenderProcess : public ChildProcess { |
| 19 public: | 23 public: |
| 20 static bool GlobalInit(const std::wstring& channel_name); | 24 static bool GlobalInit(const std::wstring& channel_name); |
| 21 static void GlobalCleanup(); | 25 static void GlobalCleanup(); |
| 22 | 26 |
| 23 // Returns true if plugins should be loaded in-process. | 27 // Returns true if plugins should be loaded in-process. |
| 24 static bool ShouldLoadPluginsInProcess(); | 28 static bool ShouldLoadPluginsInProcess(); |
| 25 | 29 |
| 26 // Allocates shared memory. When no longer needed, you should pass the | 30 // Get a canvas suitable for drawing and transporting to the browser |
| 27 // SharedMemory pointer to FreeSharedMemory so it can be recycled. The size | 31 // memory: (output) the transport DIB memory |
| 28 // reported in the resulting SharedMemory object will be greater than or | 32 // rect: the rectangle which will be painted, use for sizing the canvas |
| 29 // equal to the requested size. This method returns NULL if unable to | 33 // returns: NULL on error |
| 30 // allocate memory for some reason. | 34 // |
| 31 static base::SharedMemory* AllocSharedMemory(size_t size); | 35 // When no longer needed, you should pass the TransportDIB to |
| 36 // ReleaseTransportDIB so that it can be recycled. |
| 37 static skia::PlatformCanvas* GetDrawingCanvas( |
| 38 TransportDIB** memory, const gfx::Rect& rect); |
| 32 | 39 |
| 33 // Frees shared memory allocated by AllocSharedMemory. You should only use | 40 // Frees shared memory allocated by AllocSharedMemory. You should only use |
| 34 // this function to free the SharedMemory object. | 41 // this function to free the SharedMemory object. |
| 35 static void FreeSharedMemory(base::SharedMemory* mem); | 42 static void ReleaseTransportDIB(TransportDIB* memory); |
| 36 | |
| 37 // Deletes the shared memory allocated by AllocSharedMemory. | |
| 38 static void DeleteSharedMem(base::SharedMemory* mem); | |
| 39 | 43 |
| 40 private: | 44 private: |
| 41 friend class ChildProcessFactory<RenderProcess>; | 45 friend class ChildProcessFactory<RenderProcess>; |
| 42 explicit RenderProcess(const std::wstring& channel_name); | 46 explicit RenderProcess(const std::wstring& channel_name); |
| 43 ~RenderProcess(); | 47 ~RenderProcess(); |
| 44 | 48 |
| 45 // Returns a pointer to the RenderProcess singleton instance. This is | 49 // Returns a pointer to the RenderProcess singleton instance. This is |
| 46 // guaranteed to be non-NULL between calls to GlobalInit and GlobalCleanup. | 50 // guaranteed to be non-NULL between calls to GlobalInit and GlobalCleanup. |
| 47 static RenderProcess* self() { | 51 static RenderProcess* self() { |
| 48 return static_cast<RenderProcess*>(child_process_); | 52 return static_cast<RenderProcess*>(child_process_); |
| 49 } | 53 } |
| 50 | 54 |
| 51 static ChildProcess* ClassFactory(const std::wstring& channel_name); | 55 static ChildProcess* ClassFactory(const std::wstring& channel_name); |
| 52 | 56 |
| 53 // Look in the shared memory cache for a suitable object to reuse. Returns | 57 // Look in the shared memory cache for a suitable object to reuse. |
| 54 // NULL if there is none. | 58 // result: (output) the memory found |
| 55 base::SharedMemory* GetSharedMemFromCache(size_t size); | 59 // size: the resulting memory will be >= this size, in bytes |
| 60 // returns: false if a suitable DIB memory could not be found |
| 61 bool GetTransportDIBFromCache(TransportDIB** result, size_t size); |
| 56 | 62 |
| 57 // Maybe put the given shared memory into the shared memory cache. Returns | 63 // Maybe put the given shared memory into the shared memory cache. Returns |
| 58 // true if the SharedMemory object was stored in the cache; otherwise, false | 64 // true if the SharedMemory object was stored in the cache; otherwise, false |
| 59 // is returned. | 65 // is returned. |
| 60 bool PutSharedMemInCache(base::SharedMemory* mem); | 66 bool PutSharedMemInCache(TransportDIB* memory); |
| 61 | 67 |
| 62 void ClearSharedMemCache(); | 68 void ClearTransportDIBCache(); |
| 63 | 69 |
| 64 // We want to lazily clear the shared memory cache if no one has requested | 70 // Return the index of a free cache slot in which to install a transport DIB |
| 65 // memory. This methods are used to schedule a deferred call to | 71 // of the given size. If all entries in the cache are larger than the given |
| 66 // RenderProcess::ClearSharedMemCache. | 72 // size, this doesn't free any slots and returns -1. |
| 67 void ScheduleCacheClearer(); | 73 int FindFreeCacheSlot(size_t size); |
| 74 |
| 75 // Create a new transport DIB of, at least, the given size. Return NULL on |
| 76 // error. |
| 77 TransportDIB* CreateTransportDIB(size_t size); |
| 78 void FreeTransportDIB(TransportDIB*); |
| 68 | 79 |
| 69 // ChildProcess implementation | 80 // ChildProcess implementation |
| 70 virtual void Cleanup(); | 81 virtual void Cleanup(); |
| 71 | 82 |
| 72 // The one render thread (to be replaced with a set of render threads). | 83 // The one render thread (to be replaced with a set of render threads). |
| 73 RenderThread render_thread_; | 84 RenderThread render_thread_; |
| 74 | 85 |
| 75 // A very simplistic and small cache. If an entry in this array is non-null, | 86 // A very simplistic and small cache. If an entry in this array is non-null, |
| 76 // then it points to a SharedMemory object that is available for reuse. | 87 // then it points to a SharedMemory object that is available for reuse. |
| 77 base::SharedMemory* shared_mem_cache_[2]; | 88 TransportDIB* shared_mem_cache_[2]; |
| 78 | 89 |
| 79 // This factory is used to lazily invoke ClearSharedMemCache. | 90 // This DelayTimer cleans up our cache 5 seconds after the last use. |
| 80 ScopedRunnableMethodFactory<RenderProcess> clearer_factory_; | 91 base::DelayTimer<RenderProcess> shared_mem_cache_cleaner_; |
| 92 |
| 93 // TransportDIB sequence number |
| 94 uint32 sequence_number_; |
| 81 | 95 |
| 82 static bool load_plugins_in_process_; | 96 static bool load_plugins_in_process_; |
| 83 | 97 |
| 84 DISALLOW_COPY_AND_ASSIGN(RenderProcess); | 98 DISALLOW_COPY_AND_ASSIGN(RenderProcess); |
| 85 }; | 99 }; |
| 86 | 100 |
| 87 #endif // CHROME_RENDERER_RENDER_PROCESS_H__ | 101 #endif // CHROME_RENDERER_RENDER_PROCESS_H__ |
| OLD | NEW |