#ifndef CHROME_BROWSER_EXTENSIONS_SHELL_WINDOW_GEOMETRY_CACHE_H_
#define CHROME_BROWSER_EXTENSIONS_SHELL_WINDOW_GEOMETRY_CACHE_H_
#include <map>
#include <set>
#include <string>
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/timer.h"
#include "base/values.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "ui/gfx/rect.h"
class Profile;
namespace extensions {
class StateStore;
class ShellWindowGeometryCache
: public base::SupportsWeakPtr<ShellWindowGeometryCache>,
public content::NotificationObserver {
public:
ShellWindowGeometryCache(Profile* profile, StateStore* state_store);
virtual ~ShellWindowGeometryCache();
void SaveGeometry(const std::string& extension_id,
const std::string& window_id,
const gfx::Rect& bounds);
bool GetGeometry(const std::string& extension_id,
const std::string& window_id,
gfx::Rect* bounds) const;
private:
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
void OnExtensionLoaded(const std::string& extension_id);
void OnExtensionUnloaded(const std::string& extension_id);
void GeometryFromStorage(const std::string& extension_id,
scoped_ptr<base::Value> value);
void SyncToStorage();
friend class ShellWindowGeometryCacheTest;
StateStore* store_;
std::map<std::string, std::map<std::string, gfx::Rect> > cache_;
std::set<std::string> unsynced_extensions_;
base::OneShotTimer<ShellWindowGeometryCache> sync_timer_;
content::NotificationRegistrar registrar_;
};
}
#endif