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