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

Side by Side Diff: apps/shell_window_geometry_cache.h

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/apps.gypi ('k') | apps/shell_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 CHROME_BROWSER_EXTENSIONS_SHELL_WINDOW_GEOMETRY_CACHE_H_
6 #define CHROME_BROWSER_EXTENSIONS_SHELL_WINDOW_GEOMETRY_CACHE_H_ 6 #define CHROME_BROWSER_EXTENSIONS_SHELL_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/weak_ptr.h" 13 #include "base/memory/singleton.h"
14 #include "base/time.h" 14 #include "base/time.h"
15 #include "base/timer.h" 15 #include "base/timer.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "chrome/browser/profiles/profile_keyed_service.h"
18 #include "chrome/browser/profiles/profile_keyed_service_factory.h"
17 #include "content/public/browser/notification_observer.h" 19 #include "content/public/browser/notification_observer.h"
18 #include "content/public/browser/notification_registrar.h" 20 #include "content/public/browser/notification_registrar.h"
19 #include "ui/base/ui_base_types.h" 21 #include "ui/base/ui_base_types.h"
20 #include "ui/gfx/rect.h" 22 #include "ui/gfx/rect.h"
21 23
22 class Profile; 24 class Profile;
23 25
24 namespace extensions { 26 namespace extensions {
27 class ExtensionPrefs;
28 }
25 29
26 class ExtensionPrefs; 30 namespace apps {
27 31
28 // A cache for persisted geometry of shell windows, both to not have to wait 32 // A cache for persisted geometry of shell windows, both to not have to wait
29 // for IO when creating a new window, and to not cause IO on every window 33 // for IO when creating a new window, and to not cause IO on every window
30 // geometry change. 34 // geometry change.
31 class ShellWindowGeometryCache 35 class ShellWindowGeometryCache
32 : public base::SupportsWeakPtr<ShellWindowGeometryCache>, 36 : public ProfileKeyedService,
33 public content::NotificationObserver { 37 public content::NotificationObserver {
34 public: 38 public:
39 class Factory : public ProfileKeyedServiceFactory {
40 public:
41 static ShellWindowGeometryCache* GetForContext(
42 content::BrowserContext* context,
43 bool create);
44
45 static Factory* GetInstance();
46 private:
47 friend struct DefaultSingletonTraits<Factory>;
48
49 Factory();
50 virtual ~Factory();
51
52 // ProfileKeyedServiceFactory
53 virtual ProfileKeyedService* BuildServiceInstanceFor(
54 content::BrowserContext* context) const OVERRIDE;
55 virtual bool ServiceIsNULLWhileTesting() const OVERRIDE;
56 virtual content::BrowserContext* GetBrowserContextToUse(
57 content::BrowserContext* context) const OVERRIDE;
58 };
59
35 ShellWindowGeometryCache(Profile* profile, 60 ShellWindowGeometryCache(Profile* profile,
36 ExtensionPrefs* prefs); 61 extensions::ExtensionPrefs* prefs);
37 62
38 virtual ~ShellWindowGeometryCache(); 63 virtual ~ShellWindowGeometryCache();
39 64
65 // Returns the instance for the given browsing context.
66 static ShellWindowGeometryCache* Get(content::BrowserContext* context);
67
40 // Save the geometry and state associated with |extension_id| and |window_id|. 68 // Save the geometry and state associated with |extension_id| and |window_id|.
41 void SaveGeometry(const std::string& extension_id, 69 void SaveGeometry(const std::string& extension_id,
42 const std::string& window_id, 70 const std::string& window_id,
43 const gfx::Rect& bounds, 71 const gfx::Rect& bounds,
44 ui::WindowShowState state); 72 ui::WindowShowState state);
45 73
46 // Get any saved geometry and state associated with |extension_id| and 74 // Get any saved geometry and state associated with |extension_id| and
47 // |window_id|. If saved data exists, sets |bounds| and |state| if not NULL 75 // |window_id|. If saved data exists, sets |bounds| and |state| if not NULL
48 // and returns true. 76 // and returns true.
49 bool GetGeometry(const std::string& extension_id, 77 bool GetGeometry(const std::string& extension_id,
50 const std::string& window_id, 78 const std::string& window_id,
51 gfx::Rect* bounds, 79 gfx::Rect* bounds,
52 ui::WindowShowState* state) const; 80 ui::WindowShowState* state) const;
53 81
82 // ProfileKeyedService
83 virtual void Shutdown() OVERRIDE;
84
54 // Maximum number of windows we'll cache the geometry for per app. 85 // Maximum number of windows we'll cache the geometry for per app.
55 static const size_t kMaxCachedWindows = 100; 86 static const size_t kMaxCachedWindows = 100;
56 87
57 protected: 88 protected:
58 friend class ShellWindowGeometryCacheTest; 89 friend class ShellWindowGeometryCacheTest;
59 90
60 // For tests, this modifies the timeout delay for saving changes from calls 91 // For tests, this modifies the timeout delay for saving changes from calls
61 // to SaveGeometry. (Note that even if this is set to 0, you still need to 92 // to SaveGeometry. (Note that even if this is set to 0, you still need to
62 // run the message loop to see the results of any SyncToStorage call). 93 // run the message loop to see the results of any SyncToStorage call).
63 void SetSyncDelayForTests(int timeout_ms); 94 void SetSyncDelayForTests(int timeout_ms);
(...skipping 13 matching lines...) Expand all
77 // content::NotificationObserver 108 // content::NotificationObserver
78 virtual void Observe(int type, 109 virtual void Observe(int type,
79 const content::NotificationSource& source, 110 const content::NotificationSource& source,
80 const content::NotificationDetails& details) OVERRIDE; 111 const content::NotificationDetails& details) OVERRIDE;
81 112
82 void OnExtensionLoaded(const std::string& extension_id); 113 void OnExtensionLoaded(const std::string& extension_id);
83 void OnExtensionUnloaded(const std::string& extension_id); 114 void OnExtensionUnloaded(const std::string& extension_id);
84 void SyncToStorage(); 115 void SyncToStorage();
85 116
86 // Preferences storage. 117 // Preferences storage.
87 ExtensionPrefs* prefs_; 118 extensions::ExtensionPrefs* prefs_;
88 119
89 // Cached data 120 // Cached data
90 std::map<std::string, ExtensionData> cache_; 121 std::map<std::string, ExtensionData> cache_;
91 122
92 // Data that still needs saving 123 // Data that still needs saving
93 std::set<std::string> unsynced_extensions_; 124 std::set<std::string> unsynced_extensions_;
94 125
95 // The timer used to save the data 126 // The timer used to save the data
96 base::OneShotTimer<ShellWindowGeometryCache> sync_timer_; 127 base::OneShotTimer<ShellWindowGeometryCache> sync_timer_;
97 128
98 // The timeout value we'll use for |sync_timer_|. 129 // The timeout value we'll use for |sync_timer_|.
99 base::TimeDelta sync_delay_; 130 base::TimeDelta sync_delay_;
100 131
101 content::NotificationRegistrar registrar_; 132 content::NotificationRegistrar registrar_;
102 }; 133 };
103 134
104 } // namespace extensions 135 } // namespace apps
105 136
106 #endif // CHROME_BROWSER_EXTENSIONS_SHELL_WINDOW_GEOMETRY_CACHE_H_ 137 #endif // CHROME_BROWSER_EXTENSIONS_SHELL_WINDOW_GEOMETRY_CACHE_H_
OLDNEW
« no previous file with comments | « apps/apps.gypi ('k') | apps/shell_window_geometry_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698