| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 APPS_APP_WINDOW_GEOMETRY_CACHE_H_ | 5 #ifndef EXTENSIONS_BROWSER_APP_WINDOW_APP_WINDOW_GEOMETRY_CACHE_H_ |
| 6 #define APPS_APP_WINDOW_GEOMETRY_CACHE_H_ | 6 #define EXTENSIONS_BROWSER_APP_WINDOW_APP_WINDOW_GEOMETRY_CACHE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
| 14 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
| 15 #include "base/scoped_observer.h" | 15 #include "base/scoped_observer.h" |
| 16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 17 #include "base/timer/timer.h" | 17 #include "base/timer/timer.h" |
| 18 #include "base/values.h" | 18 #include "base/values.h" |
| 19 #include "components/keyed_service/content/browser_context_keyed_service_factory
.h" | 19 #include "components/keyed_service/content/browser_context_keyed_service_factory
.h" |
| 20 #include "components/keyed_service/core/keyed_service.h" | 20 #include "components/keyed_service/core/keyed_service.h" |
| 21 #include "extensions/browser/extension_registry_observer.h" | 21 #include "extensions/browser/extension_registry_observer.h" |
| 22 #include "ui/base/ui_base_types.h" | 22 #include "ui/base/ui_base_types.h" |
| 23 #include "ui/gfx/rect.h" | 23 #include "ui/gfx/rect.h" |
| 24 | 24 |
| 25 namespace extensions { | 25 namespace extensions { |
| 26 |
| 26 class ExtensionPrefs; | 27 class ExtensionPrefs; |
| 27 class ExtensionRegistry; | 28 class ExtensionRegistry; |
| 28 } | |
| 29 | |
| 30 namespace apps { | |
| 31 | 29 |
| 32 // A cache for persisted geometry of app windows, both to not have to wait | 30 // A cache for persisted geometry of app windows, both to not have to wait |
| 33 // for IO when creating a new window, and to not cause IO on every window | 31 // for IO when creating a new window, and to not cause IO on every window |
| 34 // geometry change. | 32 // geometry change. |
| 35 class AppWindowGeometryCache : public KeyedService, | 33 class AppWindowGeometryCache : public KeyedService, |
| 36 public extensions::ExtensionRegistryObserver { | 34 public ExtensionRegistryObserver { |
| 37 public: | 35 public: |
| 38 class Factory : public BrowserContextKeyedServiceFactory { | 36 class Factory : public BrowserContextKeyedServiceFactory { |
| 39 public: | 37 public: |
| 40 static AppWindowGeometryCache* GetForContext( | 38 static AppWindowGeometryCache* GetForContext( |
| 41 content::BrowserContext* context, | 39 content::BrowserContext* context, |
| 42 bool create); | 40 bool create); |
| 43 | 41 |
| 44 static Factory* GetInstance(); | 42 static Factory* GetInstance(); |
| 45 | 43 |
| 46 private: | 44 private: |
| (...skipping 14 matching lines...) Expand all Loading... |
| 61 public: | 59 public: |
| 62 virtual void OnGeometryCacheChanged(const std::string& extension_id, | 60 virtual void OnGeometryCacheChanged(const std::string& extension_id, |
| 63 const std::string& window_id, | 61 const std::string& window_id, |
| 64 const gfx::Rect& bounds) = 0; | 62 const gfx::Rect& bounds) = 0; |
| 65 | 63 |
| 66 protected: | 64 protected: |
| 67 virtual ~Observer() {} | 65 virtual ~Observer() {} |
| 68 }; | 66 }; |
| 69 | 67 |
| 70 AppWindowGeometryCache(content::BrowserContext* context, | 68 AppWindowGeometryCache(content::BrowserContext* context, |
| 71 extensions::ExtensionPrefs* prefs); | 69 ExtensionPrefs* prefs); |
| 72 | 70 |
| 73 virtual ~AppWindowGeometryCache(); | 71 virtual ~AppWindowGeometryCache(); |
| 74 | 72 |
| 75 // Returns the instance for the given browsing context. | 73 // Returns the instance for the given browsing context. |
| 76 static AppWindowGeometryCache* Get(content::BrowserContext* context); | 74 static AppWindowGeometryCache* Get(content::BrowserContext* context); |
| 77 | 75 |
| 78 // Save the geometry and state associated with |extension_id| and |window_id|. | 76 // Save the geometry and state associated with |extension_id| and |window_id|. |
| 79 void SaveGeometry(const std::string& extension_id, | 77 void SaveGeometry(const std::string& extension_id, |
| 80 const std::string& window_id, | 78 const std::string& window_id, |
| 81 const gfx::Rect& bounds, | 79 const gfx::Rect& bounds, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 gfx::Rect bounds; | 114 gfx::Rect bounds; |
| 117 gfx::Rect screen_bounds; | 115 gfx::Rect screen_bounds; |
| 118 ui::WindowShowState window_state; | 116 ui::WindowShowState window_state; |
| 119 base::Time last_change; | 117 base::Time last_change; |
| 120 }; | 118 }; |
| 121 | 119 |
| 122 // Data stored for each extension. | 120 // Data stored for each extension. |
| 123 typedef std::map<std::string, WindowData> ExtensionData; | 121 typedef std::map<std::string, WindowData> ExtensionData; |
| 124 | 122 |
| 125 // ExtensionRegistryObserver implementation. | 123 // ExtensionRegistryObserver implementation. |
| 126 virtual void OnExtensionLoaded( | 124 virtual void OnExtensionLoaded(content::BrowserContext* browser_context, |
| 127 content::BrowserContext* browser_context, | 125 const Extension* extension) OVERRIDE; |
| 128 const extensions::Extension* extension) OVERRIDE; | |
| 129 virtual void OnExtensionUnloaded( | 126 virtual void OnExtensionUnloaded( |
| 130 content::BrowserContext* browser_context, | 127 content::BrowserContext* browser_context, |
| 131 const extensions::Extension* extension, | 128 const Extension* extension, |
| 132 extensions::UnloadedExtensionInfo::Reason reason) OVERRIDE; | 129 UnloadedExtensionInfo::Reason reason) OVERRIDE; |
| 133 | 130 |
| 134 void LoadGeometryFromStorage(const std::string& extension_id); | 131 void LoadGeometryFromStorage(const std::string& extension_id); |
| 135 void SyncToStorage(); | 132 void SyncToStorage(); |
| 136 | 133 |
| 137 // Preferences storage. | 134 // Preferences storage. |
| 138 extensions::ExtensionPrefs* prefs_; | 135 ExtensionPrefs* prefs_; |
| 139 | 136 |
| 140 // Cached data. | 137 // Cached data. |
| 141 std::map<std::string, ExtensionData> cache_; | 138 std::map<std::string, ExtensionData> cache_; |
| 142 | 139 |
| 143 // Data that still needs saving. | 140 // Data that still needs saving. |
| 144 std::set<std::string> unsynced_extensions_; | 141 std::set<std::string> unsynced_extensions_; |
| 145 | 142 |
| 146 // The timer used to save the data. | 143 // The timer used to save the data. |
| 147 base::OneShotTimer<AppWindowGeometryCache> sync_timer_; | 144 base::OneShotTimer<AppWindowGeometryCache> sync_timer_; |
| 148 | 145 |
| 149 // The timeout value we'll use for |sync_timer_|. | 146 // The timeout value we'll use for |sync_timer_|. |
| 150 base::TimeDelta sync_delay_; | 147 base::TimeDelta sync_delay_; |
| 151 | 148 |
| 152 // Listen to extension load, unloaded notifications. | 149 // Listen to extension load, unloaded notifications. |
| 153 ScopedObserver<extensions::ExtensionRegistry, | 150 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
| 154 extensions::ExtensionRegistryObserver> | |
| 155 extension_registry_observer_; | 151 extension_registry_observer_; |
| 156 | 152 |
| 157 ObserverList<Observer> observers_; | 153 ObserverList<Observer> observers_; |
| 158 }; | 154 }; |
| 159 | 155 |
| 160 } // namespace apps | 156 } // namespace extensions |
| 161 | 157 |
| 162 #endif // APPS_APP_WINDOW_GEOMETRY_CACHE_H_ | 158 #endif // EXTENSIONS_BROWSER_APP_WINDOW_APP_WINDOW_GEOMETRY_CACHE_H_ |
| OLD | NEW |