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

Side by Side 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, 3 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 | « no previous file | chrome/browser/tab_contents/web_contents_user_data_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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_TAB_CONTENTS_WEB_CONTENTS_USER_DATA_H_
6 #define CHROME_BROWSER_TAB_CONTENTS_WEB_CONTENTS_USER_DATA_H_
7
8 #include "base/supports_user_data.h"
9 #include "content/public/browser/web_contents.h"
10
11 // A base class for classes attached to, and scoped to, the lifetime of a
12 // WebContents. For example:
13 //
14 // --- in foo_tab_helper.h ---
15 // class FooTabHelper : public WebContentsUserData<FooTabHelper> {
16 // public:
17 // explicit FooTabHelper(content::WebContents* contents);
18 // virtual ~FooTabHelper();
19 // 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
20 // // ... more stuff here ...
21 // }
22 // --- in foo_tab_helper.cc ---
23 // int FooTabHelper::kUserDataKey;
24 //
25 template <typename T>
26 class WebContentsUserData : public base::SupportsUserData::Data {
27 public:
28 // Creates an object of type T, and attaches it to the specified WebContents.
29 static void CreateForWebContents(content::WebContents* contents) {
30 contents->SetUserData(&T::kUserDataKey, new T(contents));
31 }
32
33 // Retrieves the instance of type T that was attached to the specified
34 // WebContents (via CreateForWebContents above) and returns it. If no instance
35 // of the type was attached, returns NULL.
36 static T* FromWebContents(content::WebContents* contents) {
37 return static_cast<T*>(contents->GetUserData(&T::kUserDataKey));
38 }
39 };
40
41 #endif // CHROME_BROWSER_TAB_CONTENTS_WEB_CONTENTS_USER_DATA_H_
OLDNEW
« 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