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 #include "apps/shell_window_geometry_cache.h" | 5 #include "apps/app_window_geometry_cache.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
11 #include "chrome/browser/profiles/incognito_helpers.h" | 11 #include "chrome/browser/profiles/incognito_helpers.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "components/browser_context_keyed_service/browser_context_dependency_ma
nager.h" | 13 #include "components/browser_context_keyed_service/browser_context_dependency_ma
nager.h" |
14 #include "content/public/browser/notification_service.h" | 14 #include "content/public/browser/notification_service.h" |
15 #include "content/public/browser/notification_types.h" | 15 #include "content/public/browser/notification_types.h" |
16 #include "extensions/browser/extension_prefs.h" | 16 #include "extensions/browser/extension_prefs.h" |
17 #include "extensions/browser/extension_prefs_factory.h" | 17 #include "extensions/browser/extension_prefs_factory.h" |
18 #include "extensions/browser/extensions_browser_client.h" | 18 #include "extensions/browser/extensions_browser_client.h" |
19 #include "extensions/common/extension.h" | 19 #include "extensions/common/extension.h" |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 // The timeout in milliseconds before we'll persist window geometry to the | 23 // The timeout in milliseconds before we'll persist window geometry to the |
24 // StateStore. | 24 // StateStore. |
25 const int kSyncTimeoutMilliseconds = 1000; | 25 const int kSyncTimeoutMilliseconds = 1000; |
26 | 26 |
27 } // namespace | 27 } // namespace |
28 | 28 |
29 namespace apps { | 29 namespace apps { |
30 | 30 |
31 ShellWindowGeometryCache::ShellWindowGeometryCache( | 31 AppWindowGeometryCache::AppWindowGeometryCache( |
32 Profile* profile, extensions::ExtensionPrefs* prefs) | 32 Profile* profile, |
| 33 extensions::ExtensionPrefs* prefs) |
33 : prefs_(prefs), | 34 : prefs_(prefs), |
34 sync_delay_(base::TimeDelta::FromMilliseconds(kSyncTimeoutMilliseconds)) { | 35 sync_delay_(base::TimeDelta::FromMilliseconds(kSyncTimeoutMilliseconds)) { |
35 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 36 registrar_.Add(this, |
| 37 chrome::NOTIFICATION_EXTENSION_LOADED, |
36 content::Source<Profile>(profile)); | 38 content::Source<Profile>(profile)); |
37 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 39 registrar_.Add(this, |
| 40 chrome::NOTIFICATION_EXTENSION_UNLOADED, |
38 content::Source<Profile>(profile)); | 41 content::Source<Profile>(profile)); |
39 } | 42 } |
40 | 43 |
41 ShellWindowGeometryCache::~ShellWindowGeometryCache() { | 44 AppWindowGeometryCache::~AppWindowGeometryCache() {} |
42 } | |
43 | 45 |
44 // static | 46 // static |
45 ShellWindowGeometryCache* ShellWindowGeometryCache::Get( | 47 AppWindowGeometryCache* AppWindowGeometryCache::Get( |
46 content::BrowserContext* context) { | 48 content::BrowserContext* context) { |
47 return Factory::GetForContext(context, true /* create */); | 49 return Factory::GetForContext(context, true /* create */); |
48 } | 50 } |
49 | 51 |
50 void ShellWindowGeometryCache::SaveGeometry( | 52 void AppWindowGeometryCache::SaveGeometry(const std::string& extension_id, |
51 const std::string& extension_id, | 53 const std::string& window_id, |
52 const std::string& window_id, | 54 const gfx::Rect& bounds, |
53 const gfx::Rect& bounds, | 55 const gfx::Rect& screen_bounds, |
54 const gfx::Rect& screen_bounds, | 56 ui::WindowShowState window_state) { |
55 ui::WindowShowState window_state) { | |
56 ExtensionData& extension_data = cache_[extension_id]; | 57 ExtensionData& extension_data = cache_[extension_id]; |
57 | 58 |
58 // If we don't have any unsynced changes and this is a duplicate of what's | 59 // If we don't have any unsynced changes and this is a duplicate of what's |
59 // already in the cache, just ignore it. | 60 // already in the cache, just ignore it. |
60 if (extension_data[window_id].bounds == bounds && | 61 if (extension_data[window_id].bounds == bounds && |
61 extension_data[window_id].window_state == window_state && | 62 extension_data[window_id].window_state == window_state && |
62 extension_data[window_id].screen_bounds == screen_bounds && | 63 extension_data[window_id].screen_bounds == screen_bounds && |
63 !ContainsKey(unsynced_extensions_, extension_id)) | 64 !ContainsKey(unsynced_extensions_, extension_id)) |
64 return; | 65 return; |
65 | 66 |
66 base::Time now = base::Time::Now(); | 67 base::Time now = base::Time::Now(); |
67 | 68 |
68 extension_data[window_id].bounds = bounds; | 69 extension_data[window_id].bounds = bounds; |
69 extension_data[window_id].screen_bounds = screen_bounds; | 70 extension_data[window_id].screen_bounds = screen_bounds; |
70 extension_data[window_id].window_state = window_state; | 71 extension_data[window_id].window_state = window_state; |
71 extension_data[window_id].last_change = now; | 72 extension_data[window_id].last_change = now; |
72 | 73 |
73 if (extension_data.size() > kMaxCachedWindows) { | 74 if (extension_data.size() > kMaxCachedWindows) { |
74 ExtensionData::iterator oldest = extension_data.end(); | 75 ExtensionData::iterator oldest = extension_data.end(); |
75 // Too many windows in the cache, find the oldest one to remove. | 76 // Too many windows in the cache, find the oldest one to remove. |
76 for (ExtensionData::iterator it = extension_data.begin(); | 77 for (ExtensionData::iterator it = extension_data.begin(); |
77 it != extension_data.end(); ++it) { | 78 it != extension_data.end(); |
| 79 ++it) { |
78 // Don't expunge the window that was just added. | 80 // Don't expunge the window that was just added. |
79 if (it->first == window_id) continue; | 81 if (it->first == window_id) |
| 82 continue; |
80 | 83 |
81 // If time is in the future, reset it to now to minimize weirdness. | 84 // If time is in the future, reset it to now to minimize weirdness. |
82 if (it->second.last_change > now) | 85 if (it->second.last_change > now) |
83 it->second.last_change = now; | 86 it->second.last_change = now; |
84 | 87 |
85 if (oldest == extension_data.end() || | 88 if (oldest == extension_data.end() || |
86 it->second.last_change < oldest->second.last_change) | 89 it->second.last_change < oldest->second.last_change) |
87 oldest = it; | 90 oldest = it; |
88 } | 91 } |
89 extension_data.erase(oldest); | 92 extension_data.erase(oldest); |
90 } | 93 } |
91 | 94 |
92 unsynced_extensions_.insert(extension_id); | 95 unsynced_extensions_.insert(extension_id); |
93 | 96 |
94 // We don't use Reset() because the timer may not yet be running. | 97 // We don't use Reset() because the timer may not yet be running. |
95 // (In that case Stop() is a no-op.) | 98 // (In that case Stop() is a no-op.) |
96 sync_timer_.Stop(); | 99 sync_timer_.Stop(); |
97 sync_timer_.Start(FROM_HERE, sync_delay_, this, | 100 sync_timer_.Start( |
98 &ShellWindowGeometryCache::SyncToStorage); | 101 FROM_HERE, sync_delay_, this, &AppWindowGeometryCache::SyncToStorage); |
99 } | 102 } |
100 | 103 |
101 void ShellWindowGeometryCache::SyncToStorage() { | 104 void AppWindowGeometryCache::SyncToStorage() { |
102 std::set<std::string> tosync; | 105 std::set<std::string> tosync; |
103 tosync.swap(unsynced_extensions_); | 106 tosync.swap(unsynced_extensions_); |
104 for (std::set<std::string>::const_iterator it = tosync.begin(), | 107 for (std::set<std::string>::const_iterator it = tosync.begin(), |
105 eit = tosync.end(); it != eit; ++it) { | 108 eit = tosync.end(); |
| 109 it != eit; |
| 110 ++it) { |
106 const std::string& extension_id = *it; | 111 const std::string& extension_id = *it; |
107 const ExtensionData& extension_data = cache_[extension_id]; | 112 const ExtensionData& extension_data = cache_[extension_id]; |
108 | 113 |
109 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); | 114 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); |
110 for (ExtensionData::const_iterator it = extension_data.begin(), | 115 for (ExtensionData::const_iterator it = extension_data.begin(), |
111 eit = extension_data.end(); it != eit; ++it) { | 116 eit = extension_data.end(); |
| 117 it != eit; |
| 118 ++it) { |
112 base::DictionaryValue* value = new base::DictionaryValue; | 119 base::DictionaryValue* value = new base::DictionaryValue; |
113 const gfx::Rect& bounds = it->second.bounds; | 120 const gfx::Rect& bounds = it->second.bounds; |
114 const gfx::Rect& screen_bounds = it->second.screen_bounds; | 121 const gfx::Rect& screen_bounds = it->second.screen_bounds; |
115 DCHECK(!bounds.IsEmpty()); | 122 DCHECK(!bounds.IsEmpty()); |
116 DCHECK(!screen_bounds.IsEmpty()); | 123 DCHECK(!screen_bounds.IsEmpty()); |
117 DCHECK(it->second.window_state != ui::SHOW_STATE_DEFAULT); | 124 DCHECK(it->second.window_state != ui::SHOW_STATE_DEFAULT); |
118 value->SetInteger("x", bounds.x()); | 125 value->SetInteger("x", bounds.x()); |
119 value->SetInteger("y", bounds.y()); | 126 value->SetInteger("y", bounds.y()); |
120 value->SetInteger("w", bounds.width()); | 127 value->SetInteger("w", bounds.width()); |
121 value->SetInteger("h", bounds.height()); | 128 value->SetInteger("h", bounds.height()); |
122 value->SetInteger("screen_bounds_x", screen_bounds.x()); | 129 value->SetInteger("screen_bounds_x", screen_bounds.x()); |
123 value->SetInteger("screen_bounds_y", screen_bounds.y()); | 130 value->SetInteger("screen_bounds_y", screen_bounds.y()); |
124 value->SetInteger("screen_bounds_w", screen_bounds.width()); | 131 value->SetInteger("screen_bounds_w", screen_bounds.width()); |
125 value->SetInteger("screen_bounds_h", screen_bounds.height()); | 132 value->SetInteger("screen_bounds_h", screen_bounds.height()); |
126 value->SetInteger("state", it->second.window_state); | 133 value->SetInteger("state", it->second.window_state); |
127 value->SetString( | 134 value->SetString( |
128 "ts", base::Int64ToString(it->second.last_change.ToInternalValue())); | 135 "ts", base::Int64ToString(it->second.last_change.ToInternalValue())); |
129 dict->SetWithoutPathExpansion(it->first, value); | 136 dict->SetWithoutPathExpansion(it->first, value); |
130 | 137 |
131 FOR_EACH_OBSERVER( | 138 FOR_EACH_OBSERVER( |
132 Observer, | 139 Observer, |
133 observers_, | 140 observers_, |
134 OnGeometryCacheChanged(extension_id, it->first, bounds)); | 141 OnGeometryCacheChanged(extension_id, it->first, bounds)); |
135 } | 142 } |
136 | 143 |
137 prefs_->SetGeometryCache(extension_id, dict.Pass()); | 144 prefs_->SetGeometryCache(extension_id, dict.Pass()); |
138 } | 145 } |
139 } | 146 } |
140 | 147 |
141 bool ShellWindowGeometryCache::GetGeometry( | 148 bool AppWindowGeometryCache::GetGeometry(const std::string& extension_id, |
142 const std::string& extension_id, | 149 const std::string& window_id, |
143 const std::string& window_id, | 150 gfx::Rect* bounds, |
144 gfx::Rect* bounds, | 151 gfx::Rect* screen_bounds, |
145 gfx::Rect* screen_bounds, | 152 ui::WindowShowState* window_state) { |
146 ui::WindowShowState* window_state) { | |
147 | 153 |
148 std::map<std::string, ExtensionData>::const_iterator | 154 std::map<std::string, ExtensionData>::const_iterator extension_data_it = |
149 extension_data_it = cache_.find(extension_id); | 155 cache_.find(extension_id); |
150 | 156 |
151 // Not in the map means loading data for the extension didn't finish yet or | 157 // Not in the map means loading data for the extension didn't finish yet or |
152 // the cache was not constructed until after the extension was loaded. | 158 // the cache was not constructed until after the extension was loaded. |
153 // Attempt to load from sync to address the latter case. | 159 // Attempt to load from sync to address the latter case. |
154 if (extension_data_it == cache_.end()) { | 160 if (extension_data_it == cache_.end()) { |
155 LoadGeometryFromStorage(extension_id); | 161 LoadGeometryFromStorage(extension_id); |
156 extension_data_it = cache_.find(extension_id); | 162 extension_data_it = cache_.find(extension_id); |
157 DCHECK(extension_data_it != cache_.end()); | 163 DCHECK(extension_data_it != cache_.end()); |
158 } | 164 } |
159 | 165 |
160 ExtensionData::const_iterator window_data_it = extension_data_it->second.find( | 166 ExtensionData::const_iterator window_data_it = |
161 window_id); | 167 extension_data_it->second.find(window_id); |
162 | 168 |
163 if (window_data_it == extension_data_it->second.end()) | 169 if (window_data_it == extension_data_it->second.end()) |
164 return false; | 170 return false; |
165 | 171 |
166 const WindowData& window_data = window_data_it->second; | 172 const WindowData& window_data = window_data_it->second; |
167 | 173 |
168 // Check for and do not return corrupt data. | 174 // Check for and do not return corrupt data. |
169 if ((bounds && window_data.bounds.IsEmpty()) || | 175 if ((bounds && window_data.bounds.IsEmpty()) || |
170 (screen_bounds && window_data.screen_bounds.IsEmpty()) || | 176 (screen_bounds && window_data.screen_bounds.IsEmpty()) || |
171 (window_state && window_data.window_state == ui::SHOW_STATE_DEFAULT)) | 177 (window_state && window_data.window_state == ui::SHOW_STATE_DEFAULT)) |
172 return false; | 178 return false; |
173 | 179 |
174 if (bounds) | 180 if (bounds) |
175 *bounds = window_data.bounds; | 181 *bounds = window_data.bounds; |
176 if (screen_bounds) | 182 if (screen_bounds) |
177 *screen_bounds = window_data.screen_bounds; | 183 *screen_bounds = window_data.screen_bounds; |
178 if (window_state) | 184 if (window_state) |
179 *window_state = window_data.window_state; | 185 *window_state = window_data.window_state; |
180 return true; | 186 return true; |
181 } | 187 } |
182 | 188 |
183 void ShellWindowGeometryCache::Shutdown() { | 189 void AppWindowGeometryCache::Shutdown() { SyncToStorage(); } |
184 SyncToStorage(); | |
185 } | |
186 | 190 |
| 191 AppWindowGeometryCache::WindowData::WindowData() |
| 192 : window_state(ui::SHOW_STATE_DEFAULT) {} |
187 | 193 |
188 ShellWindowGeometryCache::WindowData::WindowData() | 194 AppWindowGeometryCache::WindowData::~WindowData() {} |
189 : window_state(ui::SHOW_STATE_DEFAULT) { | |
190 } | |
191 | 195 |
192 ShellWindowGeometryCache::WindowData::~WindowData() { | 196 void AppWindowGeometryCache::Observe( |
193 } | 197 int type, |
194 | 198 const content::NotificationSource& source, |
195 void ShellWindowGeometryCache::Observe( | |
196 int type, const content::NotificationSource& source, | |
197 const content::NotificationDetails& details) { | 199 const content::NotificationDetails& details) { |
198 switch (type) { | 200 switch (type) { |
199 case chrome::NOTIFICATION_EXTENSION_LOADED: { | 201 case chrome::NOTIFICATION_EXTENSION_LOADED: { |
200 std::string extension_id = | 202 std::string extension_id = |
201 content::Details<const extensions::Extension>(details).ptr()->id(); | 203 content::Details<const extensions::Extension>(details).ptr()->id(); |
202 LoadGeometryFromStorage(extension_id); | 204 LoadGeometryFromStorage(extension_id); |
203 break; | 205 break; |
204 } | 206 } |
205 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { | 207 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { |
206 std::string extension_id = | 208 std::string extension_id = |
207 content::Details<const extensions::UnloadedExtensionInfo>(details). | 209 content::Details<const extensions::UnloadedExtensionInfo>(details) |
208 ptr()->extension->id(); | 210 .ptr() |
| 211 ->extension->id(); |
209 OnExtensionUnloaded(extension_id); | 212 OnExtensionUnloaded(extension_id); |
210 break; | 213 break; |
211 } | 214 } |
212 default: | 215 default: |
213 NOTREACHED(); | 216 NOTREACHED(); |
214 return; | 217 return; |
215 } | 218 } |
216 } | 219 } |
217 | 220 |
218 void ShellWindowGeometryCache::SetSyncDelayForTests(int timeout_ms) { | 221 void AppWindowGeometryCache::SetSyncDelayForTests(int timeout_ms) { |
219 sync_delay_ = base::TimeDelta::FromMilliseconds(timeout_ms); | 222 sync_delay_ = base::TimeDelta::FromMilliseconds(timeout_ms); |
220 } | 223 } |
221 | 224 |
222 void ShellWindowGeometryCache::LoadGeometryFromStorage( | 225 void AppWindowGeometryCache::LoadGeometryFromStorage( |
223 const std::string& extension_id) { | 226 const std::string& extension_id) { |
224 ExtensionData& extension_data = cache_[extension_id]; | 227 ExtensionData& extension_data = cache_[extension_id]; |
225 | 228 |
226 const base::DictionaryValue* stored_windows = | 229 const base::DictionaryValue* stored_windows = |
227 prefs_->GetGeometryCache(extension_id); | 230 prefs_->GetGeometryCache(extension_id); |
228 if (!stored_windows) | 231 if (!stored_windows) |
229 return; | 232 return; |
230 | 233 |
231 for (base::DictionaryValue::Iterator it(*stored_windows); !it.IsAtEnd(); | 234 for (base::DictionaryValue::Iterator it(*stored_windows); !it.IsAtEnd(); |
232 it.Advance()) { | 235 it.Advance()) { |
(...skipping 18 matching lines...) Expand all Loading... |
251 window_data.bounds.set_height(i); | 254 window_data.bounds.set_height(i); |
252 if (stored_window->GetInteger("screen_bounds_x", &i)) | 255 if (stored_window->GetInteger("screen_bounds_x", &i)) |
253 window_data.screen_bounds.set_x(i); | 256 window_data.screen_bounds.set_x(i); |
254 if (stored_window->GetInteger("screen_bounds_y", &i)) | 257 if (stored_window->GetInteger("screen_bounds_y", &i)) |
255 window_data.screen_bounds.set_y(i); | 258 window_data.screen_bounds.set_y(i); |
256 if (stored_window->GetInteger("screen_bounds_w", &i)) | 259 if (stored_window->GetInteger("screen_bounds_w", &i)) |
257 window_data.screen_bounds.set_width(i); | 260 window_data.screen_bounds.set_width(i); |
258 if (stored_window->GetInteger("screen_bounds_h", &i)) | 261 if (stored_window->GetInteger("screen_bounds_h", &i)) |
259 window_data.screen_bounds.set_height(i); | 262 window_data.screen_bounds.set_height(i); |
260 if (stored_window->GetInteger("state", &i)) { | 263 if (stored_window->GetInteger("state", &i)) { |
261 window_data.window_state = | 264 window_data.window_state = static_cast<ui::WindowShowState>(i); |
262 static_cast<ui::WindowShowState>(i); | |
263 } | 265 } |
264 std::string ts_as_string; | 266 std::string ts_as_string; |
265 if (stored_window->GetString("ts", &ts_as_string)) { | 267 if (stored_window->GetString("ts", &ts_as_string)) { |
266 int64 ts; | 268 int64 ts; |
267 if (base::StringToInt64(ts_as_string, &ts)) { | 269 if (base::StringToInt64(ts_as_string, &ts)) { |
268 window_data.last_change = base::Time::FromInternalValue(ts); | 270 window_data.last_change = base::Time::FromInternalValue(ts); |
269 } | 271 } |
270 } | 272 } |
271 } | 273 } |
272 } | 274 } |
273 } | 275 } |
274 } | 276 } |
275 | 277 |
276 void ShellWindowGeometryCache::OnExtensionUnloaded( | 278 void AppWindowGeometryCache::OnExtensionUnloaded( |
277 const std::string& extension_id) { | 279 const std::string& extension_id) { |
278 SyncToStorage(); | 280 SyncToStorage(); |
279 cache_.erase(extension_id); | 281 cache_.erase(extension_id); |
280 } | 282 } |
281 | 283 |
282 /////////////////////////////////////////////////////////////////////////////// | 284 /////////////////////////////////////////////////////////////////////////////// |
283 // Factory boilerplate | 285 // Factory boilerplate |
284 | 286 |
285 // static | 287 // static |
286 ShellWindowGeometryCache* ShellWindowGeometryCache::Factory::GetForContext( | 288 AppWindowGeometryCache* AppWindowGeometryCache::Factory::GetForContext( |
287 content::BrowserContext* context, bool create) { | 289 content::BrowserContext* context, |
288 return static_cast<ShellWindowGeometryCache*>( | 290 bool create) { |
| 291 return static_cast<AppWindowGeometryCache*>( |
289 GetInstance()->GetServiceForBrowserContext(context, create)); | 292 GetInstance()->GetServiceForBrowserContext(context, create)); |
290 } | 293 } |
291 | 294 |
292 ShellWindowGeometryCache::Factory* | 295 AppWindowGeometryCache::Factory* |
293 ShellWindowGeometryCache::Factory::GetInstance() { | 296 AppWindowGeometryCache::Factory::GetInstance() { |
294 return Singleton<ShellWindowGeometryCache::Factory>::get(); | 297 return Singleton<AppWindowGeometryCache::Factory>::get(); |
295 } | 298 } |
296 | 299 |
297 ShellWindowGeometryCache::Factory::Factory() | 300 AppWindowGeometryCache::Factory::Factory() |
298 : BrowserContextKeyedServiceFactory( | 301 : BrowserContextKeyedServiceFactory( |
299 "ShellWindowGeometryCache", | 302 "AppWindowGeometryCache", |
300 BrowserContextDependencyManager::GetInstance()) { | 303 BrowserContextDependencyManager::GetInstance()) { |
301 DependsOn(extensions::ExtensionPrefsFactory::GetInstance()); | 304 DependsOn(extensions::ExtensionPrefsFactory::GetInstance()); |
302 } | 305 } |
303 | 306 |
304 ShellWindowGeometryCache::Factory::~Factory() { | 307 AppWindowGeometryCache::Factory::~Factory() {} |
| 308 |
| 309 BrowserContextKeyedService* |
| 310 AppWindowGeometryCache::Factory::BuildServiceInstanceFor( |
| 311 content::BrowserContext* context) const { |
| 312 Profile* profile = Profile::FromBrowserContext(context); |
| 313 return new AppWindowGeometryCache(profile, |
| 314 extensions::ExtensionPrefs::Get(profile)); |
305 } | 315 } |
306 | 316 |
307 BrowserContextKeyedService* | 317 bool AppWindowGeometryCache::Factory::ServiceIsNULLWhileTesting() const { |
308 ShellWindowGeometryCache::Factory::BuildServiceInstanceFor( | |
309 content::BrowserContext* context) const { | |
310 Profile* profile = Profile::FromBrowserContext(context); | |
311 return new ShellWindowGeometryCache( | |
312 profile, | |
313 extensions::ExtensionPrefs::Get(profile)); | |
314 } | |
315 | |
316 bool ShellWindowGeometryCache::Factory::ServiceIsNULLWhileTesting() const { | |
317 return false; | 318 return false; |
318 } | 319 } |
319 | 320 |
320 content::BrowserContext* | 321 content::BrowserContext* |
321 ShellWindowGeometryCache::Factory::GetBrowserContextToUse( | 322 AppWindowGeometryCache::Factory::GetBrowserContextToUse( |
322 content::BrowserContext* context) const { | 323 content::BrowserContext* context) const { |
323 return extensions::ExtensionsBrowserClient::Get()-> | 324 return extensions::ExtensionsBrowserClient::Get()->GetOriginalContext( |
324 GetOriginalContext(context); | 325 context); |
325 } | 326 } |
326 | 327 |
327 void ShellWindowGeometryCache::AddObserver(Observer* observer) { | 328 void AppWindowGeometryCache::AddObserver(Observer* observer) { |
328 observers_.AddObserver(observer); | 329 observers_.AddObserver(observer); |
329 } | 330 } |
330 | 331 |
331 void ShellWindowGeometryCache::RemoveObserver(Observer* observer) { | 332 void AppWindowGeometryCache::RemoveObserver(Observer* observer) { |
332 observers_.RemoveObserver(observer); | 333 observers_.RemoveObserver(observer); |
333 } | 334 } |
334 | 335 |
335 } // namespace apps | 336 } // namespace apps |
OLD | NEW |