Chromium Code Reviews| 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 <utility> | 7 #include <utility> |
| 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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 CHECK(printer_dict->GetString("printerAddress", &printer_address)); | 201 CHECK(printer_dict->GetString("printerAddress", &printer_address)); |
| 202 CHECK(printer_dict->GetString("printerProtocol", &printer_protocol)); | 202 CHECK(printer_dict->GetString("printerProtocol", &printer_protocol)); |
| 203 // printerQueue might be null for a printer whose protocol is not 'LPD'. | 203 // printerQueue might be null for a printer whose protocol is not 'LPD'. |
| 204 printer_dict->GetString("printerQueue", &printer_queue); | 204 printer_dict->GetString("printerQueue", &printer_queue); |
| 205 // printerPPDPath might be null for an auto-discovered printer. | 205 // printerPPDPath might be null for an auto-discovered printer. |
| 206 printer_dict->GetString("printerPPDPath", &printer_ppd_path); | 206 printer_dict->GetString("printerPPDPath", &printer_ppd_path); |
| 207 std::string printer_uri = | 207 std::string printer_uri = |
| 208 printer_protocol + "://" + printer_address + "/" + printer_queue; | 208 printer_protocol + "://" + printer_address + "/" + printer_queue; |
| 209 | 209 |
| 210 std::unique_ptr<Printer> printer = base::MakeUnique<Printer>(printer_id); | 210 std::unique_ptr<Printer> printer = base::MakeUnique<Printer>(printer_id); |
| 211 printer_id = printer->id(); | |
| 212 printer->set_display_name(printer_name); | 211 printer->set_display_name(printer_name); |
| 213 printer->set_description(printer_description); | 212 printer->set_description(printer_description); |
| 214 printer->set_manufacturer(printer_manufacturer); | 213 printer->set_manufacturer(printer_manufacturer); |
| 215 printer->set_model(printer_model); | 214 printer->set_model(printer_model); |
| 216 printer->set_uri(printer_uri); | 215 printer->set_uri(printer_uri); |
| 217 if (!printer_ppd_path.empty()) { | 216 if (!printer_ppd_path.empty()) { |
| 218 printer->mutable_ppd_reference()->user_supplied_ppd_url = printer_ppd_path; | 217 printer->mutable_ppd_reference()->user_supplied_ppd_url = printer_ppd_path; |
| 218 bool cached = ppd_provider_->CachePpd(printer->ppd_reference(), | |
| 219 base::FilePath(printer_ppd_path)); | |
| 220 VLOG(1) << "PPD Cached: " << cached; | |
| 219 } else if (!printer_manufacturer.empty() && !printer_model.empty()) { | 221 } else if (!printer_manufacturer.empty() && !printer_model.empty()) { |
| 220 Printer::PpdReference* ppd = printer->mutable_ppd_reference(); | 222 Printer::PpdReference* ppd = printer->mutable_ppd_reference(); |
| 221 ppd->effective_manufacturer = printer_manufacturer; | 223 ppd->effective_manufacturer = printer_manufacturer; |
| 222 ppd->effective_model = printer_model; | 224 ppd->effective_model = printer_model; |
| 223 } | 225 } |
| 224 | 226 |
| 225 chromeos::DebugDaemonClient* client = | 227 const Printer::PpdReference& ppd_reference = printer->ppd_reference(); |
|
Carlson
2016/12/01 01:58:44
Add a comment about why you're doing this? Someon
skau
2016/12/01 21:45:12
I really wish this was a compiler warning. I've a
| |
| 226 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); | 228 ppd_provider_->Resolve( |
| 227 client->CupsAddPrinter( | 229 ppd_reference, |
| 228 printer_id, // record id | 230 base::Bind(&CupsPrintersHandler::OnPPDResolved, |
| 229 printer_uri, // uri | 231 weak_factory_.GetWeakPtr(), base::Passed(&printer))); |
| 230 printer_ppd_path, // ppd location | |
| 231 printer_ppd_path.empty() ? true : false, // ipp everywhere | |
| 232 base::Bind(&CupsPrintersHandler::OnAddedPrinter, | |
| 233 weak_factory_.GetWeakPtr(), base::Passed(std::move(printer))), | |
| 234 base::Bind(&CupsPrintersHandler::OnAddPrinterError, | |
| 235 weak_factory_.GetWeakPtr())); | |
| 236 } | 232 } |
| 237 | 233 |
| 238 void CupsPrintersHandler::OnAddedPrinter(std::unique_ptr<Printer> printer, | 234 void CupsPrintersHandler::OnAddedPrinter(std::unique_ptr<Printer> printer, |
| 239 bool success) { | 235 bool success) { |
| 240 std::string printer_name = printer->display_name(); | 236 std::string printer_name = printer->display_name(); |
| 241 if (success) { | 237 if (success) { |
| 242 PrinterPrefManagerFactory::GetForBrowserContext(profile_)->RegisterPrinter( | 238 PrinterPrefManagerFactory::GetForBrowserContext(profile_)->RegisterPrinter( |
| 243 std::move(printer)); | 239 std::move(printer)); |
| 244 } | 240 } |
| 245 CallJavascriptFunction( | 241 CallJavascriptFunction( |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 384 CallJavascriptFunction("cr.webUIListenerCallback", | 380 CallJavascriptFunction("cr.webUIListenerCallback", |
| 385 base::StringValue("on-printer-discovered"), | 381 base::StringValue("on-printer-discovered"), |
| 386 *printers_list); | 382 *printers_list); |
| 387 } | 383 } |
| 388 | 384 |
| 389 void CupsPrintersHandler::OnDiscoveryDone() { | 385 void CupsPrintersHandler::OnDiscoveryDone() { |
| 390 CallJavascriptFunction("cr.webUIListenerCallback", | 386 CallJavascriptFunction("cr.webUIListenerCallback", |
| 391 base::StringValue("on-printer-discovery-done")); | 387 base::StringValue("on-printer-discovery-done")); |
| 392 } | 388 } |
| 393 | 389 |
| 390 void CupsPrintersHandler::OnPPDResolved( | |
| 391 std::unique_ptr<Printer> printer, | |
| 392 printing::PpdProvider::CallbackResultCode result, | |
| 393 base::FilePath path) { | |
| 394 if (result != printing::PpdProvider::SUCCESS) { | |
| 395 // TODO(skau): Add appropriate failure modes crbug.com/670068. | |
| 396 OnAddPrinterError(); | |
| 397 return; | |
| 398 } | |
| 399 | |
| 400 bool ipp_everywhere = Printer::IsIppEverywhere(*printer); | |
| 401 std::string ppd_path = ipp_everywhere ? "" : path.value(); | |
|
Carlson
2016/12/01 01:58:44
Wait, what? So if it's an ipp everywhere printer
skau
2016/12/01 21:45:12
What I'm doing here makes no sense. I've moved th
| |
| 402 std::string printer_id = printer->id(); | |
| 403 std::string printer_uri = printer->uri(); | |
| 404 | |
| 405 chromeos::DebugDaemonClient* client = | |
| 406 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); | |
| 407 client->CupsAddPrinter( | |
| 408 printer_id, printer_uri, ppd_path, ipp_everywhere, | |
| 409 base::Bind(&CupsPrintersHandler::OnAddedPrinter, | |
| 410 weak_factory_.GetWeakPtr(), base::Passed(&printer)), | |
| 411 base::Bind(&CupsPrintersHandler::OnAddPrinterError, | |
| 412 weak_factory_.GetWeakPtr())); | |
| 413 } | |
| 414 | |
| 394 } // namespace settings | 415 } // namespace settings |
| 395 } // namespace chromeos | 416 } // namespace chromeos |
| OLD | NEW |