| 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" |
| 11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 12 #include "base/json/json_string_value_serializer.h" |
| 12 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 13 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 14 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 15 #include "base/threading/sequenced_task_runner_handle.h" | 16 #include "base/threading/sequenced_task_runner_handle.h" |
| 16 #include "base/values.h" | 17 #include "base/values.h" |
| 17 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
| 18 #include "chrome/browser/chromeos/printing/ppd_provider_factory.h" | 19 #include "chrome/browser/chromeos/printing/ppd_provider_factory.h" |
| 19 #include "chrome/browser/chromeos/printing/printer_pref_manager_factory.h" | 20 #include "chrome/browser/chromeos/printing/printer_pref_manager_factory.h" |
| 20 #include "chrome/browser/download/download_prefs.h" | 21 #include "chrome/browser/download/download_prefs.h" |
| 21 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/ui/browser_finder.h" | 23 #include "chrome/browser/ui/browser_finder.h" |
| 23 #include "chrome/browser/ui/browser_window.h" | 24 #include "chrome/browser/ui/browser_window.h" |
| 24 #include "chrome/browser/ui/chrome_select_file_policy.h" | 25 #include "chrome/browser/ui/chrome_select_file_policy.h" |
| 25 #include "chrome/common/chrome_paths.h" | 26 #include "chrome/common/chrome_paths.h" |
| 26 #include "chromeos/dbus/dbus_thread_manager.h" | 27 #include "chromeos/dbus/dbus_thread_manager.h" |
| 27 #include "chromeos/dbus/debug_daemon_client.h" | 28 #include "chromeos/dbus/debug_daemon_client.h" |
| 28 #include "chromeos/printing/fake_printer_discoverer.h" | 29 #include "chromeos/printing/fake_printer_discoverer.h" |
| 29 #include "chromeos/printing/ppd_cache.h" | 30 #include "chromeos/printing/ppd_cache.h" |
| 30 #include "chromeos/printing/ppd_provider.h" | 31 #include "chromeos/printing/ppd_provider.h" |
| 31 #include "content/public/browser/browser_context.h" | 32 #include "content/public/browser/browser_context.h" |
| 32 #include "content/public/browser/browser_thread.h" | 33 #include "content/public/browser/browser_thread.h" |
| 33 #include "content/public/browser/web_ui.h" | 34 #include "content/public/browser/web_ui.h" |
| 34 #include "google_apis/google_api_keys.h" | 35 #include "google_apis/google_api_keys.h" |
| 36 #include "net/base/filename_util.h" |
| 35 #include "net/url_request/url_request_context_getter.h" | 37 #include "net/url_request/url_request_context_getter.h" |
| 36 #include "printing/backend/print_backend.h" | 38 #include "printing/backend/print_backend.h" |
| 37 #include "url/third_party/mozilla/url_parse.h" | 39 #include "url/third_party/mozilla/url_parse.h" |
| 38 | 40 |
| 39 namespace chromeos { | 41 namespace chromeos { |
| 40 namespace settings { | 42 namespace settings { |
| 41 | 43 |
| 42 namespace { | 44 namespace { |
| 43 | 45 |
| 44 void OnRemovedPrinter(bool success) {} | 46 void OnRemovedPrinter(bool success) {} |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 std::string printer_ppd_path; | 192 std::string printer_ppd_path; |
| 191 CHECK(printer_dict->GetString("printerId", &printer_id)); | 193 CHECK(printer_dict->GetString("printerId", &printer_id)); |
| 192 CHECK(printer_dict->GetString("printerName", &printer_name)); | 194 CHECK(printer_dict->GetString("printerName", &printer_name)); |
| 193 CHECK(printer_dict->GetString("printerDescription", &printer_description)); | 195 CHECK(printer_dict->GetString("printerDescription", &printer_description)); |
| 194 CHECK(printer_dict->GetString("printerManufacturer", &printer_manufacturer)); | 196 CHECK(printer_dict->GetString("printerManufacturer", &printer_manufacturer)); |
| 195 CHECK(printer_dict->GetString("printerModel", &printer_model)); | 197 CHECK(printer_dict->GetString("printerModel", &printer_model)); |
| 196 CHECK(printer_dict->GetString("printerAddress", &printer_address)); | 198 CHECK(printer_dict->GetString("printerAddress", &printer_address)); |
| 197 CHECK(printer_dict->GetString("printerProtocol", &printer_protocol)); | 199 CHECK(printer_dict->GetString("printerProtocol", &printer_protocol)); |
| 198 // printerQueue might be null for a printer whose protocol is not 'LPD'. | 200 // printerQueue might be null for a printer whose protocol is not 'LPD'. |
| 199 printer_dict->GetString("printerQueue", &printer_queue); | 201 printer_dict->GetString("printerQueue", &printer_queue); |
| 202 |
| 200 // printerPPDPath might be null for an auto-discovered printer. | 203 // printerPPDPath might be null for an auto-discovered printer. |
| 201 printer_dict->GetString("printerPPDPath", &printer_ppd_path); | 204 printer_dict->GetString("printerPPDPath", &printer_ppd_path); |
| 202 std::string printer_uri = | 205 std::string printer_uri = |
| 203 printer_protocol + "://" + printer_address + "/" + printer_queue; | 206 printer_protocol + "://" + printer_address + "/" + printer_queue; |
| 204 | 207 |
| 205 std::unique_ptr<Printer> printer = base::MakeUnique<Printer>(printer_id); | 208 std::unique_ptr<Printer> printer = base::MakeUnique<Printer>(printer_id); |
| 206 printer->set_display_name(printer_name); | 209 printer->set_display_name(printer_name); |
| 207 printer->set_description(printer_description); | 210 printer->set_description(printer_description); |
| 208 printer->set_manufacturer(printer_manufacturer); | 211 printer->set_manufacturer(printer_manufacturer); |
| 209 printer->set_model(printer_model); | 212 printer->set_model(printer_model); |
| 210 printer->set_uri(printer_uri); | 213 printer->set_uri(printer_uri); |
| 211 if (!printer_ppd_path.empty()) { | 214 if (!printer_ppd_path.empty()) { |
| 212 printer->mutable_ppd_reference()->user_supplied_ppd_url = printer_ppd_path; | 215 GURL tmp = net::FilePathToFileURL(base::FilePath(printer_ppd_path)); |
| 213 if (!ppd_provider_->CachePpd(printer->ppd_reference(), | 216 if (!tmp.is_valid()) { |
| 214 base::FilePath(printer_ppd_path))) { | 217 LOG(ERROR) << "Invalid ppd path: " << printer_ppd_path; |
| 215 LOG(WARNING) << "PPD could not be stored in the cache"; | |
| 216 OnAddPrinterError(); | 218 OnAddPrinterError(); |
| 217 return; | 219 return; |
| 218 } | 220 } |
| 221 printer->mutable_ppd_reference()->user_supplied_ppd_url = tmp.spec(); |
| 219 } else if (!printer_manufacturer.empty() && !printer_model.empty()) { | 222 } else if (!printer_manufacturer.empty() && !printer_model.empty()) { |
| 220 Printer::PpdReference* ppd = printer->mutable_ppd_reference(); | 223 // Using the manufacturer and model, get a ppd reference. |
| 221 ppd->effective_manufacturer = printer_manufacturer; | 224 if (!ppd_provider_->GetPpdReference(printer_manufacturer, printer_model, |
| 222 ppd->effective_model = printer_model; | 225 printer->mutable_ppd_reference())) { |
| 226 LOG(ERROR) << "Failed to get ppd reference"; |
| 227 OnAddPrinterError(); |
| 228 return; |
| 229 } |
| 223 } | 230 } |
| 224 | 231 |
| 225 if (printer->IsIppEverywhere()) { | 232 if (printer->IsIppEverywhere()) { |
| 226 AddPrinterToCups(std::move(printer), base::FilePath(), true); | 233 std::string printer_id = printer->id(); |
| 227 return; | 234 std::string printer_uri = printer->uri(); |
| 235 |
| 236 chromeos::DebugDaemonClient* client = |
| 237 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); |
| 238 |
| 239 client->CupsAddAutoConfiguredPrinter( |
| 240 printer_id, printer_uri, |
| 241 base::Bind(&CupsPrintersHandler::OnAddedPrinter, |
| 242 weak_factory_.GetWeakPtr(), base::Passed(&printer)), |
| 243 base::Bind(&CupsPrintersHandler::OnAddPrinterError, |
| 244 weak_factory_.GetWeakPtr())); |
| 245 } else { |
| 246 // We need to save a reference to members of printer since we transfer |
| 247 // ownership in the bind call. |
| 248 const Printer::PpdReference ppd_reference = printer->ppd_reference(); |
| 249 ppd_provider_->ResolvePpd( |
| 250 ppd_reference, |
| 251 base::Bind(&CupsPrintersHandler::ResolvePpdDone, |
| 252 weak_factory_.GetWeakPtr(), base::Passed(&printer))); |
| 228 } | 253 } |
| 229 | |
| 230 // We need to save a reference to members of printer since we transfer | |
| 231 // ownership in the bind call. | |
| 232 const Printer::PpdReference& ppd_reference = printer->ppd_reference(); | |
| 233 ppd_provider_->Resolve( | |
| 234 ppd_reference, | |
| 235 base::Bind(&CupsPrintersHandler::OnPPDResolved, | |
| 236 weak_factory_.GetWeakPtr(), base::Passed(&printer))); | |
| 237 } | 254 } |
| 238 | 255 |
| 239 void CupsPrintersHandler::OnAddedPrinter(std::unique_ptr<Printer> printer, | 256 void CupsPrintersHandler::OnAddedPrinter(std::unique_ptr<Printer> printer, |
| 240 bool success) { | 257 int32_t result_code) { |
| 241 std::string printer_name = printer->display_name(); | 258 std::string printer_name = printer->display_name(); |
| 259 bool success = (result_code == 0); |
| 242 if (success) { | 260 if (success) { |
| 243 PrinterPrefManagerFactory::GetForBrowserContext(profile_)->RegisterPrinter( | 261 PrinterPrefManagerFactory::GetForBrowserContext(profile_)->RegisterPrinter( |
| 244 std::move(printer)); | 262 std::move(printer)); |
| 245 } | 263 } |
| 246 CallJavascriptFunction( | 264 CallJavascriptFunction( |
| 247 "cr.webUIListenerCallback", base::StringValue("on-add-cups-printer"), | 265 "cr.webUIListenerCallback", base::StringValue("on-add-cups-printer"), |
| 248 base::FundamentalValue(success), base::StringValue(printer_name)); | 266 base::FundamentalValue(success), base::StringValue(printer_name)); |
| 249 } | 267 } |
| 250 | 268 |
| 251 void CupsPrintersHandler::OnAddPrinterError() { | 269 void CupsPrintersHandler::OnAddPrinterError() { |
| 252 CallJavascriptFunction("cr.webUIListenerCallback", | 270 CallJavascriptFunction("cr.webUIListenerCallback", |
| 253 base::StringValue("on-add-cups-printer"), | 271 base::StringValue("on-add-cups-printer"), |
| 254 base::FundamentalValue(false), base::StringValue("")); | 272 base::FundamentalValue(false), base::StringValue("")); |
| 255 } | 273 } |
| 256 | 274 |
| 257 void CupsPrintersHandler::HandleGetCupsPrinterManufacturers( | 275 void CupsPrintersHandler::HandleGetCupsPrinterManufacturers( |
| 258 const base::ListValue* args) { | 276 const base::ListValue* args) { |
| 277 AllowJavascript(); |
| 259 std::string js_callback; | 278 std::string js_callback; |
| 260 CHECK_EQ(1U, args->GetSize()); | 279 CHECK_EQ(1U, args->GetSize()); |
| 261 CHECK(args->GetString(0, &js_callback)); | 280 CHECK(args->GetString(0, &js_callback)); |
| 262 ppd_provider_->QueryAvailable( | 281 ppd_provider_->ResolveManufacturers( |
| 263 base::Bind(&CupsPrintersHandler::QueryAvailableManufacturersDone, | 282 base::Bind(&CupsPrintersHandler::ResolveManufacturersDone, |
| 264 weak_factory_.GetWeakPtr(), | 283 weak_factory_.GetWeakPtr(), js_callback)); |
| 265 js_callback)); | |
| 266 } | 284 } |
| 267 | 285 |
| 268 void CupsPrintersHandler::HandleGetCupsPrinterModels( | 286 void CupsPrintersHandler::HandleGetCupsPrinterModels( |
| 269 const base::ListValue* args) { | 287 const base::ListValue* args) { |
| 288 AllowJavascript(); |
| 270 std::string js_callback; | 289 std::string js_callback; |
| 271 std::string manufacturer; | 290 std::string manufacturer; |
| 272 CHECK_EQ(2U, args->GetSize()); | 291 CHECK_EQ(2U, args->GetSize()); |
| 273 CHECK(args->GetString(0, &js_callback)); | 292 CHECK(args->GetString(0, &js_callback)); |
| 274 CHECK(args->GetString(1, &manufacturer)); | 293 CHECK(args->GetString(1, &manufacturer)); |
| 275 // Special case the "asked with no manufacturer case" since the UI sometimes | 294 |
| 276 // triggers this and it should yield a trivial (empty) result | 295 // Empty manufacturer queries may be triggered as a part of the ui |
| 296 // initialization, and should just return empty results. |
| 277 if (manufacturer.empty()) { | 297 if (manufacturer.empty()) { |
| 278 base::SequencedTaskRunnerHandle::Get()->PostTask( | 298 base::DictionaryValue response; |
| 279 FROM_HERE, | 299 response.SetBoolean("success", true); |
| 280 base::Bind(&CupsPrintersHandler::QueryAvailableModelsDone, | 300 response.Set("models", base::MakeUnique<base::ListValue>()); |
| 281 weak_factory_.GetWeakPtr(), js_callback, manufacturer, | 301 ResolveJavascriptCallback(base::StringValue(js_callback), response); |
| 282 chromeos::printing::PpdProvider::SUCCESS, | 302 return; |
| 283 chromeos::printing::PpdProvider::AvailablePrintersMap())); | |
| 284 } else { | |
| 285 ppd_provider_->QueryAvailable( | |
| 286 base::Bind(&CupsPrintersHandler::QueryAvailableModelsDone, | |
| 287 weak_factory_.GetWeakPtr(), js_callback, manufacturer)); | |
| 288 } | 303 } |
| 304 |
| 305 ppd_provider_->ResolvePrinters( |
| 306 manufacturer, base::Bind(&CupsPrintersHandler::ResolvePrintersDone, |
| 307 weak_factory_.GetWeakPtr(), js_callback)); |
| 289 } | 308 } |
| 290 | 309 |
| 291 void CupsPrintersHandler::HandleSelectPPDFile(const base::ListValue* args) { | 310 void CupsPrintersHandler::HandleSelectPPDFile(const base::ListValue* args) { |
| 292 CHECK_EQ(1U, args->GetSize()); | 311 CHECK_EQ(1U, args->GetSize()); |
| 293 CHECK(args->GetString(0, &webui_callback_id_)); | 312 CHECK(args->GetString(0, &webui_callback_id_)); |
| 294 | 313 |
| 295 base::FilePath downloads_path = DownloadPrefs::FromDownloadManager( | 314 base::FilePath downloads_path = |
| 296 content::BrowserContext::GetDownloadManager(profile_))->DownloadPath(); | 315 DownloadPrefs::FromDownloadManager( |
| 316 content::BrowserContext::GetDownloadManager(profile_)) |
| 317 ->DownloadPath(); |
| 297 | 318 |
| 298 select_file_dialog_ = ui::SelectFileDialog::Create( | 319 select_file_dialog_ = ui::SelectFileDialog::Create( |
| 299 this, new ChromeSelectFilePolicy(web_ui()->GetWebContents())); | 320 this, new ChromeSelectFilePolicy(web_ui()->GetWebContents())); |
| 300 gfx::NativeWindow owning_window = | 321 gfx::NativeWindow owning_window = |
| 301 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents()) | 322 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents()) |
| 302 ->window() | 323 ->window() |
| 303 ->GetNativeWindow(); | 324 ->GetNativeWindow(); |
| 304 select_file_dialog_->SelectFile( | 325 select_file_dialog_->SelectFile( |
| 305 ui::SelectFileDialog::SELECT_OPEN_FILE, base::string16(), downloads_path, | 326 ui::SelectFileDialog::SELECT_OPEN_FILE, base::string16(), downloads_path, |
| 306 nullptr, 0, FILE_PATH_LITERAL(""), owning_window, nullptr); | 327 nullptr, 0, FILE_PATH_LITERAL(""), owning_window, nullptr); |
| 307 } | 328 } |
| 308 | 329 |
| 309 void CupsPrintersHandler::QueryAvailableManufacturersDone( | 330 void CupsPrintersHandler::ResolveManufacturersDone( |
| 310 const std::string& js_callback, | 331 const std::string& js_callback, |
| 311 chromeos::printing::PpdProvider::CallbackResultCode result_code, | 332 chromeos::printing::PpdProvider::CallbackResultCode result_code, |
| 312 const chromeos::printing::PpdProvider::AvailablePrintersMap& available) { | 333 const std::vector<std::string>& manufacturers) { |
| 313 auto manufacturers = base::MakeUnique<base::ListValue>(); | 334 auto manufacturers_value = base::MakeUnique<base::ListValue>(); |
| 314 if (result_code == chromeos::printing::PpdProvider::SUCCESS) { | 335 if (result_code == chromeos::printing::PpdProvider::SUCCESS) { |
| 315 for (const auto& entry : available) { | 336 manufacturers_value->AppendStrings(manufacturers); |
| 316 manufacturers->AppendString(entry.first); | |
| 317 } | |
| 318 } | 337 } |
| 319 base::DictionaryValue response; | 338 base::DictionaryValue response; |
| 320 response.SetBoolean("success", | 339 response.SetBoolean("success", |
| 321 result_code == chromeos::printing::PpdProvider::SUCCESS); | 340 result_code == chromeos::printing::PpdProvider::SUCCESS); |
| 322 response.Set("manufacturers", std::move(manufacturers)); | 341 response.Set("manufacturers", std::move(manufacturers_value)); |
| 323 ResolveJavascriptCallback(base::StringValue(js_callback), response); | 342 ResolveJavascriptCallback(base::StringValue(js_callback), response); |
| 324 } | 343 } |
| 325 | 344 |
| 326 void CupsPrintersHandler::QueryAvailableModelsDone( | 345 void CupsPrintersHandler::ResolvePrintersDone( |
| 327 const std::string& js_callback, | 346 const std::string& js_callback, |
| 328 const std::string& manufacturer, | |
| 329 chromeos::printing::PpdProvider::CallbackResultCode result_code, | 347 chromeos::printing::PpdProvider::CallbackResultCode result_code, |
| 330 const chromeos::printing::PpdProvider::AvailablePrintersMap& available) { | 348 const std::vector<std::string>& printers) { |
| 331 auto models = base::MakeUnique<base::ListValue>(); | 349 auto printers_value = base::MakeUnique<base::ListValue>(); |
| 332 if (result_code == chromeos::printing::PpdProvider::SUCCESS) { | 350 if (result_code == chromeos::printing::PpdProvider::SUCCESS) { |
| 333 const auto it = available.find(manufacturer); | 351 printers_value->AppendStrings(printers); |
| 334 if (it != available.end()) { | |
| 335 // Everything looks good. | |
| 336 models->AppendStrings(it->second); | |
| 337 } | |
| 338 } | 352 } |
| 339 base::DictionaryValue response; | 353 base::DictionaryValue response; |
| 340 response.SetBoolean("success", | 354 response.SetBoolean("success", |
| 341 result_code == chromeos::printing::PpdProvider::SUCCESS); | 355 result_code == chromeos::printing::PpdProvider::SUCCESS); |
| 342 response.Set("models", std::move(models)); | 356 response.Set("models", std::move(printers_value)); |
| 343 ResolveJavascriptCallback(base::StringValue(js_callback), response); | 357 ResolveJavascriptCallback(base::StringValue(js_callback), response); |
| 344 } | 358 } |
| 345 | 359 |
| 346 void CupsPrintersHandler::FileSelected(const base::FilePath& path, | 360 void CupsPrintersHandler::FileSelected(const base::FilePath& path, |
| 347 int index, | 361 int index, |
| 348 void* params) { | 362 void* params) { |
| 349 DCHECK(!webui_callback_id_.empty()); | 363 DCHECK(!webui_callback_id_.empty()); |
| 350 ResolveJavascriptCallback(base::StringValue(webui_callback_id_), | 364 ResolveJavascriptCallback(base::StringValue(webui_callback_id_), |
| 351 base::StringValue(path.value())); | 365 base::StringValue(path.value())); |
| 352 webui_callback_id_.clear(); | 366 webui_callback_id_.clear(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 CallJavascriptFunction("cr.webUIListenerCallback", | 399 CallJavascriptFunction("cr.webUIListenerCallback", |
| 386 base::StringValue("on-printer-discovered"), | 400 base::StringValue("on-printer-discovered"), |
| 387 *printers_list); | 401 *printers_list); |
| 388 } | 402 } |
| 389 | 403 |
| 390 void CupsPrintersHandler::OnDiscoveryDone() { | 404 void CupsPrintersHandler::OnDiscoveryDone() { |
| 391 CallJavascriptFunction("cr.webUIListenerCallback", | 405 CallJavascriptFunction("cr.webUIListenerCallback", |
| 392 base::StringValue("on-printer-discovery-done")); | 406 base::StringValue("on-printer-discovery-done")); |
| 393 } | 407 } |
| 394 | 408 |
| 395 void CupsPrintersHandler::AddPrinterToCups(std::unique_ptr<Printer> printer, | 409 void CupsPrintersHandler::ResolvePpdDone( |
| 396 const base::FilePath& ppd_path, | 410 std::unique_ptr<Printer> printer, |
| 397 bool ipp_everywhere) { | 411 printing::PpdProvider::CallbackResultCode result, |
| 412 const std::string& ppd_contents) { |
| 413 if (result != printing::PpdProvider::SUCCESS) { |
| 414 // TODO(skau): Add appropriate failure modes crbug.com/670068. |
| 415 LOG(ERROR) << "Error resolving"; |
| 416 OnAddPrinterError(); |
| 417 return; |
| 418 } |
| 419 |
| 398 std::string printer_id = printer->id(); | 420 std::string printer_id = printer->id(); |
| 399 std::string printer_uri = printer->uri(); | 421 std::string printer_uri = printer->uri(); |
| 400 | 422 |
| 401 chromeos::DebugDaemonClient* client = | 423 chromeos::DebugDaemonClient* client = |
| 402 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); | 424 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); |
| 403 client->CupsAddPrinter( | 425 |
| 404 printer_id, printer_uri, ppd_path.value(), ipp_everywhere, | 426 client->CupsAddManuallyConfiguredPrinter( |
| 427 printer_id, printer_uri, ppd_contents, |
| 405 base::Bind(&CupsPrintersHandler::OnAddedPrinter, | 428 base::Bind(&CupsPrintersHandler::OnAddedPrinter, |
| 406 weak_factory_.GetWeakPtr(), base::Passed(&printer)), | 429 weak_factory_.GetWeakPtr(), base::Passed(&printer)), |
| 407 base::Bind(&CupsPrintersHandler::OnAddPrinterError, | 430 base::Bind(&CupsPrintersHandler::OnAddPrinterError, |
| 408 weak_factory_.GetWeakPtr())); | 431 weak_factory_.GetWeakPtr())); |
| 409 } | 432 } |
| 410 | 433 |
| 411 void CupsPrintersHandler::OnPPDResolved( | |
| 412 std::unique_ptr<Printer> printer, | |
| 413 printing::PpdProvider::CallbackResultCode result, | |
| 414 base::FilePath path) { | |
| 415 if (result != printing::PpdProvider::SUCCESS) { | |
| 416 // TODO(skau): Add appropriate failure modes crbug.com/670068. | |
| 417 OnAddPrinterError(); | |
| 418 return; | |
| 419 } | |
| 420 | |
| 421 AddPrinterToCups(std::move(printer), path, false /* never ipp everywhere */); | |
| 422 } | |
| 423 | |
| 424 } // namespace settings | 434 } // namespace settings |
| 425 } // namespace chromeos | 435 } // namespace chromeos |
| OLD | NEW |