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#ifndef CHROME_BROWSER_LOCAL_DISCOVERY_SERVICE_DISCOVERY_DEVICE_LISTER_H_ 6#define CHROME_BROWSER_LOCAL_DISCOVERY_SERVICE_DISCOVERY_DEVICE_LISTER_H_ 7 8#include <map> 9#include <string> 10 11#include "base/memory/linked_ptr.h" 12#include "base/memory/scoped_ptr.h" 13#include "base/memory/weak_ptr.h" 14#include "chrome/common/local_discovery/service_discovery_client.h" 15 16namespace local_discovery { 17 18class ServiceDiscoveryDeviceLister { 19 public: 20 class Delegate { 21 public: 22 virtual void OnDeviceChanged( 23 bool added, 24 const ServiceDescription& service_description) = 0; 25 virtual void OnDeviceRemoved(const std::string& service_name) = 0; 26 virtual void OnDeviceCacheFlushed() = 0; 27 }; 28 29 ServiceDiscoveryDeviceLister(Delegate* delegate, 30 ServiceDiscoveryClient* service_discovery_client, 31 const std::string& service_type); 32 virtual ~ServiceDiscoveryDeviceLister(); 33 34 void Start(); 35 void DiscoverNewDevices(bool force_update); 36 37 std::string service_type() { return service_type_; } 38 39 private: 40 typedef std::map<std::string, linked_ptr<ServiceResolver> > 41 ServiceResolverMap; 42 43 void OnServiceUpdated(ServiceWatcher::UpdateType update, 44 const std::string& service_name); 45 46 void OnResolveComplete( 47 bool added, 48 std::string service_name, 49 ServiceResolver::RequestStatus status, 50 const ServiceDescription& description); 51 52 // Create or recreate the service watcher 53 void CreateServiceWatcher(); 54 55 Delegate* const delegate_; 56 ServiceDiscoveryClient* const service_discovery_client_; 57 const std::string service_type_; 58 59 scoped_ptr<ServiceWatcher> service_watcher_; 60 ServiceResolverMap resolvers_; 61 62 base::WeakPtrFactory<ServiceDiscoveryDeviceLister> weak_factory_; 63 64 DISALLOW_COPY_AND_ASSIGN(ServiceDiscoveryDeviceLister); 65}; 66 67} // namespace local_discovery 68 69#endif // CHROME_BROWSER_LOCAL_DISCOVERY_SERVICE_DISCOVERY_DEVICE_LISTER_H_ 70