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 3// found in the LICENSE file. 4 5#include "chrome/browser/local_discovery/privet_device_lister_impl.h" 6 7#include <utility> 8#include <vector> 9 10#include "base/strings/string_util.h" 11#include "base/strings/stringprintf.h" 12#include "chrome/browser/local_discovery/privet_constants.h" 13 14namespace local_discovery { 15 16PrivetDeviceListerImpl::PrivetDeviceListerImpl( 17 ServiceDiscoveryClient* service_discovery_client, 18 PrivetDeviceLister::Delegate* delegate) 19 : delegate_(delegate), 20 device_lister_(this, service_discovery_client, kPrivetDefaultDeviceType) { 21} 22 23PrivetDeviceListerImpl::PrivetDeviceListerImpl( 24 ServiceDiscoveryClient* service_discovery_client, 25 PrivetDeviceLister::Delegate* delegate, 26 const std::string& subtype) 27 : delegate_(delegate), 28 device_lister_( 29 this, 30 service_discovery_client, 31 base::StringPrintf(kPrivetSubtypeTemplate, subtype.c_str())) { 32} 33 34PrivetDeviceListerImpl::~PrivetDeviceListerImpl() { 35} 36 37void PrivetDeviceListerImpl::Start() { 38 device_lister_.Start(); 39} 40 41void PrivetDeviceListerImpl::DiscoverNewDevices(bool force_update) { 42 device_lister_.DiscoverNewDevices(force_update); 43} 44 45void PrivetDeviceListerImpl::OnDeviceChanged( 46 bool added, const ServiceDescription& service_description) { 47 if (!delegate_) 48 return; 49 50 DeviceDescription device_description; 51 device_description.FillFromServiceDescription(service_description); 52 53 delegate_->DeviceChanged( 54 added, service_description.service_name, device_description); 55} 56 57void PrivetDeviceListerImpl::OnDeviceRemoved(const std::string& service_name) { 58 if (delegate_) 59 delegate_->DeviceRemoved(service_name); 60} 61 62void PrivetDeviceListerImpl::OnDeviceCacheFlushed() { 63 if (delegate_) 64 delegate_->DeviceCacheFlushed(); 65} 66 67} // namespace local_discovery 68