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

Unified Diff: base/id_map.h

Issue 150181: Adds some debugging code in hopes of tracking down a... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 6 months 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 | « no previous file | chrome/browser/browser_shutdown.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/id_map.h
===================================================================
--- base/id_map.h (revision 19754)
+++ base/id_map.h (working copy)
@@ -28,12 +28,17 @@
// Note, use iterator->first to get the ID, iterator->second to get the T*
typedef typename HashTable::const_iterator const_iterator;
- IDMap() : next_id_(1) {
+ IDMap() : next_id_(1), check_on_null_data_(false) {
}
- IDMap(const IDMap& other) : next_id_(other.next_id_),
- data_(other.data_) {
+ IDMap(const IDMap& other)
+ : next_id_(other.next_id_),
+ data_(other.data_),
+ check_on_null_data_(other.check_on_null_data_) {
}
+ // Sets whether Add should CHECK if passed in NULL data. Default is false.
+ void set_check_on_null_data(bool value) { check_on_null_data_ = value; }
+
const_iterator begin() const {
return data_.begin();
}
@@ -43,6 +48,7 @@
// Adds a view with an automatically generated unique ID. See AddWithID.
int32 Add(T* data) {
+ CHECK(!check_on_null_data_ || data);
int32 this_id = next_id_;
DCHECK(data_.find(this_id) == data_.end()) << "Inserting duplicate item";
data_[this_id] = data;
@@ -55,6 +61,7 @@
// 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
void AddWithID(T* data, int32 id) {
+ CHECK(!check_on_null_data_ || data);
DCHECK(data_.find(id) == data_.end()) << "Inserting duplicate item";
data_[id] = data;
}
@@ -88,6 +95,10 @@
int32 next_id_;
HashTable data_;
+
+ private:
+ // See description above setter.
+ bool check_on_null_data_;
};
#endif // BASE_ID_MAP_H__
« no previous file with comments | « no previous file | chrome/browser/browser_shutdown.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698