| 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/print_preview/printer_backend_proxy.h" | 5 #include "chrome/browser/ui/webui/print_preview/printer_backend_proxy.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 return; | 124 return; |
| 125 } | 125 } |
| 126 | 126 |
| 127 // Log printer configuration for selected printer. | 127 // Log printer configuration for selected printer. |
| 128 UMA_HISTOGRAM_ENUMERATION("Printing.CUPS.ProtocolUsed", | 128 UMA_HISTOGRAM_ENUMERATION("Printing.CUPS.ProtocolUsed", |
| 129 printer->GetProtocol(), | 129 printer->GetProtocol(), |
| 130 chromeos::Printer::kProtocolMax); | 130 chromeos::Printer::kProtocolMax); |
| 131 | 131 |
| 132 if (prefs_->IsConfigurationCurrent(*printer)) { | 132 if (prefs_->IsConfigurationCurrent(*printer)) { |
| 133 // Skip setup if the printer is already installed. | 133 // Skip setup if the printer is already installed. |
| 134 HandlePrinterSetup(std::move(printer), cb, chromeos::SUCCESS); | 134 HandlePrinterSetup(std::move(printer), cb, chromeos::kSuccess); |
| 135 return; | 135 return; |
| 136 } | 136 } |
| 137 | 137 |
| 138 const chromeos::Printer& printer_ref = *printer; | 138 const chromeos::Printer& printer_ref = *printer; |
| 139 printer_configurer_->SetUpPrinter( | 139 printer_configurer_->SetUpPrinter( |
| 140 printer_ref, | 140 printer_ref, |
| 141 base::Bind(&PrinterBackendProxyChromeos::HandlePrinterSetup, | 141 base::Bind(&PrinterBackendProxyChromeos::HandlePrinterSetup, |
| 142 weak_factory_.GetWeakPtr(), base::Passed(&printer), cb)); | 142 weak_factory_.GetWeakPtr(), base::Passed(&printer), cb)); |
| 143 }; | 143 }; |
| 144 | 144 |
| 145 private: | 145 private: |
| 146 void HandlePrinterSetup(std::unique_ptr<chromeos::Printer> printer, | 146 void HandlePrinterSetup(std::unique_ptr<chromeos::Printer> printer, |
| 147 const PrinterSetupCallback& cb, | 147 const PrinterSetupCallback& cb, |
| 148 chromeos::PrinterSetupResult result) { | 148 chromeos::PrinterSetupResult result) { |
| 149 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 149 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 150 | 150 |
| 151 switch (result) { | 151 switch (result) { |
| 152 case chromeos::PrinterSetupResult::SUCCESS: | 152 case chromeos::PrinterSetupResult::kSuccess: |
| 153 VLOG(1) << "Printer setup successful for " << printer->id() | 153 VLOG(1) << "Printer setup successful for " << printer->id() |
| 154 << " fetching properties"; | 154 << " fetching properties"; |
| 155 prefs_->PrinterInstalled(*printer); | 155 prefs_->PrinterInstalled(*printer); |
| 156 | 156 |
| 157 // fetch settings on the blocking pool and invoke callback. | 157 // fetch settings on the blocking pool and invoke callback. |
| 158 FetchCapabilities(std::move(printer), cb); | 158 FetchCapabilities(std::move(printer), cb); |
| 159 return; | 159 return; |
| 160 case chromeos::PrinterSetupResult::PPD_NOT_FOUND: | 160 case chromeos::PrinterSetupResult::kPpdNotFound: |
| 161 LOG(WARNING) << "Could not find PPD. Check printer configuration."; | 161 LOG(WARNING) << "Could not find PPD. Check printer configuration."; |
| 162 // Prompt user to update configuration. | 162 // Prompt user to update configuration. |
| 163 // TODO(skau): Fill me in | 163 // TODO(skau): Fill me in |
| 164 break; | 164 break; |
| 165 case chromeos::PrinterSetupResult::PPD_UNRETRIEVABLE: | 165 case chromeos::PrinterSetupResult::kPpdUnretrievable: |
| 166 LOG(WARNING) << "Could not download PPD. Check Internet connection."; | 166 LOG(WARNING) << "Could not download PPD. Check Internet connection."; |
| 167 // Could not download PPD. Connect to Internet. | 167 // Could not download PPD. Connect to Internet. |
| 168 // TODO(skau): Fill me in | 168 // TODO(skau): Fill me in |
| 169 break; | 169 break; |
| 170 case chromeos::PrinterSetupResult::PRINTER_UNREACHABLE: | 170 case chromeos::PrinterSetupResult::kPrinterUnreachable: |
| 171 case chromeos::PrinterSetupResult::DBUS_ERROR: | 171 case chromeos::PrinterSetupResult::kDbusError: |
| 172 case chromeos::PrinterSetupResult::PPD_TOO_LARGE: | 172 case chromeos::PrinterSetupResult::kPpdTooLarge: |
| 173 case chromeos::PrinterSetupResult::INVALID_PPD: | 173 case chromeos::PrinterSetupResult::kInvalidPpd: |
| 174 case chromeos::PrinterSetupResult::FATAL_ERROR: | 174 case chromeos::PrinterSetupResult::kFatalError: |
| 175 LOG(ERROR) << "Unexpected error in printer setup." << result; | 175 LOG(ERROR) << "Unexpected error in printer setup." << result; |
| 176 break; | 176 break; |
| 177 case chromeos::PrinterSetupResult::kMaxValue: |
| 178 NOTREACHED() << "This value is not expected"; |
| 179 break; |
| 177 } | 180 } |
| 178 | 181 |
| 179 // TODO(skau): Open printer settings if this is resolvable. | 182 // TODO(skau): Open printer settings if this is resolvable. |
| 180 cb.Run(nullptr); | 183 cb.Run(nullptr); |
| 181 } | 184 } |
| 182 | 185 |
| 183 chromeos::PrintersManager* prefs_; | 186 chromeos::PrintersManager* prefs_; |
| 184 scoped_refptr<chromeos::printing::PpdProvider> ppd_provider_; | 187 scoped_refptr<chromeos::printing::PpdProvider> ppd_provider_; |
| 185 std::unique_ptr<chromeos::PrinterConfigurer> printer_configurer_; | 188 std::unique_ptr<chromeos::PrinterConfigurer> printer_configurer_; |
| 186 base::WeakPtrFactory<PrinterBackendProxyChromeos> weak_factory_; | 189 base::WeakPtrFactory<PrinterBackendProxyChromeos> weak_factory_; |
| 187 | 190 |
| 188 DISALLOW_COPY_AND_ASSIGN(PrinterBackendProxyChromeos); | 191 DISALLOW_COPY_AND_ASSIGN(PrinterBackendProxyChromeos); |
| 189 }; | 192 }; |
| 190 | 193 |
| 191 } // namespace | 194 } // namespace |
| 192 | 195 |
| 193 std::unique_ptr<PrinterBackendProxy> PrinterBackendProxy::Create( | 196 std::unique_ptr<PrinterBackendProxy> PrinterBackendProxy::Create( |
| 194 Profile* profile) { | 197 Profile* profile) { |
| 195 return base::MakeUnique<PrinterBackendProxyChromeos>(profile); | 198 return base::MakeUnique<PrinterBackendProxyChromeos>(profile); |
| 196 } | 199 } |
| 197 | 200 |
| 198 } // namespace printing | 201 } // namespace printing |
| OLD | NEW |