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

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

Powered by Google App Engine
This is Rietveld 408576698