OLD | NEW |
(Empty) | |
| 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_CLOUD_PRINT_PRINTER_LIST_H_ |
| 6 #define CHROME_BROWSER_LOCAL_DISCOVERY_CLOUD_PRINT_PRINTER_LIST_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <string> |
| 10 #include <vector> |
| 11 |
| 12 #include "chrome/browser/local_discovery/cloud_print_base_api_flow.h" |
| 13 |
| 14 namespace local_discovery { |
| 15 |
| 16 class CloudPrintPrinterList : public CloudPrintBaseApiFlow::Delegate { |
| 17 public: |
| 18 class Delegate { |
| 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; |
| 38 |
| 39 CloudPrintPrinterList(net::URLRequestContextGetter* request_context, |
| 40 const std::string& cloud_print_url, |
| 41 OAuth2TokenService* token_service, |
| 42 Delegate* delegate); |
| 43 virtual ~CloudPrintPrinterList(); |
| 44 |
| 45 void Start(); |
| 46 |
| 47 virtual void OnCloudPrintAPIFlowError( |
| 48 CloudPrintBaseApiFlow* flow, |
| 49 CloudPrintBaseApiFlow::Status status) OVERRIDE; |
| 50 |
| 51 virtual void OnCloudPrintAPIFlowComplete( |
| 52 CloudPrintBaseApiFlow* flow, |
| 53 const base::DictionaryValue* value) OVERRIDE; |
| 54 |
| 55 const PrinterDetails* GetDetailsFor(const std::string& id); |
| 56 |
| 57 iterator begin() { return printer_list_.begin(); } |
| 58 iterator end() { return printer_list_.end(); } |
| 59 |
| 60 CloudPrintBaseApiFlow* GetOAuth2ApiFlowForTests() { |
| 61 return &api_flow_; |
| 62 } |
| 63 |
| 64 private: |
| 65 typedef std::map<std::string /*ID*/, int /* index in printer_list_ */> |
| 66 PrinterIDMap; |
| 67 |
| 68 bool FillPrinterDetails(const base::DictionaryValue* printer_value, |
| 69 PrinterDetails* printer_details); |
| 70 |
| 71 scoped_refptr<net::URLRequestContextGetter> request_context_; |
| 72 GURL url_; |
| 73 PrinterIDMap printer_id_map_; |
| 74 PrinterList printer_list_; |
| 75 Delegate* delegate_; |
| 76 CloudPrintBaseApiFlow api_flow_; |
| 77 }; |
| 78 |
| 79 } // namespace local_discovery |
| 80 |
| 81 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_CLOUD_PRINT_PRINTER_LIST_H_ |
OLD | NEW |