17dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// Copyright 2013 The Chromium Authors. All rights reserved. 27dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// Use of this source code is governed by a BSD-style license that can be 37dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// found in the LICENSE file. 47dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 57dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "chrome/browser/local_discovery/privet_device_lister_impl.h" 67dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 77dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include <utility> 87dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include <vector> 97dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 107dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "base/strings/string_util.h" 117dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "base/strings/stringprintf.h" 127dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "chrome/browser/local_discovery/privet_constants.h" 137dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 147dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochnamespace local_discovery { 157dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 168bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)PrivetDeviceListerImpl::PrivetDeviceListerImpl( 178bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) ServiceDiscoveryClient* service_discovery_client, 188bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) PrivetDeviceLister::Delegate* delegate) 198bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) : delegate_(delegate), 208bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) device_lister_(this, service_discovery_client, kPrivetDefaultDeviceType) { 217dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch} 227dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 238bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)PrivetDeviceListerImpl::PrivetDeviceListerImpl( 248bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) ServiceDiscoveryClient* service_discovery_client, 258bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) PrivetDeviceLister::Delegate* delegate, 268bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) const std::string& subtype) 278bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) : delegate_(delegate), 288bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) device_lister_( 298bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) this, 308bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) service_discovery_client, 318bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) base::StringPrintf(kPrivetSubtypeTemplate, subtype.c_str())) { 328bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 3358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 348bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)PrivetDeviceListerImpl::~PrivetDeviceListerImpl() { 358bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 368bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 378bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)void PrivetDeviceListerImpl::Start() { 388bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) device_lister_.Start(); 398bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 408bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 418bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)void PrivetDeviceListerImpl::DiscoverNewDevices(bool force_update) { 428bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) device_lister_.DiscoverNewDevices(force_update); 438bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 448bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 458bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)void PrivetDeviceListerImpl::OnDeviceChanged( 468bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) bool added, const ServiceDescription& service_description) { 478bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) if (!delegate_) 488bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return; 498bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 508bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) DeviceDescription device_description; 515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) device_description.FillFromServiceDescription(service_description); 528bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 538bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) delegate_->DeviceChanged( 548bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) added, service_description.service_name, device_description); 558bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 568bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 578bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)void PrivetDeviceListerImpl::OnDeviceRemoved(const std::string& service_name) { 588bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) if (delegate_) 598bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) delegate_->DeviceRemoved(service_name); 608bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 618bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 628bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)void PrivetDeviceListerImpl::OnDeviceCacheFlushed() { 638bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) if (delegate_) 648bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) delegate_->DeviceCacheFlushed(); 6558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)} 6658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 677dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch} // namespace local_discovery 68