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

Unified Diff: base/id_map.h

Issue 702843004: Transfer serviceworker state during cross site navigations too. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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
Index: base/id_map.h
diff --git a/base/id_map.h b/base/id_map.h
index 9cbc1f8978fa8836b770f8370ff3b2a3f44e2017..852c1380471d776689a9b05c99e67c228d0557e2 100644
--- a/base/id_map.h
+++ b/base/id_map.h
@@ -53,13 +53,14 @@ class IDMap : public base::NonThreadSafe {
Releaser<OS, 0>::release_all(&data_);
}
- // Sets whether Add should CHECK if passed in NULL data. Default is false.
+ // Sets whether Add and Replace should DCHECK if passed in NULL data.
+ // Default is false.
void set_check_on_null_data(bool value) { check_on_null_data_ = value; }
// Adds a view with an automatically generated unique ID. See AddWithID.
KeyType Add(T* data) {
DCHECK(CalledOnValidThread());
- CHECK(!check_on_null_data_ || data);
+ DCHECK(!check_on_null_data_ || data);
KeyType this_id = next_id_;
DCHECK(data_.find(this_id) == data_.end()) << "Inserting duplicate item";
data_[this_id] = data;
@@ -73,7 +74,7 @@ class IDMap : public base::NonThreadSafe {
// two methods may not be mixed, or duplicate IDs may be generated
void AddWithID(T* data, KeyType id) {
DCHECK(CalledOnValidThread());
- CHECK(!check_on_null_data_ || data);
+ DCHECK(!check_on_null_data_ || data);
DCHECK(data_.find(id) == data_.end()) << "Inserting duplicate item";
data_[id] = data;
}
@@ -94,6 +95,25 @@ class IDMap : public base::NonThreadSafe {
}
}
+ // Replaces the value for |id| with |new_data| and returns a pointer to the
+ // existing value. If there is no entry for |id|, the map is not altered and
+ // nullptr is returned. The OwnershipSemantics of the map have no effect on
+ // how the existing value is treated, the IDMap does not delete the existing
+ // value being replaced.
+ T* Replace(KeyType id, T* new_data) {
+ DCHECK(CalledOnValidThread());
+ DCHECK(!check_on_null_data_ || new_data);
+ typename HashTable::iterator i = data_.find(id);
+ if (i == data_.end()) {
+ NOTREACHED() << "Attempting to replace an item not in the list";
+ return nullptr;
+ }
+
+ T* temp = i->second;
+ i->second = new_data;
+ return temp;
+ }
+
void Clear() {
DCHECK(CalledOnValidThread());
if (iteration_depth_ == 0) {
« no previous file with comments | « no previous file | base/id_map_unittest.cc » ('j') | content/browser/service_worker/service_worker_context_core.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698