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

Side by Side Diff: net/dns/mdns_client_impl.cc

Issue 23190045: Switch ObserverList::size() to ObserverList::might_have_observers() Pt.1 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Pure merge Created 7 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « media/base/user_input_monitor.cc ('k') | sync/js/sync_js_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "net/dns/mdns_client_impl.h" 5 #include "net/dns/mdns_client_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop_proxy.h" 8 #include "base/message_loop/message_loop_proxy.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/time/default_clock.h" 10 #include "base/time/default_clock.h"
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 void MDnsClientImpl::Core::RemoveListener(MDnsListenerImpl* listener) { 371 void MDnsClientImpl::Core::RemoveListener(MDnsListenerImpl* listener) {
372 ListenerKey key(listener->GetName(), listener->GetType()); 372 ListenerKey key(listener->GetName(), listener->GetType());
373 ListenerMap::iterator observer_list_iterator = listeners_.find(key); 373 ListenerMap::iterator observer_list_iterator = listeners_.find(key);
374 374
375 DCHECK(observer_list_iterator != listeners_.end()); 375 DCHECK(observer_list_iterator != listeners_.end());
376 DCHECK(observer_list_iterator->second->HasObserver(listener)); 376 DCHECK(observer_list_iterator->second->HasObserver(listener));
377 377
378 observer_list_iterator->second->RemoveObserver(listener); 378 observer_list_iterator->second->RemoveObserver(listener);
379 379
380 // Remove the observer list from the map if it is empty 380 // Remove the observer list from the map if it is empty
381 if (observer_list_iterator->second->size() == 0) { 381 if (!observer_list_iterator->second->might_have_observers()) {
382 // Schedule the actual removal for later in case the listener removal 382 // Schedule the actual removal for later in case the listener removal
383 // happens while iterating over the observer list. 383 // happens while iterating over the observer list.
384 base::MessageLoop::current()->PostTask( 384 base::MessageLoop::current()->PostTask(
385 FROM_HERE, base::Bind( 385 FROM_HERE, base::Bind(
386 &MDnsClientImpl::Core::CleanupObserverList, AsWeakPtr(), key)); 386 &MDnsClientImpl::Core::CleanupObserverList, AsWeakPtr(), key));
387 } 387 }
388 } 388 }
389 389
390 void MDnsClientImpl::Core::CleanupObserverList(const ListenerKey& key) { 390 void MDnsClientImpl::Core::CleanupObserverList(const ListenerKey& key) {
391 ListenerMap::iterator found = listeners_.find(key); 391 ListenerMap::iterator found = listeners_.find(key);
392 if (found != listeners_.end() && found->second->size() == 0) { 392 if (found != listeners_.end() && !found->second->might_have_observers()) {
393 delete found->second; 393 delete found->second;
394 listeners_.erase(found); 394 listeners_.erase(found);
395 } 395 }
396 } 396 }
397 397
398 void MDnsClientImpl::Core::ScheduleCleanup(base::Time cleanup) { 398 void MDnsClientImpl::Core::ScheduleCleanup(base::Time cleanup) {
399 // Cleanup is already scheduled, no need to do anything. 399 // Cleanup is already scheduled, no need to do anything.
400 if (cleanup == scheduled_cleanup_) return; 400 if (cleanup == scheduled_cleanup_) return;
401 scheduled_cleanup_ = cleanup; 401 scheduled_cleanup_ = cleanup;
402 402
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 662
663 void MDnsTransactionImpl::OnNsecRecord(const std::string& name, unsigned type) { 663 void MDnsTransactionImpl::OnNsecRecord(const std::string& name, unsigned type) {
664 TriggerCallback(RESULT_NSEC, NULL); 664 TriggerCallback(RESULT_NSEC, NULL);
665 } 665 }
666 666
667 void MDnsTransactionImpl::OnCachePurged() { 667 void MDnsTransactionImpl::OnCachePurged() {
668 // TODO(noamsml): Cache purge situations not yet implemented 668 // TODO(noamsml): Cache purge situations not yet implemented
669 } 669 }
670 670
671 } // namespace net 671 } // namespace net
OLDNEW
« no previous file with comments | « media/base/user_input_monitor.cc ('k') | sync/js/sync_js_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698