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 APPS_APP_WINDOW_GEOMETRY_CACHE_H_ |
6 #define APPS_APP_WINDOW_GEOMETRY_CACHE_H_ | 6 #define APPS_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/time/time.h" | 16 #include "base/time/time.h" |
16 #include "base/timer/timer.h" | 17 #include "base/timer/timer.h" |
17 #include "base/values.h" | 18 #include "base/values.h" |
18 #include "components/keyed_service/content/browser_context_keyed_service_factory
.h" | 19 #include "components/keyed_service/content/browser_context_keyed_service_factory
.h" |
19 #include "components/keyed_service/core/keyed_service.h" | 20 #include "components/keyed_service/core/keyed_service.h" |
20 #include "content/public/browser/notification_observer.h" | 21 #include "extensions/browser/extension_registry_observer.h" |
21 #include "content/public/browser/notification_registrar.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 class Profile; | 25 class Profile; |
26 | 26 |
27 namespace extensions { | 27 namespace extensions { |
28 class ExtensionPrefs; | 28 class ExtensionPrefs; |
| 29 class ExtensionRegistry; |
29 } | 30 } |
30 | 31 |
31 namespace apps { | 32 namespace apps { |
32 | 33 |
33 // A cache for persisted geometry of app windows, both to not have to wait | 34 // A cache for persisted geometry of app windows, both to not have to wait |
34 // for IO when creating a new window, and to not cause IO on every window | 35 // for IO when creating a new window, and to not cause IO on every window |
35 // geometry change. | 36 // geometry change. |
36 class AppWindowGeometryCache : public KeyedService, | 37 class AppWindowGeometryCache : public KeyedService, |
37 public content::NotificationObserver { | 38 public extensions::ExtensionRegistryObserver { |
38 public: | 39 public: |
39 class Factory : public BrowserContextKeyedServiceFactory { | 40 class Factory : public BrowserContextKeyedServiceFactory { |
40 public: | 41 public: |
41 static AppWindowGeometryCache* GetForContext( | 42 static AppWindowGeometryCache* GetForContext( |
42 content::BrowserContext* context, | 43 content::BrowserContext* context, |
43 bool create); | 44 bool create); |
44 | 45 |
45 static Factory* GetInstance(); | 46 static Factory* GetInstance(); |
46 | 47 |
47 private: | 48 private: |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 ~WindowData(); | 116 ~WindowData(); |
116 gfx::Rect bounds; | 117 gfx::Rect bounds; |
117 gfx::Rect screen_bounds; | 118 gfx::Rect screen_bounds; |
118 ui::WindowShowState window_state; | 119 ui::WindowShowState window_state; |
119 base::Time last_change; | 120 base::Time last_change; |
120 }; | 121 }; |
121 | 122 |
122 // Data stored for each extension. | 123 // Data stored for each extension. |
123 typedef std::map<std::string, WindowData> ExtensionData; | 124 typedef std::map<std::string, WindowData> ExtensionData; |
124 | 125 |
125 // content::NotificationObserver | 126 // ExtensionRegistryObserver implementation. |
126 virtual void Observe(int type, | 127 virtual void OnExtensionLoaded( |
127 const content::NotificationSource& source, | 128 content::BrowserContext* browser_context, |
128 const content::NotificationDetails& details) OVERRIDE; | 129 const extensions::Extension* extension) OVERRIDE; |
| 130 virtual void OnExtensionUnloaded( |
| 131 content::BrowserContext* browser_context, |
| 132 const extensions::Extension* extension, |
| 133 extensions::UnloadedExtensionInfo::Reason reason) OVERRIDE; |
129 | 134 |
130 void LoadGeometryFromStorage(const std::string& extension_id); | 135 void LoadGeometryFromStorage(const std::string& extension_id); |
131 void OnExtensionUnloaded(const std::string& extension_id); | |
132 void SyncToStorage(); | 136 void SyncToStorage(); |
133 | 137 |
134 // Preferences storage. | 138 // Preferences storage. |
135 extensions::ExtensionPrefs* prefs_; | 139 extensions::ExtensionPrefs* prefs_; |
136 | 140 |
137 // Cached data | 141 // Cached data. |
138 std::map<std::string, ExtensionData> cache_; | 142 std::map<std::string, ExtensionData> cache_; |
139 | 143 |
140 // Data that still needs saving | 144 // Data that still needs saving. |
141 std::set<std::string> unsynced_extensions_; | 145 std::set<std::string> unsynced_extensions_; |
142 | 146 |
143 // The timer used to save the data | 147 // The timer used to save the data. |
144 base::OneShotTimer<AppWindowGeometryCache> sync_timer_; | 148 base::OneShotTimer<AppWindowGeometryCache> sync_timer_; |
145 | 149 |
146 // The timeout value we'll use for |sync_timer_|. | 150 // The timeout value we'll use for |sync_timer_|. |
147 base::TimeDelta sync_delay_; | 151 base::TimeDelta sync_delay_; |
148 | 152 |
149 content::NotificationRegistrar registrar_; | 153 // Listen to extension load, unloaded notifications. |
| 154 ScopedObserver<extensions::ExtensionRegistry, |
| 155 extensions::ExtensionRegistryObserver> |
| 156 extension_registry_observer_; |
| 157 |
150 ObserverList<Observer> observers_; | 158 ObserverList<Observer> observers_; |
151 }; | 159 }; |
152 | 160 |
153 } // namespace apps | 161 } // namespace apps |
154 | 162 |
155 #endif // APPS_APP_WINDOW_GEOMETRY_CACHE_H_ | 163 #endif // APPS_APP_WINDOW_GEOMETRY_CACHE_H_ |
OLD | NEW |