Commit 58478dad authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Only activate DnsSdDeviceLister::Discover() when possible.

If the ENABLE_SERVICE_DISCOVERY build flag is not set, then this code
will never work correctly, because DnsSdRegistry will not pass in a
valid ServiceDiscoverySharedClient. So just make Discover() a no-op in
this case, guarded by ENABLE_SERVICE_DISCOVERY. This in turn, makes some
DnsSdDeviceLister member variables only used when
ENABLE_SERVICE_DISCOVERY is set, so guard them by the same build flag.

Bug: 757530
Change-Id: I2f0864e1342be3d6328fbf449dc2296825fe1fbc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1716102Reviewed-by: default avatarTakumi Fujimoto <takumif@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#680473}
parent e953e560
......@@ -32,13 +32,19 @@ DnsSdDeviceLister::DnsSdDeviceLister(
local_discovery::ServiceDiscoveryClient* service_discovery_client,
DnsSdDelegate* delegate,
const std::string& service_type)
: delegate_(delegate),
: delegate_(delegate)
#if BUILDFLAG(ENABLE_SERVICE_DISCOVERY)
,
service_discovery_client_(service_discovery_client),
service_type_(service_type) {}
service_type_(service_type)
#endif
{
}
DnsSdDeviceLister::~DnsSdDeviceLister() {}
void DnsSdDeviceLister::Discover() {
#if BUILDFLAG(ENABLE_SERVICE_DISCOVERY)
if (!device_lister_) {
device_lister_ = local_discovery::ServiceDiscoveryDeviceLister::Create(
this, service_discovery_client_, service_type_);
......@@ -49,6 +55,7 @@ void DnsSdDeviceLister::Discover() {
device_lister_->DiscoverNewDevices();
VLOG(1) << "Discovery new devices for service type "
<< device_lister_->service_type();
#endif
}
void DnsSdDeviceLister::Reset() {
......
......@@ -10,6 +10,7 @@
#include "base/macros.h"
#include "chrome/browser/local_discovery/service_discovery_device_lister.h"
#include "chrome/common/buildflags.h"
namespace local_discovery {
class ServiceDiscoveryClient;
......@@ -49,12 +50,14 @@ class DnsSdDeviceLister
// The delegate to notify of changes to services.
DnsSdDelegate* const delegate_;
// Created when |Discover()| is called.
// Created when Discover() is called, if service discovery is enabled.
std::unique_ptr<local_discovery::ServiceDiscoveryDeviceLister> device_lister_;
#if BUILDFLAG(ENABLE_SERVICE_DISCOVERY)
// The client and service type used to create |device_lister_|.
local_discovery::ServiceDiscoveryClient* const service_discovery_client_;
const std::string service_type_;
#endif
DISALLOW_COPY_AND_ASSIGN(DnsSdDeviceLister);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment