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

Side by Side Diff: chrome/browser/tab_contents/web_contents_user_data.h

Issue 10873101: Revert 153571 - Create base class for TabHelpers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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 // class FooTabHelper : public WebContentsUserData<FooTabHelper> {
15 // public:
16 // explicit FooTabHelper(content::WebContents* contents);
17 // virtual ~FooTabHelper();
18 //
19 template <typename T>
20 class WebContentsUserData : public base::SupportsUserData::Data {
21 public:
22 // Creates an object of type T, and attaches it to the specified WebContents.
23 static void CreateForWebContents(content::WebContents* contents) {
24 void* key = reinterpret_cast<void*>(&CreateForWebContents);
25 contents->SetUserData(key, new T(contents));
26 }
27
28 // Retrieves the instance of type T that was attached to the specified
29 // WebContents (via CreateForWebContents above) and returns it. If no instance
30 // of the type was attached, returns NULL.
31 static T* FromWebContents(content::WebContents* contents) {
32 void* key = reinterpret_cast<void*>(&CreateForWebContents);
33 return static_cast<T*>(contents->GetUserData(key));
34 }
35 };
36
37 #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