Chromium Code Reviews| Index: apps/shell_window_geometry_cache.h |
| diff --git a/chrome/browser/extensions/shell_window_geometry_cache.h b/apps/shell_window_geometry_cache.h |
| similarity index 73% |
| rename from chrome/browser/extensions/shell_window_geometry_cache.h |
| rename to apps/shell_window_geometry_cache.h |
| index 5648b0d4b7b802a8346d7e67330b700bc6856a07..9cc10b2df424a8e34312ef6fdf919292150faa4c 100644 |
| --- a/chrome/browser/extensions/shell_window_geometry_cache.h |
| +++ b/apps/shell_window_geometry_cache.h |
| @@ -10,10 +10,12 @@ |
| #include <string> |
| #include "base/memory/scoped_ptr.h" |
| -#include "base/memory/weak_ptr.h" |
| +#include "base/memory/singleton.h" |
| #include "base/time.h" |
| #include "base/timer.h" |
| #include "base/values.h" |
| +#include "chrome/browser/profiles/profile_keyed_service.h" |
| +#include "chrome/browser/profiles/profile_keyed_service_factory.h" |
| #include "content/public/browser/notification_observer.h" |
| #include "content/public/browser/notification_registrar.h" |
| #include "ui/base/ui_base_types.h" |
| @@ -22,21 +24,47 @@ |
| class Profile; |
| namespace extensions { |
| - |
| class ExtensionPrefs; |
| +} |
| + |
| +namespace apps { |
| // A cache for persisted geometry of shell windows, both to not have to wait |
| // for IO when creating a new window, and to not cause IO on every window |
| // geometry change. |
| class ShellWindowGeometryCache |
| - : public base::SupportsWeakPtr<ShellWindowGeometryCache>, |
| + : public ProfileKeyedService, |
| public content::NotificationObserver { |
| public: |
| + class Factory : public ProfileKeyedServiceFactory { |
| + public: |
| + static ShellWindowGeometryCache* GetForContext( |
| + content::BrowserContext* context, |
| + bool create); |
| + |
| + static Factory* GetInstance(); |
| + private: |
| + friend struct DefaultSingletonTraits<Factory>; |
| + |
| + Factory(); |
| + virtual ~Factory(); |
| + |
| + // ProfileKeyedServiceFactory |
| + virtual ProfileKeyedService* BuildServiceInstanceFor( |
| + content::BrowserContext* context) const OVERRIDE; |
| + virtual bool ServiceIsNULLWhileTesting() const OVERRIDE; |
| + virtual content::BrowserContext* GetBrowserContextToUse( |
| + content::BrowserContext* context) const OVERRIDE; |
| + }; |
| + |
| ShellWindowGeometryCache(Profile* profile, |
| - ExtensionPrefs* prefs); |
| + extensions::ExtensionPrefs* prefs); |
| virtual ~ShellWindowGeometryCache(); |
| + // Returns the instance for the given browsing context, or NULL if none. |
|
Yoyo Zhou
2013/05/15 22:52:11
Do you ever return NULL?
benwells
2013/05/16 11:05:38
Oops, updated comment.
|
| + static ShellWindowGeometryCache* Get(content::BrowserContext* context); |
| + |
| // Save the geometry and state associated with |extension_id| and |window_id|. |
| void SaveGeometry(const std::string& extension_id, |
| const std::string& window_id, |
| @@ -51,6 +79,9 @@ class ShellWindowGeometryCache |
| gfx::Rect* bounds, |
| ui::WindowShowState* state) const; |
| + // ProfileKeyedService |
| + virtual void Shutdown() OVERRIDE; |
| + |
| // Maximum number of windows we'll cache the geometry for per app. |
| static const size_t kMaxCachedWindows = 100; |
| @@ -84,7 +115,7 @@ class ShellWindowGeometryCache |
| void SyncToStorage(); |
| // Preferences storage. |
| - ExtensionPrefs* prefs_; |
| + extensions::ExtensionPrefs* prefs_; |
| // Cached data |
| std::map<std::string, ExtensionData> cache_; |
| @@ -101,6 +132,6 @@ class ShellWindowGeometryCache |
| content::NotificationRegistrar registrar_; |
| }; |
| -} // namespace extensions |
| +} // namespace apps |
| #endif // CHROME_BROWSER_EXTENSIONS_SHELL_WINDOW_GEOMETRY_CACHE_H_ |