From 76960a40e09420ac2e302f4b307c4dd0d8a61ce8 Mon Sep 17 00:00:00 2001 From: "brettw@google.com" Date: Fri, 12 Dec 2008 20:16:50 +0000 Subject: Add PropertyBag to TabContents. Convert the autocomplete state as a proof of concept. Add necessary const accessors to property bag. BUG=5260 Review URL: http://codereview.chromium.org/13707 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6920 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/common/property_bag.cc | 7 +++++++ chrome/common/property_bag.h | 11 +++++++++++ 2 files changed, 18 insertions(+) (limited to 'chrome/common') diff --git a/chrome/common/property_bag.cc b/chrome/common/property_bag.cc index f7c92a3..dc25961 100644 --- a/chrome/common/property_bag.cc +++ b/chrome/common/property_bag.cc @@ -35,6 +35,13 @@ PropertyBag::Prop* PropertyBag::GetProperty(PropID id) { return found->second.get(); } +const PropertyBag::Prop* PropertyBag::GetProperty(PropID id) const { + PropertyMap::const_iterator found = props_.find(id); + if (found == props_.end()) + return NULL; + return found->second.get(); +} + void PropertyBag::DeleteProperty(PropID id) { PropertyMap::iterator found = props_.find(id); if (found == props_.end()) diff --git a/chrome/common/property_bag.h b/chrome/common/property_bag.h index 9965382..d2f3559 100644 --- a/chrome/common/property_bag.h +++ b/chrome/common/property_bag.h @@ -77,6 +77,7 @@ class PropertyBag { // The returned pointer will be NULL if there is no match. Ownership of the // pointer will stay with the property bag. Prop* GetProperty(PropID id); + const Prop* GetProperty(PropID id) const; // Deletes the property with the given ID from the bag if it exists. void DeleteProperty(PropID id); @@ -107,6 +108,9 @@ class PropertyAccessorBase { PropertyBag::Prop* GetPropertyInternal(PropertyBag* bag) { return bag->GetProperty(prop_id_); } + const PropertyBag::Prop* GetPropertyInternal(const PropertyBag* bag) const { + return bag->GetProperty(prop_id_); + } private: // Identifier for this property. @@ -140,6 +144,12 @@ class PropertyAccessor : public PropertyAccessorBase { return NULL; return static_cast(prop)->get(); } + const T* GetProperty(const PropertyBag* bag) const { + const PropertyBag::Prop* prop = GetPropertyInternal(bag); + if (!prop) + return NULL; + return static_cast(prop)->get(); + } // See also DeleteProperty on thn PropertyAccessorBase. @@ -149,6 +159,7 @@ class PropertyAccessor : public PropertyAccessorBase { Container(const T& data) : data_(data) {} T* get() { return &data_; } + const T* get() const { return &data_; } private: virtual Prop* copy() { -- cgit v1.1