diff options
author | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-23 00:03:11 +0000 |
---|---|---|
committer | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-23 00:03:11 +0000 |
commit | 36a22c4003317b933133d474f49cb5f97ed37e90 (patch) | |
tree | cd4ef16c2bbf798a73b1dda6058dde7c10d02415 /base | |
parent | 7cee190f9eaf5b9715057b2c66d8804fa34ed442 (diff) | |
download | chromium_src-36a22c4003317b933133d474f49cb5f97ed37e90.zip chromium_src-36a22c4003317b933133d474f49cb5f97ed37e90.tar.gz chromium_src-36a22c4003317b933133d474f49cb5f97ed37e90.tar.bz2 |
Kill PropertyBag, switch WebContents to SupportsUserData.
BUG=141177
TEST=no visible change
Review URL: https://chromiumcodereview.appspot.com/10831407
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152882 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/base.gyp | 1 | ||||
-rw-r--r-- | base/base.gypi | 2 | ||||
-rw-r--r-- | base/property_bag.cc | 61 | ||||
-rw-r--r-- | base/property_bag.h | 179 | ||||
-rw-r--r-- | base/property_bag_unittest.cc | 66 |
5 files changed, 0 insertions, 309 deletions
diff --git a/base/base.gyp b/base/base.gyp index 7db29d4..f620ef0 100644 --- a/base/base.gyp +++ b/base/base.gyp @@ -453,7 +453,6 @@ 'process_util_unittest_mac.h', 'process_util_unittest_mac.mm', 'profiler/tracked_time_unittest.cc', - 'property_bag_unittest.cc', 'rand_util_unittest.cc', 'scoped_native_library_unittest.cc', 'scoped_observer.h', diff --git a/base/base.gypi b/base/base.gypi index 1ba5daa..7d25444 100644 --- a/base/base.gypi +++ b/base/base.gypi @@ -312,8 +312,6 @@ 'profiler/alternate_timer.h', 'profiler/tracked_time.cc', 'profiler/tracked_time.h', - 'property_bag.cc', - 'property_bag.h', 'rand_util.cc', 'rand_util.h', 'rand_util_nacl.cc', diff --git a/base/property_bag.cc b/base/property_bag.cc deleted file mode 100644 index 9578e64..0000000 --- a/base/property_bag.cc +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/property_bag.h" - -#include "base/memory/linked_ptr.h" - -namespace base { - -PropertyBag::PropertyBag() { -} - -PropertyBag::PropertyBag(const PropertyBag& other) { - operator=(other); -} - -PropertyBag::~PropertyBag() { -} - -PropertyBag& PropertyBag::operator=(const PropertyBag& other) { - props_.clear(); - - // We need to make copies of each property using the virtual copy() method. - for (PropertyMap::const_iterator i = other.props_.begin(); - i != other.props_.end(); ++i) - props_[i->first] = linked_ptr<Prop>(i->second->copy()); - return *this; -} - -void PropertyBag::SetProperty(PropID id, Prop* prop) { - props_[id] = linked_ptr<Prop>(prop); -} - -PropertyBag::Prop* PropertyBag::GetProperty(PropID id) { - PropertyMap::const_iterator found = props_.find(id); - if (found == props_.end()) - return NULL; - 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()) - return; // Not found, nothing to do. - props_.erase(found); -} - -PropertyAccessorBase::PropertyAccessorBase() { - static PropertyBag::PropID next_id = 1; - prop_id_ = next_id++; -} - -} // namespace base diff --git a/base/property_bag.h b/base/property_bag.h deleted file mode 100644 index 16c20fa..0000000 --- a/base/property_bag.h +++ /dev/null @@ -1,179 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef BASE_PROPERTY_BAG_H_ -#define BASE_PROPERTY_BAG_H_ - -#include <map> - -#include "base/basictypes.h" -#include "base/base_export.h" - -template <typename T> class linked_ptr; - -namespace base { - -class PropertyAccessorBase; - -// A property bag holds a generalized list of arbitrary metadata called -// properties. Each property is a class type derived from PropertyBag::Prop -// that can be set and retrieved. -// -// The property bag is not read or written directly. Instead, callers go -// through a PropertyAccessor. The Accessor generates the unique IDs that -// identify different properties. The Accessor is templatized to also provide -// typesafety to the callers. -// -// Example: -// // Note: you don't want to use Singleton for your Accessor if you're using -// // a simple type like int or string as the data, since it will enforce that -// // there is only one singleton for that type, which will conflict. If -// // you're putting in some struct that's unique to you, go ahead. -// PropertyAccessor<int>* my_accessor() const { -// static PropertyAccessor<int>* accessor = NULL; -// if (!accessor) accessor = new PropertyAccessor<int>; -// return accessor; -// } -// -// void doit(SomeObjectThatImplementsPropertyBag* object) { -// PropertyAccessor<int>* accessor = my_accessor(); -// int* property = accessor->GetProperty(object); -// if (property) -// ... use property ... -// -// accessor->SetProperty(object, 22); -// } -class BASE_EXPORT PropertyBag { - public: - // The type that uniquely identifies a property type. - typedef int PropID; - enum { NULL_PROP_ID = -1 }; // Invalid property ID. - - // Properties are all derived from this class. They must be deletable and - // copyable - class Prop { - public: - virtual ~Prop() {} - - // Copies the property and returns a pointer to the new one. The caller is - // responsible for managing the lifetime. - virtual Prop* copy() = 0; - }; - - PropertyBag(); - PropertyBag(const PropertyBag& other); - virtual ~PropertyBag(); - - PropertyBag& operator=(const PropertyBag& other); - - private: - friend class PropertyAccessorBase; - - typedef std::map<PropID, linked_ptr<Prop> > PropertyMap; - - // Used by the PropertyAccessor to set the property with the given ID. - // Ownership of the given pointer will be transferred to us. Any existing - // property matching the given ID will be deleted. - void SetProperty(PropID id, Prop* prop); - - // Used by the PropertyAccessor to retrieve the property with the given ID. - // 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); - - PropertyMap props_; - - // Copy and assign is explicitly allowed for this class. -}; - -// PropertyAccessorBase ------------------------------------------------------- - -// Manages getting the unique IDs to identify a property. Callers should use -// PropertyAccessor below instead. -class BASE_EXPORT PropertyAccessorBase { - public: - PropertyAccessorBase(); - virtual ~PropertyAccessorBase() {} - - // Removes our property, if any, from the given property bag. - void DeleteProperty(PropertyBag* bag) { - bag->DeleteProperty(prop_id_); - } - - protected: - void SetPropertyInternal(PropertyBag* bag, PropertyBag::Prop* prop) { - bag->SetProperty(prop_id_, prop); - } - 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. - PropertyBag::PropID prop_id_; - - DISALLOW_COPY_AND_ASSIGN(PropertyAccessorBase); -}; - -// PropertyAccessor ----------------------------------------------------------- - -// Provides typesafe accessor functions for a property bag, and manages the -// unique identifiers for properties via the PropertyAccessorBase. -template<class T> -class PropertyAccessor : public PropertyAccessorBase { - public: - PropertyAccessor() : PropertyAccessorBase() {} - virtual ~PropertyAccessor() {} - - // Makes a copy of the |prop| object for storage. - void SetProperty(PropertyBag* bag, const T& prop) { - SetPropertyInternal(bag, new Container(prop)); - } - - // Returns our property in the given bag or NULL if there is no match. The - // returned pointer's ownership will stay with the property bag. - T* GetProperty(PropertyBag* bag) { - PropertyBag::Prop* prop = GetPropertyInternal(bag); - if (!prop) - return NULL; - return static_cast<Container*>(prop)->get(); - } - const T* GetProperty(const PropertyBag* bag) const { - const PropertyBag::Prop* prop = GetPropertyInternal(bag); - if (!prop) - return NULL; - return static_cast<const Container*>(prop)->get(); - } - - // See also DeleteProperty on thn PropertyAccessorBase. - - private: - class Container : public PropertyBag::Prop { - public: - explicit Container(const T& data) : data_(data) {} - - T* get() { return &data_; } - const T* get() const { return &data_; } - - private: - virtual Prop* copy() { - return new Container(data_); - } - - T data_; - }; - - DISALLOW_COPY_AND_ASSIGN(PropertyAccessor); -}; - -} // namespace base - -#endif // BASE_PROPERTY_BAG_H_ diff --git a/base/property_bag_unittest.cc b/base/property_bag_unittest.cc deleted file mode 100644 index b267d04..0000000 --- a/base/property_bag_unittest.cc +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/property_bag.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace base { - -TEST(PropertyBagTest, AddQueryRemove) { - PropertyBag bag; - PropertyAccessor<int> adaptor; - - // Should be no match initially. - EXPECT_TRUE(adaptor.GetProperty(&bag) == NULL); - - // Add the value and make sure we get it back. - const int kFirstValue = 1; - adaptor.SetProperty(&bag, kFirstValue); - ASSERT_TRUE(adaptor.GetProperty(&bag)); - EXPECT_EQ(kFirstValue, *adaptor.GetProperty(&bag)); - - // Set it to a new value. - const int kSecondValue = 2; - adaptor.SetProperty(&bag, kSecondValue); - ASSERT_TRUE(adaptor.GetProperty(&bag)); - EXPECT_EQ(kSecondValue, *adaptor.GetProperty(&bag)); - - // Remove the value and make sure it's gone. - adaptor.DeleteProperty(&bag); - EXPECT_TRUE(adaptor.GetProperty(&bag) == NULL); -} - -TEST(PropertyBagTest, Copy) { - PropertyAccessor<int> adaptor1; - PropertyAccessor<double> adaptor2; - - // Create a bag with property type 1 in it. - PropertyBag copy; - adaptor1.SetProperty(©, 22); - - const int kType1Value = 10; - const double kType2Value = 2.7; - { - // Create a bag with property types 1 and 2 in it. - PropertyBag initial; - adaptor1.SetProperty(&initial, kType1Value); - adaptor2.SetProperty(&initial, kType2Value); - - // Assign to the original. - copy = initial; - } - - // Verify the copy got the two properties. - ASSERT_TRUE(adaptor1.GetProperty(©)); - ASSERT_TRUE(adaptor2.GetProperty(©)); - EXPECT_EQ(kType1Value, *adaptor1.GetProperty(©)); - EXPECT_EQ(kType2Value, *adaptor2.GetProperty(©)); - - // Clear it out, neither property should be left. - copy = PropertyBag(); - EXPECT_TRUE(adaptor1.GetProperty(©) == NULL); - EXPECT_TRUE(adaptor2.GetProperty(©) == NULL); -} - -} // namespace base |