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

Side by Side Diff: apps/shell_window_geometry_cache.cc

Issue 14636012: Move ShellWindowGeometryCache into apps (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: PKS dependency Created 7 years, 7 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
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 #include "chrome/browser/extensions/shell_window_geometry_cache.h" 5 #include "apps/shell_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/extensions/extension_prefs.h" 10 #include "chrome/browser/extensions/extension_prefs.h"
11 #include "chrome/browser/extensions/extension_system.h"
12 #include "chrome/browser/extensions/extension_system_factory.h"
13 #include "chrome/browser/profiles/incognito_helpers.h"
14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/profiles/profile_dependency_manager.h"
11 #include "chrome/common/chrome_notification_types.h" 16 #include "chrome/common/chrome_notification_types.h"
12 #include "chrome/common/extensions/extension.h" 17 #include "chrome/common/extensions/extension.h"
13 #include "content/public/browser/notification_service.h" 18 #include "content/public/browser/notification_service.h"
14 #include "content/public/browser/notification_types.h" 19 #include "content/public/browser/notification_types.h"
15 20
16 namespace { 21 namespace {
17 22
18 // 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
19 // StateStore. 24 // StateStore.
20 const int kSyncTimeoutMilliseconds = 1000; 25 const int kSyncTimeoutMilliseconds = 1000;
21 26
22 } // namespace 27 } // namespace
23 28
24 namespace extensions { 29 namespace apps {
25 30
26 ShellWindowGeometryCache::ShellWindowGeometryCache(Profile* profile, 31 ShellWindowGeometryCache::ShellWindowGeometryCache(
27 ExtensionPrefs* prefs) 32 Profile* profile, extensions::ExtensionPrefs* prefs)
28 : prefs_(prefs), 33 : prefs_(prefs),
29 sync_delay_(base::TimeDelta::FromMilliseconds(kSyncTimeoutMilliseconds)) { 34 sync_delay_(base::TimeDelta::FromMilliseconds(kSyncTimeoutMilliseconds)) {
30 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, 35 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
31 content::Source<Profile>(profile)); 36 content::Source<Profile>(profile));
32 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, 37 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
33 content::Source<Profile>(profile)); 38 content::Source<Profile>(profile));
34 } 39 }
35 40
36 ShellWindowGeometryCache::~ShellWindowGeometryCache() { 41 ShellWindowGeometryCache::~ShellWindowGeometryCache() {
37 SyncToStorage(); 42 }
43
44 // static
45 ShellWindowGeometryCache* ShellWindowGeometryCache::Get(
46 content::BrowserContext* context) {
47 return Factory::GetForContext(context, true /* create */);
38 } 48 }
39 49
40 void ShellWindowGeometryCache::SaveGeometry( 50 void ShellWindowGeometryCache::SaveGeometry(
41 const std::string& extension_id, 51 const std::string& extension_id,
42 const std::string& window_id, 52 const std::string& window_id,
43 const gfx::Rect& bounds, 53 const gfx::Rect& bounds,
44 ui::WindowShowState window_state) { 54 ui::WindowShowState window_state) {
45 ExtensionData& extension_data = cache_[extension_id]; 55 ExtensionData& extension_data = cache_[extension_id];
46 56
47 // If we don't have any unsynced changes and this is a duplicate of what's 57 // If we don't have any unsynced changes and this is a duplicate of what's
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 if (window_data == extension_data_it->second.end()) 140 if (window_data == extension_data_it->second.end())
131 return false; 141 return false;
132 142
133 if (bounds) 143 if (bounds)
134 *bounds = window_data->second.bounds; 144 *bounds = window_data->second.bounds;
135 if (window_state) 145 if (window_state)
136 *window_state = window_data->second.window_state; 146 *window_state = window_data->second.window_state;
137 return true; 147 return true;
138 } 148 }
139 149
150 void ShellWindowGeometryCache::Shutdown() {
151 SyncToStorage();
152 }
153
140 void ShellWindowGeometryCache::Observe( 154 void ShellWindowGeometryCache::Observe(
141 int type, const content::NotificationSource& source, 155 int type, const content::NotificationSource& source,
142 const content::NotificationDetails& details) { 156 const content::NotificationDetails& details) {
143 switch (type) { 157 switch (type) {
144 case chrome::NOTIFICATION_EXTENSION_LOADED: { 158 case chrome::NOTIFICATION_EXTENSION_LOADED: {
145 std::string extension_id = 159 std::string extension_id =
146 content::Details<const Extension>(details).ptr()->id(); 160 content::Details<const extensions::Extension>(details).ptr()->id();
147 OnExtensionLoaded(extension_id); 161 OnExtensionLoaded(extension_id);
148 break; 162 break;
149 } 163 }
150 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { 164 case chrome::NOTIFICATION_EXTENSION_UNLOADED: {
151 std::string extension_id = 165 std::string extension_id =
152 content::Details<const UnloadedExtensionInfo>(details). 166 content::Details<const extensions::UnloadedExtensionInfo>(details).
153 ptr()->extension->id(); 167 ptr()->extension->id();
154 OnExtensionUnloaded(extension_id); 168 OnExtensionUnloaded(extension_id);
155 break; 169 break;
156 } 170 }
157 default: 171 default:
158 NOTREACHED(); 172 NOTREACHED();
159 return; 173 return;
160 } 174 }
161 } 175 }
162 176
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 } 223 }
210 } 224 }
211 } 225 }
212 226
213 void ShellWindowGeometryCache::OnExtensionUnloaded( 227 void ShellWindowGeometryCache::OnExtensionUnloaded(
214 const std::string& extension_id) { 228 const std::string& extension_id) {
215 SyncToStorage(); 229 SyncToStorage();
216 cache_.erase(extension_id); 230 cache_.erase(extension_id);
217 } 231 }
218 232
219 } // namespace extensions 233 ///////////////////////////////////////////////////////////////////////////////
234 // Factory boilerplate
235
236 // static
237 ShellWindowGeometryCache* ShellWindowGeometryCache::Factory::GetForContext(
238 content::BrowserContext* context, bool create) {
239 return static_cast<ShellWindowGeometryCache*>(
240 GetInstance()->GetServiceForProfile(context, create));
241 }
242
243 ShellWindowGeometryCache::Factory*
244 ShellWindowGeometryCache::Factory::GetInstance() {
245 return Singleton<ShellWindowGeometryCache::Factory>::get();
246 }
247
248 ShellWindowGeometryCache::Factory::Factory()
249 : ProfileKeyedServiceFactory("ShellWindowGeometryCache",
250 ProfileDependencyManager::GetInstance()) {
251 DependsOn(extensions::ExtensionSystemFactory::GetInstance());
252 }
253
254 ShellWindowGeometryCache::Factory::~Factory() {
255 }
256
257 ProfileKeyedService*
258 ShellWindowGeometryCache::Factory::BuildServiceInstanceFor(
259 content::BrowserContext* context) const {
260 Profile* profile = Profile::FromBrowserContext(context);
261 return new ShellWindowGeometryCache(
262 profile,
263 extensions::ExtensionSystem::Get(profile)->extension_prefs());
264 }
265
266 bool ShellWindowGeometryCache::Factory::ServiceIsNULLWhileTesting() const {
267 return false;
268 }
269
270 content::BrowserContext*
271 ShellWindowGeometryCache::Factory::GetBrowserContextToUse(
272 content::BrowserContext* context) const {
273 return chrome::GetBrowserContextRedirectedInIncognito(context);
274 }
275
276 } // namespace apps
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698