summaryrefslogtreecommitdiffstats
path: root/chrome/browser/common
diff options
context:
space:
mode:
authordharani@google.com <dharani@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-28 17:00:14 +0000
committerdharani@google.com <dharani@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-28 17:00:14 +0000
commit3f735995e6a2ed67cb0d4b01b50b058da1179a38 (patch)
treebfb3cb8f485e29ad302662c2662f5374c4df3b5e /chrome/browser/common
parent05adeba6452d76ab39c0c407660df9ec4291e0f7 (diff)
downloadchromium_src-3f735995e6a2ed67cb0d4b01b50b058da1179a38.zip
chromium_src-3f735995e6a2ed67cb0d4b01b50b058da1179a38.tar.gz
chromium_src-3f735995e6a2ed67cb0d4b01b50b058da1179a38.tar.bz2
Revert 159158 - Make using WebContentsUserData simpler.
BUG=107201 TEST=no visible change Reverted due to bug 152950 Review URL: https://chromiumcodereview.appspot.com/10993064 TBR=avi@chromium.org Review URL: https://codereview.chromium.org/10990113 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@159277 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/common')
-rw-r--r--chrome/browser/common/web_contents_user_data.h24
-rw-r--r--chrome/browser/common/web_contents_user_data_unittest.cc10
2 files changed, 13 insertions, 21 deletions
diff --git a/chrome/browser/common/web_contents_user_data.h b/chrome/browser/common/web_contents_user_data.h
index 364997e..2cffb58 100644
--- a/chrome/browser/common/web_contents_user_data.h
+++ b/chrome/browser/common/web_contents_user_data.h
@@ -18,11 +18,12 @@
// // ... more public stuff here ...
// private:
// explicit FooTabHelper(content::WebContents* contents);
+// static int kUserDataKey;
// friend class WebContentsUserData<FooTabHelper>;
// // ... more private stuff here ...
// }
// --- in foo_tab_helper.cc ---
-// DEFINE_WEB_CONTENTS_USER_DATA_KEY(FooTabHelper)
+// int FooTabHelper::kUserDataKey;
//
template <typename T>
class WebContentsUserData : public base::SupportsUserData::Data {
@@ -31,33 +32,18 @@ class WebContentsUserData : public base::SupportsUserData::Data {
// If an instance is already attached, does nothing.
static void CreateForWebContents(content::WebContents* contents) {
if (!FromWebContents(contents))
- contents->SetUserData(&kLocatorKey, new T(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(&kLocatorKey));
+ return static_cast<T*>(contents->GetUserData(&T::kUserDataKey));
}
static const T* FromWebContents(const content::WebContents* contents) {
- return static_cast<const T*>(contents->GetUserData(&kLocatorKey));
+ return static_cast<const T*>(contents->GetUserData(&T::kUserDataKey));
}
-
- // The user data key.
- static int kLocatorKey;
};
-// The macro to define the locator key. This key must be defined in the .cc file
-// of the tab helper otherwise different instances for different template types
-// will be collapsed by the Visual Studio linker.
-//
-// The "= 0" is surprising, but is required to effect a definition rather than
-// a declaration. Without it, this would be merely a declaration of a template
-// specialization. (C++98: 14.7.3.15; C++11: 14.7.3.13)
-//
-#define DEFINE_WEB_CONTENTS_USER_DATA_KEY(TYPE) \
-template<> \
-int WebContentsUserData<TYPE>::kLocatorKey = 0;
-
#endif // CHROME_BROWSER_COMMON_WEB_CONTENTS_USER_DATA_H_
diff --git a/chrome/browser/common/web_contents_user_data_unittest.cc b/chrome/browser/common/web_contents_user_data_unittest.cc
index 1ee3a6a..cb35bac 100644
--- a/chrome/browser/common/web_contents_user_data_unittest.cc
+++ b/chrome/browser/common/web_contents_user_data_unittest.cc
@@ -11,12 +11,15 @@
#include "content/public/test/web_contents_tester.h"
#include "testing/gtest/include/gtest/gtest.h"
+namespace {
+
class WebContentsAttachedClass1
: public WebContentsUserData<WebContentsAttachedClass1> {
public:
virtual ~WebContentsAttachedClass1() {}
private:
explicit WebContentsAttachedClass1(content::WebContents* contents) {}
+ static int kUserDataKey;
friend class WebContentsUserData<WebContentsAttachedClass1>;
};
@@ -26,11 +29,14 @@ class WebContentsAttachedClass2
virtual ~WebContentsAttachedClass2() {}
private:
explicit WebContentsAttachedClass2(content::WebContents* contents) {}
+ static int kUserDataKey;
friend class WebContentsUserData<WebContentsAttachedClass2>;
};
-DEFINE_WEB_CONTENTS_USER_DATA_KEY(WebContentsAttachedClass1)
-DEFINE_WEB_CONTENTS_USER_DATA_KEY(WebContentsAttachedClass2)
+int WebContentsAttachedClass1::kUserDataKey;
+int WebContentsAttachedClass2::kUserDataKey;
+
+} // namespace
typedef ChromeRenderViewHostTestHarness WebContentsUserDataTest;