| 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> |
| 11 | 11 |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/time.h" | 14 #include "base/time.h" |
| 15 #include "base/timer.h" | 15 #include "base/timer.h" |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
| 18 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
| 19 #include "ui/base/ui_base_types.h" |
| 19 #include "ui/gfx/rect.h" | 20 #include "ui/gfx/rect.h" |
| 20 | 21 |
| 21 class Profile; | 22 class Profile; |
| 22 | 23 |
| 23 namespace extensions { | 24 namespace extensions { |
| 24 | 25 |
| 25 class ExtensionPrefs; | 26 class ExtensionPrefs; |
| 26 | 27 |
| 27 // A cache for persisted geometry of shell windows, both to not have to wait | 28 // A cache for persisted geometry of shell windows, both to not have to wait |
| 28 // for IO when creating a new window, and to not cause IO on every window | 29 // for IO when creating a new window, and to not cause IO on every window |
| 29 // geometry change. | 30 // geometry change. |
| 30 class ShellWindowGeometryCache | 31 class ShellWindowGeometryCache |
| 31 : public base::SupportsWeakPtr<ShellWindowGeometryCache>, | 32 : public base::SupportsWeakPtr<ShellWindowGeometryCache>, |
| 32 public content::NotificationObserver { | 33 public content::NotificationObserver { |
| 33 public: | 34 public: |
| 34 ShellWindowGeometryCache(Profile* profile, | 35 ShellWindowGeometryCache(Profile* profile, |
| 35 ExtensionPrefs* prefs); | 36 ExtensionPrefs* prefs); |
| 36 | 37 |
| 37 virtual ~ShellWindowGeometryCache(); | 38 virtual ~ShellWindowGeometryCache(); |
| 38 | 39 |
| 40 // Save the geometry and state associated with |extension_id| and |window_id|. |
| 39 void SaveGeometry(const std::string& extension_id, | 41 void SaveGeometry(const std::string& extension_id, |
| 40 const std::string& window_id, | 42 const std::string& window_id, |
| 41 const gfx::Rect& bounds); | 43 const gfx::Rect& bounds, |
| 44 ui::WindowShowState state); |
| 42 | 45 |
| 46 // Get any saved geometry and state associated with |extension_id| and |
| 47 // |window_id|. If saved data exists, sets |bounds| and |state| if not NULL |
| 48 // and returns true. |
| 43 bool GetGeometry(const std::string& extension_id, | 49 bool GetGeometry(const std::string& extension_id, |
| 44 const std::string& window_id, | 50 const std::string& window_id, |
| 45 gfx::Rect* bounds) const; | 51 gfx::Rect* bounds, |
| 52 ui::WindowShowState* state) const; |
| 46 | 53 |
| 47 // Maximum number of windows we'll cache the geometry for per app. | 54 // Maximum number of windows we'll cache the geometry for per app. |
| 48 static const size_t kMaxCachedWindows = 100; | 55 static const size_t kMaxCachedWindows = 100; |
| 49 | 56 |
| 50 protected: | 57 protected: |
| 51 friend class ShellWindowGeometryCacheTest; | 58 friend class ShellWindowGeometryCacheTest; |
| 52 | 59 |
| 53 // For tests, this modifies the timeout delay for saving changes from calls | 60 // For tests, this modifies the timeout delay for saving changes from calls |
| 54 // to SaveGeometry. (Note that even if this is set to 0, you still need to | 61 // to SaveGeometry. (Note that even if this is set to 0, you still need to |
| 55 // run the message loop to see the results of any SyncToStorage call). | 62 // run the message loop to see the results of any SyncToStorage call). |
| 56 void SetSyncDelayForTests(int timeout_ms); | 63 void SetSyncDelayForTests(int timeout_ms); |
| 57 | 64 |
| 58 private: | 65 private: |
| 59 // Data stored for each window. | 66 // Data stored for each window. |
| 60 struct WindowData { | 67 struct WindowData { |
| 68 WindowData() : window_state(ui::SHOW_STATE_DEFAULT) {} |
| 61 gfx::Rect bounds; | 69 gfx::Rect bounds; |
| 70 ui::WindowShowState window_state; |
| 62 base::Time last_change; | 71 base::Time last_change; |
| 63 }; | 72 }; |
| 64 | 73 |
| 65 // Data stored for each extension. | 74 // Data stored for each extension. |
| 66 typedef std::map<std::string, WindowData> ExtensionData; | 75 typedef std::map<std::string, WindowData> ExtensionData; |
| 67 | 76 |
| 68 // content::NotificationObserver | 77 // content::NotificationObserver |
| 69 virtual void Observe(int type, | 78 virtual void Observe(int type, |
| 70 const content::NotificationSource& source, | 79 const content::NotificationSource& source, |
| 71 const content::NotificationDetails& details) OVERRIDE; | 80 const content::NotificationDetails& details) OVERRIDE; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 88 | 97 |
| 89 // The timeout value we'll use for |sync_timer_|. | 98 // The timeout value we'll use for |sync_timer_|. |
| 90 base::TimeDelta sync_delay_; | 99 base::TimeDelta sync_delay_; |
| 91 | 100 |
| 92 content::NotificationRegistrar registrar_; | 101 content::NotificationRegistrar registrar_; |
| 93 }; | 102 }; |
| 94 | 103 |
| 95 } // namespace extensions | 104 } // namespace extensions |
| 96 | 105 |
| 97 #endif // CHROME_BROWSER_EXTENSIONS_SHELL_WINDOW_GEOMETRY_CACHE_H_ | 106 #endif // CHROME_BROWSER_EXTENSIONS_SHELL_WINDOW_GEOMETRY_CACHE_H_ |
| OLD | NEW |