Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(419)

Side by Side Diff: apps/app_window_geometry_cache.h

Issue 166573005: Rename apps::ShellWindow to apps::AppWindow (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase, nits (rename) Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « apps/app_window_contents.cc ('k') | apps/app_window_geometry_cache.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 APPS_APP_WINDOW_GEOMETRY_CACHE_H_
6 #define CHROME_BROWSER_EXTENSIONS_SHELL_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/time/time.h" 15 #include "base/time/time.h"
16 #include "base/timer/timer.h" 16 #include "base/timer/timer.h"
17 #include "base/values.h" 17 #include "base/values.h"
18 #include "components/browser_context_keyed_service/browser_context_keyed_service .h" 18 #include "components/browser_context_keyed_service/browser_context_keyed_service .h"
19 #include "components/browser_context_keyed_service/browser_context_keyed_service _factory.h" 19 #include "components/browser_context_keyed_service/browser_context_keyed_service _factory.h"
20 #include "content/public/browser/notification_observer.h" 20 #include "content/public/browser/notification_observer.h"
21 #include "content/public/browser/notification_registrar.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 } 29 }
30 30
31 namespace apps { 31 namespace apps {
32 32
33 // A cache for persisted geometry of shell windows, both to not have to wait 33 // 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 34 // for IO when creating a new window, and to not cause IO on every window
35 // geometry change. 35 // geometry change.
36 class ShellWindowGeometryCache 36 class AppWindowGeometryCache : public BrowserContextKeyedService,
37 : public BrowserContextKeyedService, 37 public content::NotificationObserver {
38 public content::NotificationObserver {
39 public: 38 public:
40 class Factory : public BrowserContextKeyedServiceFactory { 39 class Factory : public BrowserContextKeyedServiceFactory {
41 public: 40 public:
42 static ShellWindowGeometryCache* GetForContext( 41 static AppWindowGeometryCache* GetForContext(
43 content::BrowserContext* context, 42 content::BrowserContext* context,
44 bool create); 43 bool create);
45 44
46 static Factory* GetInstance(); 45 static Factory* GetInstance();
46
47 private: 47 private:
48 friend struct DefaultSingletonTraits<Factory>; 48 friend struct DefaultSingletonTraits<Factory>;
49 49
50 Factory(); 50 Factory();
51 virtual ~Factory(); 51 virtual ~Factory();
52 52
53 // BrowserContextKeyedServiceFactory 53 // BrowserContextKeyedServiceFactory
54 virtual BrowserContextKeyedService* BuildServiceInstanceFor( 54 virtual BrowserContextKeyedService* BuildServiceInstanceFor(
55 content::BrowserContext* context) const OVERRIDE; 55 content::BrowserContext* context) const OVERRIDE;
56 virtual bool ServiceIsNULLWhileTesting() const OVERRIDE; 56 virtual bool ServiceIsNULLWhileTesting() const OVERRIDE;
57 virtual content::BrowserContext* GetBrowserContextToUse( 57 virtual content::BrowserContext* GetBrowserContextToUse(
58 content::BrowserContext* context) const OVERRIDE; 58 content::BrowserContext* context) const OVERRIDE;
59 }; 59 };
60 60
61 class Observer { 61 class Observer {
62 public: 62 public:
63 virtual void OnGeometryCacheChanged(const std::string& extension_id, 63 virtual void OnGeometryCacheChanged(const std::string& extension_id,
64 const std::string& window_id, 64 const std::string& window_id,
65 const gfx::Rect& bounds) = 0; 65 const gfx::Rect& bounds) = 0;
66 66
67 protected: 67 protected:
68 virtual ~Observer() {}; 68 virtual ~Observer() {};
69 }; 69 };
70 70
71 ShellWindowGeometryCache(Profile* profile, 71 AppWindowGeometryCache(Profile* profile, extensions::ExtensionPrefs* prefs);
72 extensions::ExtensionPrefs* prefs);
73 72
74 virtual ~ShellWindowGeometryCache(); 73 virtual ~AppWindowGeometryCache();
75 74
76 // Returns the instance for the given browsing context. 75 // Returns the instance for the given browsing context.
77 static ShellWindowGeometryCache* Get(content::BrowserContext* context); 76 static AppWindowGeometryCache* Get(content::BrowserContext* context);
78 77
79 // Save the geometry and state associated with |extension_id| and |window_id|. 78 // Save the geometry and state associated with |extension_id| and |window_id|.
80 void SaveGeometry(const std::string& extension_id, 79 void SaveGeometry(const std::string& extension_id,
81 const std::string& window_id, 80 const std::string& window_id,
82 const gfx::Rect& bounds, 81 const gfx::Rect& bounds,
83 const gfx::Rect& screen_bounds, 82 const gfx::Rect& screen_bounds,
84 ui::WindowShowState state); 83 ui::WindowShowState state);
85 84
86 // Get any saved geometry and state associated with |extension_id| and 85 // Get any saved geometry and state associated with |extension_id| and
87 // |window_id|. If saved data exists, sets |bounds|, |screen_bounds| and 86 // |window_id|. If saved data exists, sets |bounds|, |screen_bounds| and
88 // |state| if not NULL and returns true. 87 // |state| if not NULL and returns true.
89 bool GetGeometry(const std::string& extension_id, 88 bool GetGeometry(const std::string& extension_id,
90 const std::string& window_id, 89 const std::string& window_id,
91 gfx::Rect* bounds, 90 gfx::Rect* bounds,
92 gfx::Rect* screen_bounds, 91 gfx::Rect* screen_bounds,
93 ui::WindowShowState* state); 92 ui::WindowShowState* state);
94 93
95 // BrowserContextKeyedService 94 // BrowserContextKeyedService
96 virtual void Shutdown() OVERRIDE; 95 virtual void Shutdown() OVERRIDE;
97 96
98 void AddObserver(Observer* observer); 97 void AddObserver(Observer* observer);
99 void RemoveObserver(Observer* observer); 98 void RemoveObserver(Observer* observer);
100 99
101 // Maximum number of windows we'll cache the geometry for per app. 100 // Maximum number of windows we'll cache the geometry for per app.
102 static const size_t kMaxCachedWindows = 100; 101 static const size_t kMaxCachedWindows = 100;
103 102
104 protected: 103 protected:
105 friend class ShellWindowGeometryCacheTest; 104 friend class AppWindowGeometryCacheTest;
106 105
107 // For tests, this modifies the timeout delay for saving changes from calls 106 // For tests, this modifies the timeout delay for saving changes from calls
108 // to SaveGeometry. (Note that even if this is set to 0, you still need to 107 // to SaveGeometry. (Note that even if this is set to 0, you still need to
109 // run the message loop to see the results of any SyncToStorage call). 108 // run the message loop to see the results of any SyncToStorage call).
110 void SetSyncDelayForTests(int timeout_ms); 109 void SetSyncDelayForTests(int timeout_ms);
111 110
112 private: 111 private:
113 // Data stored for each window. 112 // Data stored for each window.
114 struct WindowData { 113 struct WindowData {
115 WindowData(); 114 WindowData();
(...skipping 19 matching lines...) Expand all
135 // Preferences storage. 134 // Preferences storage.
136 extensions::ExtensionPrefs* prefs_; 135 extensions::ExtensionPrefs* prefs_;
137 136
138 // Cached data 137 // Cached data
139 std::map<std::string, ExtensionData> cache_; 138 std::map<std::string, ExtensionData> cache_;
140 139
141 // Data that still needs saving 140 // Data that still needs saving
142 std::set<std::string> unsynced_extensions_; 141 std::set<std::string> unsynced_extensions_;
143 142
144 // The timer used to save the data 143 // The timer used to save the data
145 base::OneShotTimer<ShellWindowGeometryCache> sync_timer_; 144 base::OneShotTimer<AppWindowGeometryCache> sync_timer_;
146 145
147 // The timeout value we'll use for |sync_timer_|. 146 // The timeout value we'll use for |sync_timer_|.
148 base::TimeDelta sync_delay_; 147 base::TimeDelta sync_delay_;
149 148
150 content::NotificationRegistrar registrar_; 149 content::NotificationRegistrar registrar_;
151 ObserverList<Observer> observers_; 150 ObserverList<Observer> observers_;
152 }; 151 };
153 152
154 } // namespace apps 153 } // namespace apps
155 154
156 #endif // CHROME_BROWSER_EXTENSIONS_SHELL_WINDOW_GEOMETRY_CACHE_H_ 155 #endif // APPS_APP_WINDOW_GEOMETRY_CACHE_H_
OLDNEW
« no previous file with comments | « apps/app_window_contents.cc ('k') | apps/app_window_geometry_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698