| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/chromeos/printing/printer_configurer.h" | 5 #include "chrome/browser/chromeos/printing/printer_configurer.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 private: | 65 private: |
| 66 void OnAddedPrinter(const Printer& printer, | 66 void OnAddedPrinter(const Printer& printer, |
| 67 const PrinterSetupCallback& cb, | 67 const PrinterSetupCallback& cb, |
| 68 int32_t result_code) { | 68 int32_t result_code) { |
| 69 // It's expected that debug daemon posts callbacks on the UI thread. | 69 // It's expected that debug daemon posts callbacks on the UI thread. |
| 70 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 70 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 71 | 71 |
| 72 PrinterSetupResult result; | 72 PrinterSetupResult result; |
| 73 switch (result_code) { | 73 switch (result_code) { |
| 74 case debugd::CupsResult::CUPS_SUCCESS: | 74 case debugd::CupsResult::CUPS_SUCCESS: |
| 75 result = PrinterSetupResult::SUCCESS; | 75 result = PrinterSetupResult::kSuccess; |
| 76 break; | 76 break; |
| 77 case debugd::CupsResult::CUPS_INVALID_PPD: | 77 case debugd::CupsResult::CUPS_INVALID_PPD: |
| 78 result = PrinterSetupResult::INVALID_PPD; | 78 result = PrinterSetupResult::kInvalidPpd; |
| 79 break; | 79 break; |
| 80 case debugd::CupsResult::CUPS_AUTOCONF_FAILURE: | 80 case debugd::CupsResult::CUPS_AUTOCONF_FAILURE: |
| 81 // There are other reasons autoconf fails but this is the most likely. | 81 // There are other reasons autoconf fails but this is the most likely. |
| 82 result = PrinterSetupResult::PRINTER_UNREACHABLE; | 82 result = PrinterSetupResult::kPrinterUnreachable; |
| 83 break; | 83 break; |
| 84 case debugd::CupsResult::CUPS_LPADMIN_FAILURE: | 84 case debugd::CupsResult::CUPS_LPADMIN_FAILURE: |
| 85 // Printers should always be configurable by lpadmin. | 85 // Printers should always be configurable by lpadmin. |
| 86 NOTREACHED() << "lpadmin could not add the printer"; | 86 NOTREACHED() << "lpadmin could not add the printer"; |
| 87 result = PrinterSetupResult::FATAL_ERROR; | 87 result = PrinterSetupResult::kFatalError; |
| 88 break; | 88 break; |
| 89 case debugd::CupsResult::CUPS_FATAL: | 89 case debugd::CupsResult::CUPS_FATAL: |
| 90 default: | 90 default: |
| 91 // We have no idea. It must be fatal. | 91 // We have no idea. It must be fatal. |
| 92 LOG(ERROR) << "Unrecognized printer setup error: " << result_code; | 92 LOG(ERROR) << "Unrecognized printer setup error: " << result_code; |
| 93 result = PrinterSetupResult::FATAL_ERROR; | 93 result = PrinterSetupResult::kFatalError; |
| 94 break; | 94 break; |
| 95 } | 95 } |
| 96 | 96 |
| 97 cb.Run(result); | 97 cb.Run(result); |
| 98 } | 98 } |
| 99 | 99 |
| 100 void OnDbusError(const PrinterSetupCallback& cb) { | 100 void OnDbusError(const PrinterSetupCallback& cb) { |
| 101 // The callback is expected to run on the UI thread. | 101 // The callback is expected to run on the UI thread. |
| 102 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 102 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 103 LOG(WARNING) << "Could not contact debugd"; | 103 LOG(WARNING) << "Could not contact debugd"; |
| 104 cb.Run(PrinterSetupResult::DBUS_ERROR); | 104 cb.Run(PrinterSetupResult::kDbusError); |
| 105 } | 105 } |
| 106 | 106 |
| 107 void AddPrinter(const Printer& printer, | 107 void AddPrinter(const Printer& printer, |
| 108 const std::string& ppd_contents, | 108 const std::string& ppd_contents, |
| 109 const PrinterSetupCallback& cb) { | 109 const PrinterSetupCallback& cb) { |
| 110 auto* client = chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); | 110 auto* client = chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); |
| 111 | 111 |
| 112 client->CupsAddManuallyConfiguredPrinter( | 112 client->CupsAddManuallyConfiguredPrinter( |
| 113 printer.id(), printer.uri(), ppd_contents, | 113 printer.id(), printer.uri(), ppd_contents, |
| 114 base::Bind(&PrinterConfigurerImpl::OnAddedPrinter, | 114 base::Bind(&PrinterConfigurerImpl::OnAddedPrinter, |
| 115 weak_factory_.GetWeakPtr(), printer, cb), | 115 weak_factory_.GetWeakPtr(), printer, cb), |
| 116 base::Bind(&PrinterConfigurerImpl::OnDbusError, | 116 base::Bind(&PrinterConfigurerImpl::OnDbusError, |
| 117 weak_factory_.GetWeakPtr(), cb)); | 117 weak_factory_.GetWeakPtr(), cb)); |
| 118 } | 118 } |
| 119 | 119 |
| 120 void ResolvePpdDone(const Printer& printer, | 120 void ResolvePpdDone(const Printer& printer, |
| 121 const PrinterSetupCallback& cb, | 121 const PrinterSetupCallback& cb, |
| 122 printing::PpdProvider::CallbackResultCode result, | 122 printing::PpdProvider::CallbackResultCode result, |
| 123 const std::string& ppd_contents, | 123 const std::string& ppd_contents, |
| 124 const std::vector<std::string>& ppd_filters) { | 124 const std::vector<std::string>& ppd_filters) { |
| 125 // TODO(justincarlson) - Use ppd_filters to invoke cups components downloads | 125 // TODO(justincarlson) - Use ppd_filters to invoke cups components downloads |
| 126 // if needed. | 126 // if needed. |
| 127 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 127 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 128 switch (result) { | 128 switch (result) { |
| 129 case chromeos::printing::PpdProvider::SUCCESS: | 129 case chromeos::printing::PpdProvider::SUCCESS: |
| 130 DCHECK(!ppd_contents.empty()); | 130 DCHECK(!ppd_contents.empty()); |
| 131 AddPrinter(printer, ppd_contents, cb); | 131 AddPrinter(printer, ppd_contents, cb); |
| 132 break; | 132 break; |
| 133 case printing::PpdProvider::CallbackResultCode::NOT_FOUND: | 133 case printing::PpdProvider::CallbackResultCode::NOT_FOUND: |
| 134 cb.Run(PPD_NOT_FOUND); | 134 cb.Run(PrinterSetupResult::kPpdNotFound); |
| 135 break; | 135 break; |
| 136 case printing::PpdProvider::CallbackResultCode::SERVER_ERROR: | 136 case printing::PpdProvider::CallbackResultCode::SERVER_ERROR: |
| 137 cb.Run(PPD_UNRETRIEVABLE); | 137 cb.Run(PrinterSetupResult::kPpdUnretrievable); |
| 138 break; | 138 break; |
| 139 case printing::PpdProvider::CallbackResultCode::INTERNAL_ERROR: | 139 case printing::PpdProvider::CallbackResultCode::INTERNAL_ERROR: |
| 140 // TODO(skau): Add PPD_TOO_LARGE when it's reported by the PpdProvider. | 140 // TODO(skau): Add kPpdTooLarge when it's reported by the PpdProvider. |
| 141 cb.Run(FATAL_ERROR); | 141 cb.Run(PrinterSetupResult::kFatalError); |
| 142 break; | 142 break; |
| 143 } | 143 } |
| 144 } | 144 } |
| 145 | 145 |
| 146 scoped_refptr<printing::PpdProvider> ppd_provider_; | 146 scoped_refptr<printing::PpdProvider> ppd_provider_; |
| 147 base::WeakPtrFactory<PrinterConfigurerImpl> weak_factory_; | 147 base::WeakPtrFactory<PrinterConfigurerImpl> weak_factory_; |
| 148 }; | 148 }; |
| 149 | 149 |
| 150 } // namespace | 150 } // namespace |
| 151 | 151 |
| 152 // static | 152 // static |
| 153 std::unique_ptr<PrinterConfigurer> PrinterConfigurer::Create(Profile* profile) { | 153 std::unique_ptr<PrinterConfigurer> PrinterConfigurer::Create(Profile* profile) { |
| 154 return base::MakeUnique<PrinterConfigurerImpl>(profile); | 154 return base::MakeUnique<PrinterConfigurerImpl>(profile); |
| 155 } | 155 } |
| 156 | 156 |
| 157 } // namespace chromeos | 157 } // namespace chromeos |
| OLD | NEW |