summaryrefslogtreecommitdiffstats
path: root/base/supports_user_data.h
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-15 22:07:34 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-15 22:07:34 +0000
commitea8e1813f4dec2371093983e7503aae2d591c1e4 (patch)
tree102acfab138debea374a8d0e850d872bf98adcef /base/supports_user_data.h
parentea93125d7961a09ba90d44a9c3013483399a2051 (diff)
downloadchromium_src-ea8e1813f4dec2371093983e7503aae2d591c1e4.zip
chromium_src-ea8e1813f4dec2371093983e7503aae2d591c1e4.tar.gz
chromium_src-ea8e1813f4dec2371093983e7503aae2d591c1e4.tar.bz2
Add extra data to BrowserContext so that content layer and other embedders can stash data with it that has the same lifetime. Converted SSLHostState to use it for now. I'll do the rest in a followup.
BUG=98716 Review URL: https://chromiumcodereview.appspot.com/9348109 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@122164 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/supports_user_data.h')
-rw-r--r--base/supports_user_data.h47
1 files changed, 47 insertions, 0 deletions
diff --git a/base/supports_user_data.h b/base/supports_user_data.h
new file mode 100644
index 0000000..0296a3e
--- /dev/null
+++ b/base/supports_user_data.h
@@ -0,0 +1,47 @@
+// Copyright (c) 2012 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_SUPPORTS_USER_DATA_H_
+#define BASE_SUPPORTS_USER_DATA_H_
+
+#include <map>
+
+#include "base/base_export.h"
+#include "base/memory/linked_ptr.h"
+
+namespace base {
+
+// This is a helper for classes that want to allow users to stash random data by
+// key. At destruction all the objects will be destructed.
+class BASE_EXPORT SupportsUserData {
+ public:
+ SupportsUserData();
+ virtual ~SupportsUserData();
+
+ // Derive from this class and add your own data members to associate extra
+ // information with this object. Use GetUserData(key) and SetUserData()
+ class BASE_EXPORT Data {
+ public:
+ virtual ~Data() {}
+ };
+
+ // The user data allows the clients to associate data with this object.
+ // Multiple user data values can be stored under different keys.
+ // This object will TAKE OWNERSHIP of the given data pointer, and will
+ // delete the object if it is changed or the object is destroyed.
+ Data* GetUserData(const void* key) const;
+ void SetUserData(const void* key, Data* data);
+
+ private:
+ typedef std::map<const void*, linked_ptr<Data> > DataMap;
+
+ // Externally-defined data accessible by key
+ DataMap user_data_;
+
+ DISALLOW_COPY_AND_ASSIGN(SupportsUserData);
+};
+
+} // namespace base
+
+#endif // BASE_SUPPORTS_USER_DATA_H_