Chromium Code Reviews| Index: net/disk_cache/blockfile/backend_impl.cc |
| diff --git a/net/disk_cache/blockfile/backend_impl.cc b/net/disk_cache/blockfile/backend_impl.cc |
| index 7d4f296199bfce07ec22a5e89cd19592fab2eb71..82d4b5cb8448e0d0d367583157ff6b724592ecf9 100644 |
| --- a/net/disk_cache/blockfile/backend_impl.cc |
| +++ b/net/disk_cache/blockfile/backend_impl.cc |
| @@ -540,7 +540,8 @@ EntryImpl* BackendImpl::CreateEntryImpl(const std::string& key) { |
| EntryImpl* parent_entry = MatchEntry(key, hash, true, Addr(), &error); |
| DCHECK(!error); |
| if (parent_entry) { |
| - parent.swap(&parent_entry); |
| + parent = make_scoped_refptr(parent_entry); |
| + parent_entry->Release(); |
|
dcheng
2017/03/02 18:40:19
Is there any chance we can fix the //net code to j
tzik
2017/03/02 19:26:28
Agree. It's very hard to read even for writing sma
jkarlin
2017/03/03 15:30:32
+1
|
| } else if (data_->table[hash & mask_]) { |
| // We should have corrected the problem. |
| NOTREACHED(); |
| @@ -632,7 +633,11 @@ EntryImpl* BackendImpl::OpenNextEntryImpl(Rankings::Iterator* iterator) { |
| EntryImpl* temp = NULL; |
| ret |= OpenFollowingEntryFromList(static_cast<Rankings::List>(i), |
| &iterator->nodes[i], &temp); |
| - entries[i].swap(&temp); // The entry was already addref'd. |
| + if (temp) { |
| + // The entry was already addref'd. |
| + entries[i] = make_scoped_refptr(temp); |
| + temp->Release(); |
| + } |
| } |
| if (!ret) { |
| iterator->Reset(); |
| @@ -651,7 +656,11 @@ EntryImpl* BackendImpl::OpenNextEntryImpl(Rankings::Iterator* iterator) { |
| static_cast<Rankings::List>(i)); |
| } |
| - entries[i].swap(&temp); // The entry was already addref'd. |
| + if (temp) { |
| + // The entry was already addref'd. |
| + entries[i] = make_scoped_refptr(temp); |
| + temp->Release(); |
| + } |
| } |
| } |
| @@ -1606,7 +1615,8 @@ int BackendImpl::NewEntry(Addr address, EntryImpl** entry) { |
| open_entries_[address.value()] = cache_entry.get(); |
| cache_entry->BeginLogging(net_log_, false); |
| - cache_entry.swap(entry); |
| + *entry = cache_entry.get(); |
| + (*entry)->AddRef(); |
| return 0; |
| } |
| @@ -1617,12 +1627,13 @@ EntryImpl* BackendImpl::MatchEntry(const std::string& key, |
| bool* match_error) { |
| Addr address(data_->table[hash & mask_]); |
| scoped_refptr<EntryImpl> cache_entry, parent_entry; |
| - EntryImpl* tmp = NULL; |
| bool found = false; |
| std::set<CacheAddr> visited; |
| *match_error = false; |
| for (;;) { |
| + DCHECK(!cache_entry); |
| + |
| if (disabled_) |
| break; |
| @@ -1641,8 +1652,12 @@ EntryImpl* BackendImpl::MatchEntry(const std::string& key, |
| break; |
| } |
| + EntryImpl* tmp = nullptr; |
| int error = NewEntry(address, &tmp); |
| - cache_entry.swap(&tmp); |
| + if (!error) { |
| + cache_entry = make_scoped_refptr(tmp); |
| + tmp->Release(); |
| + } |
| if (error || cache_entry->dirty()) { |
| // This entry is dirty on disk (it was not properly closed): we cannot |
| @@ -1709,10 +1724,14 @@ EntryImpl* BackendImpl::MatchEntry(const std::string& key, |
| if (cache_entry.get() && (find_parent || !found)) |
| cache_entry = NULL; |
| + EntryImpl* tmp = NULL; |
| if (find_parent) |
| - parent_entry.swap(&tmp); |
| + tmp = parent_entry.get(); |
| else |
| - cache_entry.swap(&tmp); |
| + tmp = cache_entry.get(); |
| + |
| + if (tmp) |
| + tmp->AddRef(); |
| FlushIndex(); |
| return tmp; |
| @@ -2060,7 +2079,8 @@ int BackendImpl::CheckAllEntries() { |
| return ret; |
| } |
| scoped_refptr<EntryImpl> cache_entry; |
| - cache_entry.swap(&tmp); |
| + cache_entry = make_scoped_refptr(tmp); |
| + tmp->Release(); |
| if (cache_entry->dirty()) |
| num_dirty++; |