OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_TOOLS_SERVICE_DISCOVERY_SNIFFER_SERVICE_DISCOVERY_SNIFFER_H_ | 5 #ifndef CHROME_TOOLS_SERVICE_DISCOVERY_SNIFFER_SERVICE_DISCOVERY_SNIFFER_H_ |
6 #define CHROME_TOOLS_SERVICE_DISCOVERY_SNIFFER_SERVICE_DISCOVERY_SNIFFER_H_ | 6 #define CHROME_TOOLS_SERVICE_DISCOVERY_SNIFFER_SERVICE_DISCOVERY_SNIFFER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
| 9 #include <memory> |
9 #include <string> | 10 #include <string> |
10 | 11 |
11 #include "base/macros.h" | 12 #include "base/macros.h" |
12 #include "base/memory/linked_ptr.h" | 13 #include "base/memory/linked_ptr.h" |
13 #include "chrome/browser/local_discovery/service_discovery_client.h" | 14 #include "chrome/browser/local_discovery/service_discovery_client.h" |
14 | 15 |
15 namespace local_discovery { | 16 namespace local_discovery { |
16 | 17 |
17 // Resolves a service and prints out information regarding it to the | 18 // Resolves a service and prints out information regarding it to the |
18 // console. |client| must outlive the ServicePrinter. | 19 // console. |client| must outlive the ServicePrinter. |
19 class ServicePrinter { | 20 class ServicePrinter { |
20 public: | 21 public: |
21 ServicePrinter(ServiceDiscoveryClient* client, | 22 ServicePrinter(ServiceDiscoveryClient* client, |
22 const std::string& service_name); | 23 const std::string& service_name); |
23 ~ServicePrinter(); | 24 ~ServicePrinter(); |
24 | 25 |
25 void Added(); | 26 void Added(); |
26 void Changed(); | 27 void Changed(); |
27 void Removed(); | 28 void Removed(); |
28 | 29 |
29 private: | 30 private: |
30 void OnServiceResolved(ServiceResolver::RequestStatus status, | 31 void OnServiceResolved(ServiceResolver::RequestStatus status, |
31 const ServiceDescription& service); | 32 const ServiceDescription& service); |
32 | 33 |
33 bool changed_; | 34 bool changed_; |
34 scoped_ptr<ServiceResolver> service_resolver_; | 35 std::unique_ptr<ServiceResolver> service_resolver_; |
35 | 36 |
36 DISALLOW_COPY_AND_ASSIGN(ServicePrinter); | 37 DISALLOW_COPY_AND_ASSIGN(ServicePrinter); |
37 }; | 38 }; |
38 | 39 |
39 // Monitors a service type and prints information regarding all services on it | 40 // Monitors a service type and prints information regarding all services on it |
40 // to the console. |client| must outlive the ServiceTypePrinter. | 41 // to the console. |client| must outlive the ServiceTypePrinter. |
41 class ServiceTypePrinter { | 42 class ServiceTypePrinter { |
42 public: | 43 public: |
43 ServiceTypePrinter(ServiceDiscoveryClient* client, | 44 ServiceTypePrinter(ServiceDiscoveryClient* client, |
44 const std::string& service_type); | 45 const std::string& service_type); |
45 virtual ~ServiceTypePrinter(); | 46 virtual ~ServiceTypePrinter(); |
46 | 47 |
47 void Start(); | 48 void Start(); |
48 void OnServiceUpdated(ServiceWatcher::UpdateType, | 49 void OnServiceUpdated(ServiceWatcher::UpdateType, |
49 const std::string& service_name); | 50 const std::string& service_name); |
50 | 51 |
51 private: | 52 private: |
52 typedef std::map<std::string, linked_ptr<ServicePrinter> > ServiceMap; | 53 typedef std::map<std::string, linked_ptr<ServicePrinter> > ServiceMap; |
53 | 54 |
54 ServiceMap services_; | 55 ServiceMap services_; |
55 scoped_ptr<ServiceWatcher> watcher_; | 56 std::unique_ptr<ServiceWatcher> watcher_; |
56 ServiceDiscoveryClient* client_; | 57 ServiceDiscoveryClient* client_; |
57 | 58 |
58 DISALLOW_COPY_AND_ASSIGN(ServiceTypePrinter); | 59 DISALLOW_COPY_AND_ASSIGN(ServiceTypePrinter); |
59 }; | 60 }; |
60 | 61 |
61 } // namespace local_discovery | 62 } // namespace local_discovery |
62 | 63 |
63 #endif // CHROME_TOOLS_SERVICE_DISCOVERY_SNIFFER_SERVICE_DISCOVERY_SNIFFER_H_ | 64 #endif // CHROME_TOOLS_SERVICE_DISCOVERY_SNIFFER_SERVICE_DISCOVERY_SNIFFER_H_ |
OLD | NEW |