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

Unified Diff: chrome/browser/tab_contents/web_contents_user_data.h

Issue 10868115: Create base class for TabHelpers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: VS makes me sad 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
« no previous file with comments | « no previous file | chrome/browser/tab_contents/web_contents_user_data_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/tab_contents/web_contents_user_data.h
diff --git a/chrome/browser/tab_contents/web_contents_user_data.h b/chrome/browser/tab_contents/web_contents_user_data.h
new file mode 100644
index 0000000000000000000000000000000000000000..00fd9ab5051af4b469bf08583b26b54ec2b7a21d
--- /dev/null
+++ b/chrome/browser/tab_contents/web_contents_user_data.h
@@ -0,0 +1,41 @@
+// 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_TAB_CONTENTS_WEB_CONTENTS_USER_DATA_H_
+#define CHROME_BROWSER_TAB_CONTENTS_WEB_CONTENTS_USER_DATA_H_
+
+#include "base/supports_user_data.h"
+#include "content/public/browser/web_contents.h"
+
+// A base class for classes attached to, and scoped to, the lifetime of a
+// WebContents. For example:
+//
+// --- in foo_tab_helper.h ---
+// class FooTabHelper : public WebContentsUserData<FooTabHelper> {
+// public:
+// explicit FooTabHelper(content::WebContents* contents);
+// virtual ~FooTabHelper();
+// static int kUserDataKey;
sky 2012/09/12 00:03:13 If this isn't constant, shouldn't it be named user
Avi (use Gerrit) 2012/09/12 00:08:44 The key to the puzzle is that its value is irrelev
+// // ... more stuff here ...
+// }
+// --- in foo_tab_helper.cc ---
+// int FooTabHelper::kUserDataKey;
+//
+template <typename T>
+class WebContentsUserData : public base::SupportsUserData::Data {
+ public:
+ // Creates an object of type T, and attaches it to the specified WebContents.
+ static void CreateForWebContents(content::WebContents* contents) {
+ contents->SetUserData(&T::kUserDataKey, new T(contents));
+ }
+
+ // Retrieves the instance of type T that was attached to the specified
+ // WebContents (via CreateForWebContents above) and returns it. If no instance
+ // of the type was attached, returns NULL.
+ static T* FromWebContents(content::WebContents* contents) {
+ return static_cast<T*>(contents->GetUserData(&T::kUserDataKey));
+ }
+};
+
+#endif // CHROME_BROWSER_TAB_CONTENTS_WEB_CONTENTS_USER_DATA_H_
« no previous file with comments | « no previous file | chrome/browser/tab_contents/web_contents_user_data_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698