diff options
Diffstat (limited to 'chrome/browser/common/web_contents_user_data.h')
-rw-r--r-- | chrome/browser/common/web_contents_user_data.h | 24 |
1 files changed, 5 insertions, 19 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_ |