OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_BROWSER_EXTENSIONS_SHELL_WINDOW_GEOMETRY_CACHE_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_SHELL_WINDOW_GEOMETRY_CACHE_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_SHELL_WINDOW_GEOMETRY_CACHE_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_SHELL_WINDOW_GEOMETRY_CACHE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 15 matching lines...) Expand all Loading... |
26 namespace extensions { | 26 namespace extensions { |
27 class ExtensionPrefs; | 27 class ExtensionPrefs; |
28 } | 28 } |
29 | 29 |
30 namespace apps { | 30 namespace apps { |
31 | 31 |
32 // A cache for persisted geometry of shell windows, both to not have to wait | 32 // A cache for persisted geometry of shell windows, both to not have to wait |
33 // for IO when creating a new window, and to not cause IO on every window | 33 // for IO when creating a new window, and to not cause IO on every window |
34 // geometry change. | 34 // geometry change. |
35 class ShellWindowGeometryCache | 35 class ShellWindowGeometryCache |
36 : public ProfileKeyedService, | 36 : public BrowserContextKeyedService, |
37 public content::NotificationObserver { | 37 public content::NotificationObserver { |
38 public: | 38 public: |
39 class Factory : public ProfileKeyedServiceFactory { | 39 class Factory : public BrowserContextKeyedServiceFactory { |
40 public: | 40 public: |
41 static ShellWindowGeometryCache* GetForContext( | 41 static ShellWindowGeometryCache* GetForContext( |
42 content::BrowserContext* context, | 42 content::BrowserContext* context, |
43 bool create); | 43 bool create); |
44 | 44 |
45 static Factory* GetInstance(); | 45 static Factory* GetInstance(); |
46 private: | 46 private: |
47 friend struct DefaultSingletonTraits<Factory>; | 47 friend struct DefaultSingletonTraits<Factory>; |
48 | 48 |
49 Factory(); | 49 Factory(); |
50 virtual ~Factory(); | 50 virtual ~Factory(); |
51 | 51 |
52 // ProfileKeyedServiceFactory | 52 // BrowserContextKeyedServiceFactory |
53 virtual ProfileKeyedService* BuildServiceInstanceFor( | 53 virtual BrowserContextKeyedService* BuildServiceInstanceFor( |
54 content::BrowserContext* context) const OVERRIDE; | 54 content::BrowserContext* context) const OVERRIDE; |
55 virtual bool ServiceIsNULLWhileTesting() const OVERRIDE; | 55 virtual bool ServiceIsNULLWhileTesting() const OVERRIDE; |
56 virtual content::BrowserContext* GetBrowserContextToUse( | 56 virtual content::BrowserContext* GetBrowserContextToUse( |
57 content::BrowserContext* context) const OVERRIDE; | 57 content::BrowserContext* context) const OVERRIDE; |
58 }; | 58 }; |
59 | 59 |
60 ShellWindowGeometryCache(Profile* profile, | 60 ShellWindowGeometryCache(Profile* profile, |
61 extensions::ExtensionPrefs* prefs); | 61 extensions::ExtensionPrefs* prefs); |
62 | 62 |
63 virtual ~ShellWindowGeometryCache(); | 63 virtual ~ShellWindowGeometryCache(); |
64 | 64 |
65 // Returns the instance for the given browsing context. | 65 // Returns the instance for the given browsing context. |
66 static ShellWindowGeometryCache* Get(content::BrowserContext* context); | 66 static ShellWindowGeometryCache* Get(content::BrowserContext* context); |
67 | 67 |
68 // Save the geometry and state associated with |extension_id| and |window_id|. | 68 // Save the geometry and state associated with |extension_id| and |window_id|. |
69 void SaveGeometry(const std::string& extension_id, | 69 void SaveGeometry(const std::string& extension_id, |
70 const std::string& window_id, | 70 const std::string& window_id, |
71 const gfx::Rect& bounds, | 71 const gfx::Rect& bounds, |
72 ui::WindowShowState state); | 72 ui::WindowShowState state); |
73 | 73 |
74 // Get any saved geometry and state associated with |extension_id| and | 74 // Get any saved geometry and state associated with |extension_id| and |
75 // |window_id|. If saved data exists, sets |bounds| and |state| if not NULL | 75 // |window_id|. If saved data exists, sets |bounds| and |state| if not NULL |
76 // and returns true. | 76 // and returns true. |
77 bool GetGeometry(const std::string& extension_id, | 77 bool GetGeometry(const std::string& extension_id, |
78 const std::string& window_id, | 78 const std::string& window_id, |
79 gfx::Rect* bounds, | 79 gfx::Rect* bounds, |
80 ui::WindowShowState* state) const; | 80 ui::WindowShowState* state) const; |
81 | 81 |
82 // ProfileKeyedService | 82 // BrowserContextKeyedService |
83 virtual void Shutdown() OVERRIDE; | 83 virtual void Shutdown() OVERRIDE; |
84 | 84 |
85 // Maximum number of windows we'll cache the geometry for per app. | 85 // Maximum number of windows we'll cache the geometry for per app. |
86 static const size_t kMaxCachedWindows = 100; | 86 static const size_t kMaxCachedWindows = 100; |
87 | 87 |
88 protected: | 88 protected: |
89 friend class ShellWindowGeometryCacheTest; | 89 friend class ShellWindowGeometryCacheTest; |
90 | 90 |
91 // For tests, this modifies the timeout delay for saving changes from calls | 91 // For tests, this modifies the timeout delay for saving changes from calls |
92 // to SaveGeometry. (Note that even if this is set to 0, you still need to | 92 // to SaveGeometry. (Note that even if this is set to 0, you still need to |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 | 128 |
129 // The timeout value we'll use for |sync_timer_|. | 129 // The timeout value we'll use for |sync_timer_|. |
130 base::TimeDelta sync_delay_; | 130 base::TimeDelta sync_delay_; |
131 | 131 |
132 content::NotificationRegistrar registrar_; | 132 content::NotificationRegistrar registrar_; |
133 }; | 133 }; |
134 | 134 |
135 } // namespace apps | 135 } // namespace apps |
136 | 136 |
137 #endif // CHROME_BROWSER_EXTENSIONS_SHELL_WINDOW_GEOMETRY_CACHE_H_ | 137 #endif // CHROME_BROWSER_EXTENSIONS_SHELL_WINDOW_GEOMETRY_CACHE_H_ |
OLD | NEW |