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

Unified Diff: base/id_map.h

Issue 2480293004: Mandate unique_ptr for base::IDMap in IDMapOwnPointer mode. (Closed)
Patch Set: Make changes requested by danakj, fix a few more headers Created 4 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « android_webview/native/aw_contents_client_bridge.cc ('k') | base/id_map_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/id_map.h
diff --git a/base/id_map.h b/base/id_map.h
index 8702982f172ffd0f06725207f296104946965d4d..74fb8d0b596cb7e1b0d758ad4e8ddfc3eb2b0103 100644
--- a/base/id_map.h
+++ b/base/id_map.h
@@ -17,8 +17,13 @@
#include "base/macros.h"
#include "base/sequence_checker.h"
-// Ownership semantics - own pointer means the pointer is deleted in Remove()
-// & during destruction
+// Ownership semantics:
+// - OwnPointer means we store a unique_ptr that owns the object (so the
+// object is deleted in Remove() and during destruction).
+// - ExternalPointer means we store a raw pointer and don't own the object
+
+// TODO (http://crbug.com/647091): eliminate this enum, replace OwnPointer
+// mode in callsites with IDMap<unique_ptr<T>>
enum IDMapOwnershipSemantics {
IDMapExternalPointer,
IDMapOwnPointer
@@ -68,30 +73,13 @@ class IDMap {
void set_check_on_null_data(bool value) { check_on_null_data_ = value; }
// Adds a view with an automatically generated unique ID. See AddWithID.
- // (This unique_ptr<> variant will not compile in IDMapExternalPointer mode.)
- KeyType Add(std::unique_ptr<T> data) {
- return AddInternal(std::move(data));
- }
+ KeyType Add(V data) { return AddInternal(std::move(data)); }
// Adds a new data member with the specified ID. The ID must not be in
// the list. The caller either must generate all unique IDs itself and use
// this function, or allow this object to generate IDs and call Add. These
// two methods may not be mixed, or duplicate IDs may be generated.
- // (This unique_ptr<> variant will not compile in IDMapExternalPointer mode.)
- void AddWithID(std::unique_ptr<T> data, KeyType id) {
- AddWithIDInternal(std::move(data), id);
- }
-
- // http://crbug.com/647091: Raw pointer Add()s in IDMapOwnPointer mode are
- // deprecated. Users of IDMapOwnPointer should transition to the unique_ptr
- // variant above, and the following methods should only be used in
- // IDMapExternalPointer mode.
- KeyType Add(T* data) {
- return AddInternal(V(data));
- }
- void AddWithID(T* data, KeyType id) {
- AddWithIDInternal(V(data), id);
- }
+ void AddWithID(V data, KeyType id) { AddWithIDInternal(std::move(data), id); }
void Remove(KeyType id) {
DCHECK(sequence_checker_.CalledOnValidSequence());
« no previous file with comments | « android_webview/native/aw_contents_client_bridge.cc ('k') | base/id_map_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698