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_PRIVET_LOCAL_PRINTER_LISTER_H_ 6 #define CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_LOCAL_PRINTER_LISTER_H_ 7 8 #include <map> 9 #include <string> 10 11 #include "base/memory/linked_ptr.h" 12 #include "chrome/browser/local_discovery/privet_device_lister.h" 13 #include "chrome/browser/local_discovery/privet_http.h" 14 #include "chrome/browser/local_discovery/privet_http_asynchronous_factory.h" 15 #include "chrome/common/local_discovery/service_discovery_client.h" 16 #include "net/url_request/url_request_context.h" 17 18 namespace local_discovery { 19 20 // This is an adapter to PrivetDeviceLister that finds printers and checks if 21 // they support Privet local printing. 22 class PrivetLocalPrinterLister : PrivetDeviceLister::Delegate { 23 public: 24 class Delegate { 25 public: 26 virtual ~Delegate() {} 27 virtual void LocalPrinterChanged(bool added, 28 const std::string& name, 29 bool has_local_printing, 30 const DeviceDescription& description) = 0; 31 virtual void LocalPrinterRemoved(const std::string& name) = 0; 32 virtual void LocalPrinterCacheFlushed() = 0; 33 }; 34 35 PrivetLocalPrinterLister(ServiceDiscoveryClient* service_discovery_client, 36 net::URLRequestContextGetter* request_context, 37 Delegate* delegate); 38 virtual ~PrivetLocalPrinterLister(); 39 40 void Start(); 41 42 // Stops listening/listing, keeps the data. 43 void Stop(); 44 45 const DeviceDescription* GetDeviceDescription(const std::string& name); 46 47 // PrivetDeviceLister::Delegate implementation. 48 virtual void DeviceChanged(bool added, 49 const std::string& name, 50 const DeviceDescription& description) OVERRIDE; 51 virtual void DeviceRemoved(const std::string& name) OVERRIDE; 52 virtual void DeviceCacheFlushed() OVERRIDE; 53 54 private: 55 struct DeviceContext; 56 57 typedef std::map<std::string, linked_ptr<DeviceContext> > DeviceContextMap; 58 59 void OnPrivetInfoDone(DeviceContext* context, 60 const std::string& name, 61 const base::DictionaryValue* json_value); 62 63 void OnPrivetResolved(const std::string& name, 64 scoped_ptr<PrivetHTTPClient> http_client); 65 66 scoped_ptr<PrivetHTTPAsynchronousFactory> privet_http_factory_; 67 DeviceContextMap device_contexts_; 68 Delegate* delegate_; 69 70 scoped_ptr<PrivetDeviceLister> privet_lister_; 71 }; 72 73 } // namespace local_discovery 74 75 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_LOCAL_PRINTER_LISTER_H_ 76