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

Side by Side Diff: ios/public/provider/web/web_state_user_data.h

Issue 781643004: Cleanup WebState and WebStateUserData API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef IOS_PUBLIC_PROVIDER_WEB_WEB_STATE_USER_DATA_H_ 5 #ifndef IOS_PUBLIC_PROVIDER_WEB_WEB_STATE_USER_DATA_H_
6 #define IOS_PUBLIC_PROVIDER_WEB_WEB_STATE_USER_DATA_H_ 6 #define IOS_PUBLIC_PROVIDER_WEB_WEB_STATE_USER_DATA_H_
7 7
8 #include "ios/public/consumer/base/supports_user_data.h" 8 #include "base/supports_user_data.h"
9 #include "ios/public/provider/web/web_state.h" 9 #include "ios/public/provider/web/web_state.h"
10 10
11 namespace ios { 11 namespace ios {
12 12
13 // A base class for classes attached to, and scoped to, the lifetime of a 13 // A base class for classes attached to, and scoped to, the lifetime of a
14 // WebState. For example: 14 // WebState. For example:
15 // 15 //
16 // --- in foo.h --- 16 // --- in foo.h ---
17 // class Foo : public ios::WebStateUserData<Foo> { 17 // class Foo : public ios::WebStateUserData<Foo> {
18 // public: 18 // public:
19 // virtual ~Foo(); 19 // virtual ~Foo();
20 // // ... more public stuff here ... 20 // // ... more public stuff here ...
21 // private: 21 // private:
22 // explicit Foo(ios::WebState* web_state); 22 // explicit Foo(ios::WebState* web_state);
23 // friend class ios::WebStateUserData<Foo>; 23 // friend class ios::WebStateUserData<Foo>;
24 // // ... more private stuff here ... 24 // // ... more private stuff here ...
25 // } 25 // }
26 // --- in foo.cc --- 26 // --- in foo.cc ---
27 // DEFINE_WEB_CONTENTS_USER_DATA_KEY(Foo); 27 // DEFINE_WEB_CONTENTS_USER_DATA_KEY(Foo);
28 // 28 //
29 template <typename T> 29 template <typename T>
30 class WebStateUserData : public ios::SupportsUserData::Data { 30 class WebStateUserData : public base::SupportsUserData::Data {
droger 2014/12/04 09:39:47 Important: This class needs a virtual destructor.
sdefresne 2014/12/05 14:32:05 Done. But base::SupportsUserData::Data already has
droger 2014/12/05 14:44:33 I think there is a problem in this case, am I wron
droger 2014/12/05 14:57:41 Ok, it turns out I was wrong. As long as the base
31 public: 31 public:
32 // Creates an object of type T, and attaches it to the specified WebState. 32 // Creates an object of type T, and attaches it to the specified WebState.
33 // If an instance is already attached, does nothing. 33 // If an instance is already attached, does nothing.
34 static void CreateForWebState(WebState* web_state) { 34 static void CreateForWebState(WebState* web_state) {
35 if (!FromWebState(web_state)) 35 if (!FromWebState(web_state))
36 web_state->SetUserData(UserDataKey(), new T(web_state)); 36 web_state->SetUserData(UserDataKey(), new T(web_state));
37 } 37 }
38 38
39 // Retrieves the instance of type T that was attached to the specified 39 // Retrieves the instance of type T that was attached to the specified
40 // WebState (via CreateForWebState above) and returns it. If no instance 40 // WebState (via CreateForWebState above) and returns it. If no instance
(...skipping 22 matching lines...) Expand all
63 // a declaration. Without it, this would be merely a declaration of a template 63 // a declaration. Without it, this would be merely a declaration of a template
64 // specialization. (C++98: 14.7.3.15; C++11: 14.7.3.13) 64 // specialization. (C++98: 14.7.3.15; C++11: 14.7.3.13)
65 // 65 //
66 #define DEFINE_WEB_STATE_USER_DATA_KEY(TYPE) \ 66 #define DEFINE_WEB_STATE_USER_DATA_KEY(TYPE) \
67 template<> \ 67 template<> \
68 int ios::WebStateUserData<TYPE>::kLocatorKey = 0 68 int ios::WebStateUserData<TYPE>::kLocatorKey = 0
69 69
70 } // namespace ios 70 } // namespace ios
71 71
72 #endif // IOS_PUBLIC_PROVIDER_WEB_WEB_STATE_USER_DATA_H_ 72 #endif // IOS_PUBLIC_PROVIDER_WEB_WEB_STATE_USER_DATA_H_
OLDNEW
« ios/public/provider/web/web_state.h ('K') | « ios/public/provider/web/web_state.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698