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

Unified Diff: chrome/browser/extensions/shell_window_geometry_cache.h

Issue 10871086: First part of remembering platform app window geometry. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/shell_window_geometry_cache.h
diff --git a/chrome/browser/extensions/shell_window_geometry_cache.h b/chrome/browser/extensions/shell_window_geometry_cache.h
new file mode 100644
index 0000000000000000000000000000000000000000..08acd7e60057ce3c3665e2c6ea19c99401ea1720
--- /dev/null
+++ b/chrome/browser/extensions/shell_window_geometry_cache.h
@@ -0,0 +1,76 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_EXTENSIONS_SHELL_WINDOW_GEOMETRY_CACHE_H_
+#define CHROME_BROWSER_EXTENSIONS_SHELL_WINDOW_GEOMETRY_CACHE_H_
+
+#include <map>
+#include <set>
+#include <string>
+
+#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
+#include "base/timer.h"
+#include "base/values.h"
+#include "content/public/browser/notification_observer.h"
+#include "content/public/browser/notification_registrar.h"
+#include "ui/gfx/rect.h"
+
+class Profile;
+
+namespace extensions {
+
+class StateStore;
+
+// A cache for persisted geometry of shell windows, both to not have to wait
+// for IO when creating a new window, and to not cause IO on every window
+// geometry change
asargent_no_longer_on_chrome 2012/08/28 18:49:41 nit: finish paragraph with a period.
Marijn Kruisselbrink 2012/08/28 22:14:58 Done.
+class ShellWindowGeometryCache
+ : public base::SupportsWeakPtr<ShellWindowGeometryCache>,
+ public content::NotificationObserver {
+ public:
+ ShellWindowGeometryCache(Profile* profile, StateStore* state_store);
+
+ virtual ~ShellWindowGeometryCache();
+
+ void SaveWindowGeometry(const std::string& extension_id,
asargent_no_longer_on_chrome 2012/08/28 18:49:41 optional suggestion: "SaveGeometry" and "GetGeomet
Marijn Kruisselbrink 2012/08/28 22:14:58 Done.
+ const std::string& window_id,
+ const gfx::Rect& bounds);
+
+ bool GetWindowGeometry(const std::string& extension_id,
+ const std::string& window_id,
+ gfx::Rect* bounds) const;
+
+ protected:
+ void OnExtensionLoaded(const std::string& extension_id);
+ void OnExtensionUnloaded(const std::string& extension_id);
+ private:
+ // content::NotificationObserver
+ virtual void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) OVERRIDE;
+
+ void GeometryFromStorage(const std::string& extension_id,
+ scoped_ptr<base::Value> value);
+
+ void SyncToStorage();
+
+ // State store.
+ StateStore* store_;
+
+ // Cached data
+ std::map<std::string, std::map<std::string, gfx::Rect> > cache_;
+
+ // Data that still needs saving
+ std::set<std::string> unsynced_extensions_;
+
+ // The timer used to save the data
+ base::OneShotTimer<ShellWindowGeometryCache> sync_timer_;
+
+ content::NotificationRegistrar registrar_;
+};
+
+} // namespace extensions
+
+#endif // CHROME_BROWSER_EXTENSIONS_SHELL_WINDOW_GEOMETRY_CACHE_H_

Powered by Google App Engine
This is Rietveld 408576698