Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_SHELL_WINDOW_GEOMETRY_CACHE_H_ | |
| 6 #define CHROME_BROWSER_EXTENSIONS_SHELL_WINDOW_GEOMETRY_CACHE_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <set> | |
| 10 #include <string> | |
| 11 | |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/memory/weak_ptr.h" | |
| 14 #include "base/timer.h" | |
| 15 #include "base/values.h" | |
| 16 #include "content/public/browser/notification_observer.h" | |
| 17 #include "content/public/browser/notification_registrar.h" | |
| 18 #include "ui/gfx/rect.h" | |
| 19 | |
| 20 class Profile; | |
| 21 | |
| 22 namespace extensions { | |
| 23 | |
| 24 class StateStore; | |
| 25 | |
| 26 // A cache for persisted geometry of shell windows, both to not have to wait | |
| 27 // for IO when creating a new window, and to not cause IO on every window | |
| 28 // geometry change | |
|
asargent_no_longer_on_chrome
2012/08/28 18:49:41
nit: finish paragraph with a period.
Marijn Kruisselbrink
2012/08/28 22:14:58
Done.
| |
| 29 class ShellWindowGeometryCache | |
| 30 : public base::SupportsWeakPtr<ShellWindowGeometryCache>, | |
| 31 public content::NotificationObserver { | |
| 32 public: | |
| 33 ShellWindowGeometryCache(Profile* profile, StateStore* state_store); | |
| 34 | |
| 35 virtual ~ShellWindowGeometryCache(); | |
| 36 | |
| 37 void SaveWindowGeometry(const std::string& extension_id, | |
|
asargent_no_longer_on_chrome
2012/08/28 18:49:41
optional suggestion: "SaveGeometry" and "GetGeomet
Marijn Kruisselbrink
2012/08/28 22:14:58
Done.
| |
| 38 const std::string& window_id, | |
| 39 const gfx::Rect& bounds); | |
| 40 | |
| 41 bool GetWindowGeometry(const std::string& extension_id, | |
| 42 const std::string& window_id, | |
| 43 gfx::Rect* bounds) const; | |
| 44 | |
| 45 protected: | |
| 46 void OnExtensionLoaded(const std::string& extension_id); | |
| 47 void OnExtensionUnloaded(const std::string& extension_id); | |
| 48 private: | |
| 49 // content::NotificationObserver | |
| 50 virtual void Observe(int type, | |
| 51 const content::NotificationSource& source, | |
| 52 const content::NotificationDetails& details) OVERRIDE; | |
| 53 | |
| 54 void GeometryFromStorage(const std::string& extension_id, | |
| 55 scoped_ptr<base::Value> value); | |
| 56 | |
| 57 void SyncToStorage(); | |
| 58 | |
| 59 // State store. | |
| 60 StateStore* store_; | |
| 61 | |
| 62 // Cached data | |
| 63 std::map<std::string, std::map<std::string, gfx::Rect> > cache_; | |
| 64 | |
| 65 // Data that still needs saving | |
| 66 std::set<std::string> unsynced_extensions_; | |
| 67 | |
| 68 // The timer used to save the data | |
| 69 base::OneShotTimer<ShellWindowGeometryCache> sync_timer_; | |
| 70 | |
| 71 content::NotificationRegistrar registrar_; | |
| 72 }; | |
| 73 | |
| 74 } // namespace extensions | |
| 75 | |
| 76 #endif // CHROME_BROWSER_EXTENSIONS_SHELL_WINDOW_GEOMETRY_CACHE_H_ | |
| OLD | NEW |