Home | History | Annotate | Download | only in renderer_host
      1 // Copyright 2013 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_BROWSER_RENDERER_HOST_RENDERER_FRAME_MANAGER_H_
      6 #define CONTENT_BROWSER_RENDERER_HOST_RENDERER_FRAME_MANAGER_H_
      7 
      8 #include <list>
      9 #include <map>
     10 
     11 #include "base/basictypes.h"
     12 #include "base/memory/singleton.h"
     13 #include "content/common/content_export.h"
     14 
     15 namespace content {
     16 
     17 class CONTENT_EXPORT RendererFrameManagerClient {
     18  public:
     19   virtual ~RendererFrameManagerClient() {}
     20   virtual void EvictCurrentFrame() = 0;
     21 };
     22 
     23 class CONTENT_EXPORT RendererFrameManager {
     24  public:
     25   static RendererFrameManager* GetInstance();
     26 
     27   void AddFrame(RendererFrameManagerClient*, bool locked);
     28   void RemoveFrame(RendererFrameManagerClient*);
     29   void LockFrame(RendererFrameManagerClient*);
     30   void UnlockFrame(RendererFrameManagerClient*);
     31 
     32   size_t max_number_of_saved_frames() const {
     33     return max_number_of_saved_frames_;
     34   }
     35 
     36   // For testing only
     37   void set_max_handles(float max_handles) { max_handles_ = max_handles; }
     38 
     39  private:
     40   RendererFrameManager();
     41   ~RendererFrameManager();
     42   void CullUnlockedFrames();
     43 
     44   friend struct DefaultSingletonTraits<RendererFrameManager>;
     45 
     46   std::map<RendererFrameManagerClient*, size_t> locked_frames_;
     47   std::list<RendererFrameManagerClient*> unlocked_frames_;
     48   size_t max_number_of_saved_frames_;
     49   float max_handles_;
     50 
     51   DISALLOW_COPY_AND_ASSIGN(RendererFrameManager);
     52 };
     53 
     54 }  // namespace content
     55 
     56 #endif  // CONTENT_BROWSER_RENDERER_HOST_RENDERER_FRAME_MANAGER_H_
     57