Home | History | Annotate | Download | only in renderer
      1 // Copyright (c) 2012 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 CONTENT_RENDERER_RENDER_PROCESS_IMPL_H_
      6 #define CONTENT_RENDERER_RENDER_PROCESS_IMPL_H_
      7 
      8 #include "base/timer/timer.h"
      9 #include "content/renderer/render_process.h"
     10 
     11 class SkCanvas;
     12 
     13 namespace content {
     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   virtual ~RenderProcessImpl();
     22 
     23   // RenderProcess implementation.
     24   virtual SkCanvas* GetDrawingCanvas(
     25       TransportDIB** memory,
     26       const gfx::Rect& rect) OVERRIDE;
     27   virtual void ReleaseTransportDIB(TransportDIB* memory) OVERRIDE;
     28   virtual bool UseInProcessPlugins() const OVERRIDE;
     29   virtual void AddBindings(int bindings) OVERRIDE;
     30   virtual int GetEnabledBindings() const OVERRIDE;
     31   virtual TransportDIB* CreateTransportDIB(size_t size) OVERRIDE;
     32   virtual void FreeTransportDIB(TransportDIB*) OVERRIDE;
     33 
     34   // Like UseInProcessPlugins(), but called before RenderProcess is created
     35   // and does not allow overriding by tests. This just checks the command line
     36   // each time.
     37   static bool InProcessPlugins();
     38 
     39  private:
     40   // Look in the shared memory cache for a suitable object to reuse.
     41   //   result: (output) the memory found
     42   //   size: the resulting memory will be >= this size, in bytes
     43   //   returns: false if a suitable DIB memory could not be found
     44   bool GetTransportDIBFromCache(TransportDIB** result, size_t size);
     45 
     46   // Maybe put the given shared memory into the shared memory cache. Returns
     47   // true if the SharedMemory object was stored in the cache; otherwise, false
     48   // is returned.
     49   bool PutSharedMemInCache(TransportDIB* memory);
     50 
     51   void ClearTransportDIBCache();
     52 
     53   // Return the index of a free cache slot in which to install a transport DIB
     54   // of the given size. If all entries in the cache are larger than the given
     55   // size, this doesn't free any slots and returns -1.
     56   int FindFreeCacheSlot(size_t size);
     57 
     58   // A very simplistic and small cache.  If an entry in this array is non-null,
     59   // then it points to a SharedMemory object that is available for reuse.
     60   TransportDIB* shared_mem_cache_[2];
     61 
     62   // This DelayTimer cleans up our cache 5 seconds after the last use.
     63   base::DelayTimer<RenderProcessImpl> shared_mem_cache_cleaner_;
     64 
     65   // TransportDIB sequence number
     66   uint32 transport_dib_next_sequence_number_;
     67 
     68   bool in_process_plugins_;
     69 
     70   // Bitwise-ORed set of extra bindings that have been enabled anywhere in this
     71   // process.  See BindingsPolicy for details.
     72   int enabled_bindings_;
     73 
     74   DISALLOW_COPY_AND_ASSIGN(RenderProcessImpl);
     75 };
     76 
     77 }  // namespace content
     78 
     79 #endif  // CONTENT_RENDERER_RENDER_PROCESS_IMPL_H_
     80