Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / local_discovery / cloud_print_printer_list.h
blob95b5aca6c64d9464262f8571aadedc2614a346c4
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.
5 #ifndef CHROME_BROWSER_LOCAL_DISCOVERY_CLOUD_PRINT_PRINTER_LIST_H_
6 #define CHROME_BROWSER_LOCAL_DISCOVERY_CLOUD_PRINT_PRINTER_LIST_H_
8 #include <map>
9 #include <string>
10 #include <vector>
12 #include "chrome/browser/local_discovery/cloud_print_base_api_flow.h"
14 namespace local_discovery {
16 class CloudPrintPrinterList : public CloudPrintBaseApiFlow::Delegate {
17 public:
18 class Delegate {
19 public:
20 ~Delegate() {}
22 virtual void OnCloudPrintPrinterListReady() = 0;
23 virtual void OnCloudPrintPrinterListUnavailable() = 0;
26 struct PrinterDetails {
27 PrinterDetails();
28 ~PrinterDetails();
30 std::string id;
31 std::string display_name;
32 std::string description;
33 // TODO(noamsml): std::string user;
36 typedef std::vector<PrinterDetails> PrinterList;
37 typedef PrinterList::const_iterator iterator;
39 CloudPrintPrinterList(net::URLRequestContextGetter* request_context,
40 const std::string& cloud_print_url,
41 OAuth2TokenService* token_service,
42 const std::string& account_id,
43 Delegate* delegate);
44 virtual ~CloudPrintPrinterList();
46 void Start();
48 virtual void OnCloudPrintAPIFlowError(
49 CloudPrintBaseApiFlow* flow,
50 CloudPrintBaseApiFlow::Status status) OVERRIDE;
52 virtual void OnCloudPrintAPIFlowComplete(
53 CloudPrintBaseApiFlow* flow,
54 const base::DictionaryValue* value) OVERRIDE;
56 const PrinterDetails* GetDetailsFor(const std::string& id);
58 iterator begin() { return printer_list_.begin(); }
59 iterator end() { return printer_list_.end(); }
61 CloudPrintBaseApiFlow* GetOAuth2ApiFlowForTests() {
62 return &api_flow_;
65 private:
66 typedef std::map<std::string /*ID*/, int /* index in printer_list_ */>
67 PrinterIDMap;
69 bool FillPrinterDetails(const base::DictionaryValue* printer_value,
70 PrinterDetails* printer_details);
72 scoped_refptr<net::URLRequestContextGetter> request_context_;
73 GURL url_;
74 PrinterIDMap printer_id_map_;
75 PrinterList printer_list_;
76 Delegate* delegate_;
77 CloudPrintBaseApiFlow api_flow_;
80 } // namespace local_discovery
82 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_CLOUD_PRINT_PRINTER_LIST_H_