summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-23 00:58:23 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-23 00:58:23 +0000
commit45644f6cc27340a43cddec94054c0c90ef65b7c9 (patch)
tree18aa26a314a5ff51bc82c40cb709427ebe8a754a /content
parentffe38f8add90e8c29055cd2aed4937ed5c45273a (diff)
downloadchromium_src-45644f6cc27340a43cddec94054c0c90ef65b7c9.zip
chromium_src-45644f6cc27340a43cddec94054c0c90ef65b7c9.tar.gz
chromium_src-45644f6cc27340a43cddec94054c0c90ef65b7c9.tar.bz2
Move PropertyBag to base. Originally this was in chrome\common because only chrome used it. Now that chrome and content use it, and that we want to only expose interface through the content API, this belongs in base.
BUG=98716 Review URL: http://codereview.chromium.org/8652002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111266 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r--content/browser/renderer_host/render_widget_host.h8
-rw-r--r--content/browser/tab_contents/tab_contents.h8
-rw-r--r--content/common/property_bag.cc56
-rw-r--r--content/common/property_bag.h176
-rw-r--r--content/common/property_bag_unittest.cc62
-rw-r--r--content/content_common.gypi2
-rw-r--r--content/content_tests.gypi1
7 files changed, 8 insertions, 305 deletions
diff --git a/content/browser/renderer_host/render_widget_host.h b/content/browser/renderer_host/render_widget_host.h
index 8552d4d..2ed1e50 100644
--- a/content/browser/renderer_host/render_widget_host.h
+++ b/content/browser/renderer_host/render_widget_host.h
@@ -14,10 +14,10 @@
#include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h"
#include "base/process_util.h"
+#include "base/property_bag.h"
#include "base/string16.h"
#include "base/timer.h"
#include "content/common/content_export.h"
-#include "content/common/property_bag.h"
#include "content/public/browser/native_web_keyboard_event.h"
#include "content/public/common/page_zoom.h"
#include "ipc/ipc_channel.h"
@@ -166,8 +166,8 @@ class CONTENT_EXPORT RenderWidgetHost : public IPC::Channel::Listener,
// Returns the property bag for this widget, where callers can add extra data
// they may wish to associate with it. Returns a pointer rather than a
// reference since the PropertyAccessors expect this.
- const PropertyBag* property_bag() const { return &property_bag_; }
- PropertyBag* property_bag() { return &property_bag_; }
+ const base::PropertyBag* property_bag() const { return &property_bag_; }
+ base::PropertyBag* property_bag() { return &property_bag_; }
// Called when a renderer object already been created for this host, and we
// just need to be attached to it. Used for window.open, <select> dropdown
@@ -631,7 +631,7 @@ class CONTENT_EXPORT RenderWidgetHost : public IPC::Channel::Listener,
content::RenderProcessHost* process_;
// Stores random bits of data for others to associate with this object.
- PropertyBag property_bag_;
+ base::PropertyBag property_bag_;
// The ID of the corresponding object in the Renderer Instance.
int routing_id_;
diff --git a/content/browser/tab_contents/tab_contents.h b/content/browser/tab_contents/tab_contents.h
index 9f7dd31..846a8f5 100644
--- a/content/browser/tab_contents/tab_contents.h
+++ b/content/browser/tab_contents/tab_contents.h
@@ -14,6 +14,7 @@
#include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h"
#include "base/observer_list.h"
+#include "base/property_bag.h"
#include "base/string16.h"
#include "content/browser/download/save_package.h"
#include "content/browser/javascript_dialogs.h"
@@ -26,7 +27,6 @@
#include "content/browser/tab_contents/tab_contents_observer.h"
#include "content/browser/webui/web_ui.h"
#include "content/common/content_export.h"
-#include "content/common/property_bag.h"
#include "content/public/common/renderer_preferences.h"
#include "net/base/load_states.h"
#include "ui/gfx/native_widget_types.h"
@@ -87,8 +87,8 @@ class CONTENT_EXPORT TabContents : public PageNavigator,
// Returns the property bag for this tab contents, where callers can add
// extra data they may wish to associate with the tab. Returns a pointer
// rather than a reference since the PropertyAccessors expect this.
- const PropertyBag* property_bag() const { return &property_bag_; }
- PropertyBag* property_bag() { return &property_bag_; }
+ const base::PropertyBag* property_bag() const { return &property_bag_; }
+ base::PropertyBag* property_bag() { return &property_bag_; }
TabContentsDelegate* delegate() const { return delegate_; }
void set_delegate(TabContentsDelegate* delegate);
@@ -734,7 +734,7 @@ class CONTENT_EXPORT TabContents : public PageNavigator,
// Stores random bits of data for others to associate with this object.
// WARNING: this needs to be deleted after NavigationController.
- PropertyBag property_bag_;
+ base::PropertyBag property_bag_;
// Data for core operation ---------------------------------------------------
diff --git a/content/common/property_bag.cc b/content/common/property_bag.cc
deleted file mode 100644
index ec3cc5c..0000000
--- a/content/common/property_bag.cc
+++ /dev/null
@@ -1,56 +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/memory/linked_ptr.h"
-#include "content/common/property_bag.h"
-
-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++;
-}
diff --git a/content/common/property_bag.h b/content/common/property_bag.h
deleted file mode 100644
index b83cc58..0000000
--- a/content/common/property_bag.h
+++ /dev/null
@@ -1,176 +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 CONTENT_COMMON_PROPERTY_BAG_H_
-#define CONTENT_COMMON_PROPERTY_BAG_H_
-#pragma once
-
-#include <map>
-
-#include "base/basictypes.h"
-#include "content/common/content_export.h"
-
-template <typename T>
-class linked_ptr;
-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 CONTENT_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 CONTENT_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);
-};
-
-#endif // CONTENT_COMMON_PROPERTY_BAG_H_
diff --git a/content/common/property_bag_unittest.cc b/content/common/property_bag_unittest.cc
deleted file mode 100644
index ed84099..0000000
--- a/content/common/property_bag_unittest.cc
+++ /dev/null
@@ -1,62 +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 "content/common/property_bag.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-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(&copy, 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(&copy));
- ASSERT_TRUE(adaptor2.GetProperty(&copy));
- EXPECT_EQ(kType1Value, *adaptor1.GetProperty(&copy));
- EXPECT_EQ(kType2Value, *adaptor2.GetProperty(&copy));
-
- // Clear it out, neither property should be left.
- copy = PropertyBag();
- EXPECT_TRUE(adaptor1.GetProperty(&copy) == NULL);
- EXPECT_TRUE(adaptor2.GetProperty(&copy) == NULL);
-}
diff --git a/content/content_common.gypi b/content/content_common.gypi
index 15c0201..9471689 100644
--- a/content/content_common.gypi
+++ b/content/content_common.gypi
@@ -209,8 +209,6 @@
'common/process_watcher_mac.cc',
'common/process_watcher_posix.cc',
'common/process_watcher_win.cc',
- 'common/property_bag.cc',
- 'common/property_bag.h',
'common/quota_messages.h',
'common/quota_dispatcher.cc',
'common/quota_dispatcher.h',
diff --git a/content/content_tests.gypi b/content/content_tests.gypi
index e95c636..aa97203 100644
--- a/content/content_tests.gypi
+++ b/content/content_tests.gypi
@@ -227,7 +227,6 @@
'common/net/url_fetcher_impl_unittest.cc',
'common/page_zoom_unittest.cc',
'common/process_watcher_unittest.cc',
- 'common/property_bag_unittest.cc',
'common/resource_dispatcher_unittest.cc',
'gpu/gpu_info_collector_unittest.cc',
'gpu/gpu_info_collector_unittest_win.cc',