| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include "chrome/browser/ui/webui/settings/chromeos/cups_printers_handler.h" | 5 #include "chrome/browser/ui/webui/settings/chromeos/cups_printers_handler.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 CHECK(printer_dict->GetString("printerModel", &printer_model)); | 175 CHECK(printer_dict->GetString("printerModel", &printer_model)); |
| 176 CHECK(printer_dict->GetString("printerAddress", &printer_address)); | 176 CHECK(printer_dict->GetString("printerAddress", &printer_address)); |
| 177 CHECK(printer_dict->GetString("printerProtocol", &printer_protocol)); | 177 CHECK(printer_dict->GetString("printerProtocol", &printer_protocol)); |
| 178 // printerQueue might be null for a printer whose protocol is not 'LPD'. | 178 // printerQueue might be null for a printer whose protocol is not 'LPD'. |
| 179 printer_dict->GetString("printerQueue", &printer_queue); | 179 printer_dict->GetString("printerQueue", &printer_queue); |
| 180 // printerPPDPath might be null for an auto-discovered printer. | 180 // printerPPDPath might be null for an auto-discovered printer. |
| 181 printer_dict->GetString("printerPPDPath", &printer_ppd_path); | 181 printer_dict->GetString("printerPPDPath", &printer_ppd_path); |
| 182 std::string printer_uri = | 182 std::string printer_uri = |
| 183 printer_protocol + "://" + printer_address + "/" + printer_queue; | 183 printer_protocol + "://" + printer_address + "/" + printer_queue; |
| 184 | 184 |
| 185 std::unique_ptr<Printer> printer = base::MakeUnique<Printer>(); | 185 std::unique_ptr<Printer> printer = base::MakeUnique<Printer>(printer_id); |
| 186 printer->set_id(printer_id); | 186 printer_id = printer->id(); |
| 187 printer->set_display_name(printer_name); | 187 printer->set_display_name(printer_name); |
| 188 printer->set_description(printer_description); | 188 printer->set_description(printer_description); |
| 189 printer->set_manufacturer(printer_manufacturer); | 189 printer->set_manufacturer(printer_manufacturer); |
| 190 printer->set_model(printer_model); | 190 printer->set_model(printer_model); |
| 191 printer->set_uri(printer_uri); | 191 printer->set_uri(printer_uri); |
| 192 if (!printer_ppd_path.empty()) { |
| 193 printer->mutable_ppd_reference()->user_supplied_ppd_url = printer_ppd_path; |
| 194 } else if (!printer_manufacturer.empty() && !printer_model.empty()) { |
| 195 Printer::PpdReference* ppd = printer->mutable_ppd_reference(); |
| 196 ppd->effective_manufacturer = printer_manufacturer; |
| 197 ppd->effective_model = printer_model; |
| 198 } |
| 192 | 199 |
| 193 chromeos::DebugDaemonClient* client = | 200 chromeos::DebugDaemonClient* client = |
| 194 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); | 201 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); |
| 195 client->CupsAddPrinter( | 202 client->CupsAddPrinter( |
| 196 printer_name, printer_uri, | 203 printer_id, // record id |
| 197 printer_ppd_path, | 204 printer_uri, // uri |
| 198 printer_ppd_path.empty() ? true : false, // ipp everywhere | 205 printer_ppd_path, // ppd location |
| 206 printer_ppd_path.empty() ? true : false, // ipp everywhere |
| 199 base::Bind(&CupsPrintersHandler::OnAddedPrinter, | 207 base::Bind(&CupsPrintersHandler::OnAddedPrinter, |
| 200 weak_factory_.GetWeakPtr(), base::Passed(std::move(printer))), | 208 weak_factory_.GetWeakPtr(), base::Passed(std::move(printer))), |
| 201 base::Bind(&CupsPrintersHandler::OnAddPrinterError, | 209 base::Bind(&CupsPrintersHandler::OnAddPrinterError, |
| 202 weak_factory_.GetWeakPtr())); | 210 weak_factory_.GetWeakPtr())); |
| 203 } | 211 } |
| 204 | 212 |
| 205 void CupsPrintersHandler::OnAddedPrinter(std::unique_ptr<Printer> printer, | 213 void CupsPrintersHandler::OnAddedPrinter(std::unique_ptr<Printer> printer, |
| 206 bool success) { | 214 bool success) { |
| 207 std::string printer_name = printer->display_name(); | 215 std::string printer_name = printer->display_name(); |
| 208 if (success) { | 216 if (success) { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 *printers_list); | 290 *printers_list); |
| 283 } | 291 } |
| 284 | 292 |
| 285 void CupsPrintersHandler::OnDiscoveryDone() { | 293 void CupsPrintersHandler::OnDiscoveryDone() { |
| 286 CallJavascriptFunction("cr.webUIListenerCallback", | 294 CallJavascriptFunction("cr.webUIListenerCallback", |
| 287 base::StringValue("on-printer-discovery-done")); | 295 base::StringValue("on-printer-discovery-done")); |
| 288 } | 296 } |
| 289 | 297 |
| 290 } // namespace settings | 298 } // namespace settings |
| 291 } // namespace chromeos | 299 } // namespace chromeos |
| OLD | NEW |