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

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

Issue 17922002: Add an explicit way of forcing the MDnsClient to listen on the network (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 5 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
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 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 } 377 }
378 378
379 void MDnsClientImpl::Core::QueryCache( 379 void MDnsClientImpl::Core::QueryCache(
380 uint16 rrtype, const std::string& name, 380 uint16 rrtype, const std::string& name,
381 std::vector<const RecordParsed*>* records) const { 381 std::vector<const RecordParsed*>* records) const {
382 cache_.FindDnsRecords(rrtype, name, records, base::Time::Now()); 382 cache_.FindDnsRecords(rrtype, name, records, base::Time::Now());
383 } 383 }
384 384
385 MDnsClientImpl::MDnsClientImpl( 385 MDnsClientImpl::MDnsClientImpl(
386 scoped_ptr<MDnsConnection::SocketFactory> socket_factory) 386 scoped_ptr<MDnsConnection::SocketFactory> socket_factory)
387 : listen_refs_(0), socket_factory_(socket_factory.Pass()) { 387 : socket_factory_(socket_factory.Pass()) {
388 } 388 }
389 389
390 MDnsClientImpl::~MDnsClientImpl() { 390 MDnsClientImpl::~MDnsClientImpl() {
391 } 391 }
392 392
393 bool MDnsClientImpl::AddListenRef() { 393 bool MDnsClientImpl::StartListening() {
394 if (!core_.get()) { 394 DCHECK(!core_.get());
395 core_.reset(new Core(this, socket_factory_.get())); 395 core_.reset(new Core(this, socket_factory_.get()));
396 if (!core_->Init()) { 396 if (!core_->Init()) {
397 core_.reset(); 397 core_.reset();
398 return false; 398 return false;
399 }
400 } 399 }
401 listen_refs_++;
402 return true; 400 return true;
403 } 401 }
404 402
405 void MDnsClientImpl::SubtractListenRef() { 403 void MDnsClientImpl::StopListening() {
406 listen_refs_--; 404 core_.reset();
407 if (listen_refs_ == 0) {
408 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
409 &MDnsClientImpl::Shutdown, base::Unretained(this)));
410 }
411 } 405 }
412 406
413 void MDnsClientImpl::Shutdown() { 407 bool MDnsClientImpl::GetListening() const {
414 // We need to check that new listeners haven't been created.
415 if (listen_refs_ == 0) {
416 core_.reset();
417 }
418 }
419
420 bool MDnsClientImpl::IsListeningForTests() {
421 return core_.get() != NULL; 408 return core_.get() != NULL;
422 } 409 }
423 410
424 scoped_ptr<MDnsListener> MDnsClientImpl::CreateListener( 411 scoped_ptr<MDnsListener> MDnsClientImpl::CreateListener(
425 uint16 rrtype, 412 uint16 rrtype,
426 const std::string& name, 413 const std::string& name,
427 MDnsListener::Delegate* delegate) { 414 MDnsListener::Delegate* delegate) {
428 return scoped_ptr<net::MDnsListener>( 415 return scoped_ptr<net::MDnsListener>(
429 new MDnsListenerImpl(rrtype, name, delegate, this)); 416 new MDnsListenerImpl(rrtype, name, delegate, this));
430 } 417 }
(...skipping 12 matching lines...) Expand all
443 const std::string& name, 430 const std::string& name,
444 MDnsListener::Delegate* delegate, 431 MDnsListener::Delegate* delegate,
445 MDnsClientImpl* client) 432 MDnsClientImpl* client)
446 : rrtype_(rrtype), name_(name), client_(client), delegate_(delegate), 433 : rrtype_(rrtype), name_(name), client_(client), delegate_(delegate),
447 started_(false) { 434 started_(false) {
448 } 435 }
449 436
450 bool MDnsListenerImpl::Start() { 437 bool MDnsListenerImpl::Start() {
451 DCHECK(!started_); 438 DCHECK(!started_);
452 439
453 if (!client_->AddListenRef()) return false;
454 started_ = true; 440 started_ = true;
455 441
456 DCHECK(client_->core()); 442 DCHECK(client_->core());
457 client_->core()->AddListener(this); 443 client_->core()->AddListener(this);
458 444
459 return true; 445 return true;
460 } 446 }
461 447
462 MDnsListenerImpl::~MDnsListenerImpl() { 448 MDnsListenerImpl::~MDnsListenerImpl() {
463 if (started_) { 449 if (started_) {
464 DCHECK(client_->core()); 450 DCHECK(client_->core());
465 client_->core()->RemoveListener(this); 451 client_->core()->RemoveListener(this);
466 client_->SubtractListenRef();
467 } 452 }
468 } 453 }
469 454
470 const std::string& MDnsListenerImpl::GetName() const { 455 const std::string& MDnsListenerImpl::GetName() const {
471 return name_; 456 return name_;
472 } 457 }
473 458
474 uint16 MDnsListenerImpl::GetType() const { 459 uint16 MDnsListenerImpl::GetType() const {
475 return rrtype_; 460 return rrtype_;
476 } 461 }
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 596
612 void MDnsTransactionImpl::OnNsecRecord(const std::string& name, unsigned type) { 597 void MDnsTransactionImpl::OnNsecRecord(const std::string& name, unsigned type) {
613 // TODO(noamsml): NSEC records not yet implemented 598 // TODO(noamsml): NSEC records not yet implemented
614 } 599 }
615 600
616 void MDnsTransactionImpl::OnCachePurged() { 601 void MDnsTransactionImpl::OnCachePurged() {
617 // TODO(noamsml): Cache purge situations not yet implemented 602 // TODO(noamsml): Cache purge situations not yet implemented
618 } 603 }
619 604
620 } // namespace net 605 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698