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