| 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 #include "chrome/browser/local_discovery/cloud_print_printer_list.h" | |
| 6 | |
| 7 #include <utility> | |
| 8 | |
| 9 #include "base/strings/stringprintf.h" | |
| 10 #include "chrome/common/cloud_print/cloud_print_constants.h" | |
| 11 #include "components/cloud_devices/common/cloud_devices_urls.h" | |
| 12 | |
| 13 namespace local_discovery { | |
| 14 | |
| 15 CloudPrintPrinterList::Device::Device() {} | |
| 16 | |
| 17 CloudPrintPrinterList::Device::~Device() {} | |
| 18 | |
| 19 CloudPrintPrinterList::Delegate::Delegate() {} | |
| 20 | |
| 21 CloudPrintPrinterList::Delegate::~Delegate() {} | |
| 22 | |
| 23 CloudPrintPrinterList::CloudPrintPrinterList(Delegate* delegate) | |
| 24 : delegate_(delegate) {} | |
| 25 | |
| 26 CloudPrintPrinterList::~CloudPrintPrinterList() { | |
| 27 } | |
| 28 | |
| 29 void CloudPrintPrinterList::OnGCDAPIFlowError(GCDApiFlow::Status status) { | |
| 30 delegate_->OnDeviceListUnavailable(); | |
| 31 } | |
| 32 | |
| 33 void CloudPrintPrinterList::OnGCDAPIFlowComplete( | |
| 34 const base::DictionaryValue& value) { | |
| 35 const base::ListValue* printers; | |
| 36 | |
| 37 if (!value.GetList(cloud_print::kPrinterListValue, &printers)) { | |
| 38 delegate_->OnDeviceListUnavailable(); | |
| 39 return; | |
| 40 } | |
| 41 | |
| 42 DeviceList devices; | |
| 43 for (base::ListValue::const_iterator i = printers->begin(); | |
| 44 i != printers->end(); | |
| 45 i++) { | |
| 46 base::DictionaryValue* printer; | |
| 47 Device printer_details; | |
| 48 | |
| 49 if (!(*i)->GetAsDictionary(&printer)) | |
| 50 continue; | |
| 51 | |
| 52 if (!FillPrinterDetails(*printer, &printer_details)) | |
| 53 continue; | |
| 54 | |
| 55 devices.push_back(printer_details); | |
| 56 } | |
| 57 | |
| 58 delegate_->OnDeviceListReady(devices); | |
| 59 } | |
| 60 | |
| 61 GURL CloudPrintPrinterList::GetURL() { | |
| 62 return cloud_devices::GetCloudPrintRelativeURL("search"); | |
| 63 } | |
| 64 | |
| 65 bool CloudPrintPrinterList::FillPrinterDetails( | |
| 66 const base::DictionaryValue& printer_value, | |
| 67 Device* printer_details) { | |
| 68 if (!printer_value.GetString(cloud_print::kIdValue, &printer_details->id)) | |
| 69 return false; | |
| 70 | |
| 71 if (!printer_value.GetString(cloud_print::kDisplayNameValue, | |
| 72 &printer_details->display_name)) { | |
| 73 return false; | |
| 74 } | |
| 75 | |
| 76 // Non-essential. | |
| 77 printer_value.GetString(cloud_print::kPrinterDescValue, | |
| 78 &printer_details->description); | |
| 79 | |
| 80 return true; | |
| 81 } | |
| 82 | |
| 83 } // namespace local_discovery | |
| OLD | NEW |