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

Side by Side Diff: chrome/browser/net/passive_log_collector.cc

Issue 4960001: Fix a DCHECK that could fire in PassiveLogCollector for a particular stream o... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: rename x --> log Created 10 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/net/passive_log_collector.h" 5 #include "chrome/browser/net/passive_log_collector.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 282
283 // After the deletion queue has reached its maximum size, start 283 // After the deletion queue has reached its maximum size, start
284 // deleting sources in FIFO order. 284 // deleting sources in FIFO order.
285 if (deletion_queue_.size() > max_graveyard_size_) { 285 if (deletion_queue_.size() > max_graveyard_size_) {
286 uint32 oldest = deletion_queue_.front(); 286 uint32 oldest = deletion_queue_.front();
287 deletion_queue_.pop_front(); 287 deletion_queue_.pop_front();
288 DeleteSourceInfo(oldest); 288 DeleteSourceInfo(oldest);
289 } 289 }
290 } 290 }
291 291
292 void PassiveLogCollector::SourceTracker::EraseFromDeletionQueue(
293 uint32 source_id) {
294 DeletionQueue::iterator it =
295 std::remove(deletion_queue_.begin(), deletion_queue_.end(),
296 source_id);
297 DCHECK(it != deletion_queue_.end());
298 deletion_queue_.erase(it);
299 }
300
292 void PassiveLogCollector::SourceTracker::AdjustReferenceCountForSource( 301 void PassiveLogCollector::SourceTracker::AdjustReferenceCountForSource(
293 int offset, uint32 source_id) { 302 int offset, uint32 source_id) {
294 DCHECK(offset == -1 || offset == 1) << "invalid offset: " << offset; 303 DCHECK(offset == -1 || offset == 1) << "invalid offset: " << offset;
295 304
296 // In general it is invalid to call AdjustReferenceCountForSource() on 305 // In general it is invalid to call AdjustReferenceCountForSource() on
297 // source that doesn't exist. However, it is possible that if 306 // source that doesn't exist. However, it is possible that if
298 // SourceTracker::Clear() was previously called this can happen. 307 // SourceTracker::Clear() was previously called this can happen.
299 SourceIDToInfoMap::iterator it = sources_.find(source_id); 308 SourceIDToInfoMap::iterator it = sources_.find(source_id);
300 if (it == sources_.end()) { 309 if (it == sources_.end()) {
301 LOG(WARNING) << "Released a reference to nonexistent source."; 310 LOG(WARNING) << "Released a reference to nonexistent source.";
302 return; 311 return;
303 } 312 }
304 313
305 SourceInfo& info = it->second; 314 SourceInfo& info = it->second;
306 DCHECK_GE(info.reference_count, 0); 315 DCHECK_GE(info.reference_count, 0);
307 info.reference_count += offset; 316 info.reference_count += offset;
308 317
309 if (info.reference_count < 0) { 318 bool released_unmatched_reference = info.reference_count < 0;
319 if (released_unmatched_reference) {
310 // In general this shouldn't happen, however it is possible to reach this 320 // In general this shouldn't happen, however it is possible to reach this
311 // state if SourceTracker::Clear() was called earlier. 321 // state if SourceTracker::Clear() was called earlier.
312 LOG(WARNING) << "Released unmatched reference count."; 322 LOG(WARNING) << "Released unmatched reference count.";
313 info.reference_count = 0; 323 info.reference_count = 0;
314 } 324 }
315 325
316 if (!info.is_alive) { 326 if (!info.is_alive) {
317 if (info.reference_count == 1 && offset == 1) { 327 if (info.reference_count == 1 && offset == 1) {
318 // If we just added a reference to a dead source that had no references, 328 // If we just added a reference to a dead source that had no references,
319 // it must have been in the deletion queue, so remove it from the queue. 329 // it must have been in the deletion queue, so remove it from the queue.
320 DeletionQueue::iterator it = 330 EraseFromDeletionQueue(source_id);
321 std::remove(deletion_queue_.begin(), deletion_queue_.end(),
322 source_id);
323 DCHECK(it != deletion_queue_.end());
324 deletion_queue_.erase(it);
325 } else if (info.reference_count == 0) { 331 } else if (info.reference_count == 0) {
332 if (released_unmatched_reference)
333 EraseFromDeletionQueue(source_id);
326 // If we just released the final reference to a dead source, go ahead 334 // If we just released the final reference to a dead source, go ahead
327 // and delete it right away. 335 // and delete it right away.
328 DeleteSourceInfo(source_id); 336 DeleteSourceInfo(source_id);
329 } 337 }
330 } 338 }
331 } 339 }
332 340
333 void PassiveLogCollector::SourceTracker::AddReferenceToSourceDependency( 341 void PassiveLogCollector::SourceTracker::AddReferenceToSourceDependency(
334 const net::NetLog::Source& source, SourceInfo* info) { 342 const net::NetLog::Source& source, SourceInfo* info) {
335 // Find the tracker which should be holding |source|. 343 // Find the tracker which should be holding |source|.
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 PassiveLogCollector::DNSJobTracker::DoAddEntry(const Entry& entry, 562 PassiveLogCollector::DNSJobTracker::DoAddEntry(const Entry& entry,
555 SourceInfo* out_info) { 563 SourceInfo* out_info) {
556 AddEntryToSourceInfo(entry, out_info); 564 AddEntryToSourceInfo(entry, out_info);
557 if (entry.type == net::NetLog::TYPE_HOST_RESOLVER_IMPL_JOB && 565 if (entry.type == net::NetLog::TYPE_HOST_RESOLVER_IMPL_JOB &&
558 entry.phase == net::NetLog::PHASE_END) { 566 entry.phase == net::NetLog::PHASE_END) {
559 return ACTION_MOVE_TO_GRAVEYARD; 567 return ACTION_MOVE_TO_GRAVEYARD;
560 } else { 568 } else {
561 return ACTION_NONE; 569 return ACTION_NONE;
562 } 570 }
563 } 571 }
OLDNEW
« no previous file with comments | « chrome/browser/net/passive_log_collector.h ('k') | chrome/browser/net/passive_log_collector_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698