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

Side by Side Diff: chrome/browser/view_type_utils.cc

Issue 10831407: Kill PropertyBag, switch WebContents to SupportsUserData. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase only Created 8 years, 4 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 #include "chrome/browser/view_type_utils.h" 5 #include "chrome/browser/view_type_utils.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/property_bag.h"
9 #include "content/public/browser/web_contents.h" 8 #include "content/public/browser/web_contents.h"
10 9
11 using content::WebContents; 10 using content::WebContents;
12 11
13 namespace chrome { 12 namespace chrome {
14 13
15 static base::LazyInstance<base::PropertyAccessor<ViewType> > 14 namespace {
16 g_view_type_property_accessor = LAZY_INSTANCE_INITIALIZER;
17 15
18 base::PropertyAccessor<ViewType>* GetPropertyAccessor() { 16 const char kViewTypeUserDataKey[] = "ViewTypeUserData";
19 return g_view_type_property_accessor.Pointer(); 17
20 } 18 class ViewTypeUserData : public base::SupportsUserData::Data {
19 public:
20 explicit ViewTypeUserData(ViewType type) : type_(type) {}
21 virtual ~ViewTypeUserData() {}
22 ViewType type() { return type_; }
23
24 private:
25 ViewType type_;
26 };
27
28 } // namespace
21 29
22 ViewType GetViewType(WebContents* tab) { 30 ViewType GetViewType(WebContents* tab) {
23 if (!tab) 31 if (!tab)
24 return VIEW_TYPE_INVALID; 32 return VIEW_TYPE_INVALID;
25 ViewType* type = GetPropertyAccessor()->GetProperty(tab->GetPropertyBag()); 33
26 if (type) 34 ViewTypeUserData* user_data = static_cast<ViewTypeUserData*>(
27 return *type; 35 tab->GetUserData(&kViewTypeUserDataKey));
28 return VIEW_TYPE_INVALID; 36
37 return user_data ? user_data->type() : VIEW_TYPE_INVALID;
29 } 38 }
30 39
31 void SetViewType(WebContents* tab, ViewType type) { 40 void SetViewType(WebContents* tab, ViewType type) {
32 GetPropertyAccessor()->SetProperty(tab->GetPropertyBag(), type); 41 tab->SetUserData(&kViewTypeUserDataKey,
42 new ViewTypeUserData(type));
33 } 43 }
34 44
35 } // namespace chrome 45 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/constrained_web_dialog_delegate_base.cc ('k') | content/browser/web_contents/web_contents_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698