| 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_BROWSER_LOCAL_DISCOVERY_CLOUD_PRINT_PRINTER_LIST_H_ | 5 #ifndef CHROME_BROWSER_LOCAL_DISCOVERY_CLOUD_PRINT_PRINTER_LIST_H_ |
| 6 #define CHROME_BROWSER_LOCAL_DISCOVERY_CLOUD_PRINT_PRINTER_LIST_H_ | 6 #define CHROME_BROWSER_LOCAL_DISCOVERY_CLOUD_PRINT_PRINTER_LIST_H_ |
| 7 | 7 |
| 8 #include <map> | |
| 9 #include <string> | 8 #include <string> |
| 10 #include <vector> | 9 #include <vector> |
| 11 | 10 |
| 11 #include "chrome/browser/local_discovery/cloud_device_list_delegate.h" |
| 12 #include "chrome/browser/local_discovery/gcd_base_api_flow.h" | 12 #include "chrome/browser/local_discovery/gcd_base_api_flow.h" |
| 13 | 13 |
| 14 namespace local_discovery { | 14 namespace local_discovery { |
| 15 | 15 |
| 16 class CloudPrintPrinterList : public GCDBaseApiFlow::Delegate { | 16 class CloudPrintPrinterList : public GCDBaseApiFlow::Delegate { |
| 17 public: | 17 public: |
| 18 class Delegate { | 18 typedef std::vector<CloudDeviceListDelegate::Device> PrinterList; |
| 19 public: | |
| 20 ~Delegate() {} | |
| 21 | |
| 22 virtual void OnCloudPrintPrinterListReady() = 0; | |
| 23 virtual void OnCloudPrintPrinterListUnavailable() = 0; | |
| 24 }; | |
| 25 | |
| 26 struct PrinterDetails { | |
| 27 PrinterDetails(); | |
| 28 ~PrinterDetails(); | |
| 29 | |
| 30 std::string id; | |
| 31 std::string display_name; | |
| 32 std::string description; | |
| 33 // TODO(noamsml): std::string user; | |
| 34 }; | |
| 35 | |
| 36 typedef std::vector<PrinterDetails> PrinterList; | |
| 37 typedef PrinterList::const_iterator iterator; | 19 typedef PrinterList::const_iterator iterator; |
| 38 | 20 |
| 39 CloudPrintPrinterList(net::URLRequestContextGetter* request_context, | 21 CloudPrintPrinterList(net::URLRequestContextGetter* request_context, |
| 40 OAuth2TokenService* token_service, | 22 OAuth2TokenService* token_service, |
| 41 const std::string& account_id, | 23 const std::string& account_id, |
| 42 Delegate* delegate); | 24 CloudDeviceListDelegate* delegate); |
| 43 virtual ~CloudPrintPrinterList(); | 25 virtual ~CloudPrintPrinterList(); |
| 44 | 26 |
| 45 void Start(); | 27 void Start(); |
| 46 | 28 |
| 47 virtual void OnGCDAPIFlowError(GCDBaseApiFlow* flow, | 29 virtual void OnGCDAPIFlowError(GCDBaseApiFlow* flow, |
| 48 GCDBaseApiFlow::Status status) OVERRIDE; | 30 GCDBaseApiFlow::Status status) OVERRIDE; |
| 49 | 31 |
| 50 virtual void OnGCDAPIFlowComplete(GCDBaseApiFlow* flow, | 32 virtual void OnGCDAPIFlowComplete( |
| 51 const base::DictionaryValue* value) | 33 GCDBaseApiFlow* flow, |
| 52 OVERRIDE; | 34 const base::DictionaryValue* value) OVERRIDE; |
| 53 | 35 |
| 54 virtual bool GCDIsCloudPrint() OVERRIDE; | 36 virtual bool GCDIsCloudPrint() OVERRIDE; |
| 55 | 37 |
| 56 const PrinterDetails* GetDetailsFor(const std::string& id); | |
| 57 | |
| 58 iterator begin() { return printer_list_.begin(); } | |
| 59 iterator end() { return printer_list_.end(); } | |
| 60 | |
| 61 GCDBaseApiFlow* GetOAuth2ApiFlowForTests() { return &api_flow_; } | 38 GCDBaseApiFlow* GetOAuth2ApiFlowForTests() { return &api_flow_; } |
| 62 | 39 |
| 40 const PrinterList& printer_list() const { |
| 41 return printer_list_; |
| 42 } |
| 43 |
| 63 private: | 44 private: |
| 64 typedef std::map<std::string /*ID*/, int /* index in printer_list_ */> | |
| 65 PrinterIDMap; | |
| 66 | |
| 67 bool FillPrinterDetails(const base::DictionaryValue* printer_value, | 45 bool FillPrinterDetails(const base::DictionaryValue* printer_value, |
| 68 PrinterDetails* printer_details); | 46 CloudDeviceListDelegate::Device* printer_details); |
| 69 | 47 |
| 70 scoped_refptr<net::URLRequestContextGetter> request_context_; | 48 scoped_refptr<net::URLRequestContextGetter> request_context_; |
| 71 PrinterIDMap printer_id_map_; | |
| 72 PrinterList printer_list_; | 49 PrinterList printer_list_; |
| 73 Delegate* delegate_; | 50 CloudDeviceListDelegate* delegate_; |
| 74 GCDBaseApiFlow api_flow_; | 51 GCDBaseApiFlow api_flow_; |
| 75 }; | 52 }; |
| 76 | 53 |
| 77 } // namespace local_discovery | 54 } // namespace local_discovery |
| 78 | 55 |
| 79 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_CLOUD_PRINT_PRINTER_LIST_H_ | 56 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_CLOUD_PRINT_PRINTER_LIST_H_ |
| OLD | NEW |