| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   89  |   89  | 
|   90   VLOG(1) << "Printer setup successful for " << printer->id() |   90   VLOG(1) << "Printer setup successful for " << printer->id() | 
|   91           << " fetching properties"; |   91           << " fetching properties"; | 
|   92  |   92  | 
|   93   // fetch settings on the blocking pool and invoke callback. |   93   // fetch settings on the blocking pool and invoke callback. | 
|   94   FetchCapabilities(std::move(printer), cb); |   94   FetchCapabilities(std::move(printer), cb); | 
|   95 } |   95 } | 
|   96  |   96  | 
|   97 void OnPrinterAddResult(std::unique_ptr<chromeos::Printer> printer, |   97 void OnPrinterAddResult(std::unique_ptr<chromeos::Printer> printer, | 
|   98                         const PrinterSetupCallback& cb, |   98                         const PrinterSetupCallback& cb, | 
|   99                         bool success) { |   99                         int32_t result_code) { | 
|  100   // It's expected that debug daemon posts callbacks on the UI thread. |  100   // It's expected that debug daemon posts callbacks on the UI thread. | 
|  101   DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |  101   DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 
|  102  |  102  | 
|  103   HandlePrinterSetup(std::move(printer), success ? SUCCESS : FAILURE, cb); |  103   HandlePrinterSetup(std::move(printer), (result_code == 0) ? SUCCESS : FAILURE, | 
 |  104                      cb); | 
|  104 } |  105 } | 
|  105  |  106  | 
|  106 void OnPrinterAddError(const PrinterSetupCallback& cb) { |  107 void OnPrinterAddError(const PrinterSetupCallback& cb) { | 
|  107   // It's expected that debug daemon posts callbacks on the UI thread. |  108   // It's expected that debug daemon posts callbacks on the UI thread. | 
|  108   DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |  109   DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 
|  109  |  110  | 
|  110   LOG(WARNING) << "Could not contact debugd"; |  111   LOG(WARNING) << "Could not contact debugd"; | 
|  111   PostCallbackError(cb); |  112   PostCallbackError(cb); | 
|  112 } |  113 } | 
|  113  |  114  | 
|  114 void AddPrinter(std::unique_ptr<chromeos::Printer> printer, |  115 void AddPrinter(std::unique_ptr<chromeos::Printer> printer, | 
|  115                 const std::string& ppd_path, |  116                 const std::string& ppd_contents, | 
|  116                 bool ipp_everywhere, |  | 
|  117                 const PrinterSetupCallback& cb) { |  117                 const PrinterSetupCallback& cb) { | 
|  118   // Always push configuration to CUPS.  It may need an update. |  118   // Always push configuration to CUPS.  It may need an update. | 
|  119   const std::string printer_name = printer->id(); |  119   const std::string printer_name = printer->id(); | 
|  120   const std::string printer_uri = printer->uri(); |  120   const std::string printer_uri = printer->uri(); | 
|  121  |  121  | 
|  122   chromeos::DBusThreadManager::Get()->GetDebugDaemonClient()->CupsAddPrinter( |  122   if (!ppd_contents.empty()) { | 
|  123       printer_name, printer_uri, ppd_path, ipp_everywhere, |  123     chromeos::DBusThreadManager::Get() | 
|  124       base::Bind(&OnPrinterAddResult, base::Passed(&printer), cb), |  124         ->GetDebugDaemonClient() | 
|  125       base::Bind(&OnPrinterAddError, cb)); |  125         ->CupsAddManuallyConfiguredPrinter( | 
 |  126             printer_name, printer_uri, ppd_contents, | 
 |  127             base::Bind(&OnPrinterAddResult, base::Passed(&printer), cb), | 
 |  128             base::Bind(&OnPrinterAddError, cb)); | 
 |  129   } else { | 
 |  130     // If we weren't given a ppd to use, we'd better be auto-configurable. | 
 |  131     DCHECK(printer->IsIppEverywhere()); | 
 |  132     chromeos::DBusThreadManager::Get() | 
 |  133         ->GetDebugDaemonClient() | 
 |  134         ->CupsAddAutoConfiguredPrinter( | 
 |  135             printer_name, printer_uri, | 
 |  136             base::Bind(&OnPrinterAddResult, base::Passed(&printer), cb), | 
 |  137             base::Bind(&OnPrinterAddError, cb)); | 
 |  138   } | 
|  126 } |  139 } | 
|  127  |  140  | 
|  128 void PPDResolve(std::unique_ptr<chromeos::Printer> printer, |  141 void PPDResolve(std::unique_ptr<chromeos::Printer> printer, | 
|  129                 const PrinterSetupCallback& cb, |  142                 const PrinterSetupCallback& cb, | 
|  130                 chromeos::printing::PpdProvider::CallbackResultCode result, |  143                 chromeos::printing::PpdProvider::CallbackResultCode result, | 
|  131                 base::FilePath path) { |  144                 const std::string& ppd_contents) { | 
|  132   switch (result) { |  145   switch (result) { | 
|  133     case chromeos::printing::PpdProvider::SUCCESS: { |  146     case chromeos::printing::PpdProvider::SUCCESS: { | 
|  134       DCHECK(!path.empty()); |  147       DCHECK(!ppd_contents.empty()); | 
|  135       AddPrinter(std::move(printer), path.value() /* ppd path */, |  148       AddPrinter(std::move(printer), ppd_contents, cb); | 
|  136                  false /* non-ipp-everywhere */, cb); |  | 
|  137       break; |  149       break; | 
|  138     } |  150     } | 
|  139     case chromeos::printing::PpdProvider::NOT_FOUND: |  151     case chromeos::printing::PpdProvider::NOT_FOUND: | 
|  140       HandlePrinterSetup(std::move(printer), PPD_NOT_FOUND, cb); |  152       HandlePrinterSetup(std::move(printer), PPD_NOT_FOUND, cb); | 
|  141       break; |  153       break; | 
|  142     default: |  154     default: | 
|  143       HandlePrinterSetup(std::move(printer), FAILURE, cb); |  155       HandlePrinterSetup(std::move(printer), FAILURE, cb); | 
|  144       break; |  156       break; | 
|  145   } |  157   } | 
|  146 } |  158 } | 
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  193         prefs_->GetPrinter(printer_name); |  205         prefs_->GetPrinter(printer_name); | 
|  194     if (!printer) { |  206     if (!printer) { | 
|  195       // If the printer was removed, the lookup will fail. |  207       // If the printer was removed, the lookup will fail. | 
|  196       content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |  208       content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | 
|  197                                        base::Bind(cb, nullptr)); |  209                                        base::Bind(cb, nullptr)); | 
|  198       return; |  210       return; | 
|  199     } |  211     } | 
|  200  |  212  | 
|  201     if (printer->IsIppEverywhere()) { |  213     if (printer->IsIppEverywhere()) { | 
|  202       // ChromeOS registers printer by GUID rather than display name. |  214       // ChromeOS registers printer by GUID rather than display name. | 
|  203       AddPrinter(std::move(printer), "" /* empty ppd path */, |  215       AddPrinter(std::move(printer), "", cb); | 
|  204                  true /* ipp everywhere */, cb); |  216     } else { | 
|  205       return; |  217       // Ref taken because printer is moved. | 
 |  218       const chromeos::Printer::PpdReference& ppd_ref = printer->ppd_reference(); | 
 |  219       ppd_provider_->ResolvePpd( | 
 |  220           ppd_ref, base::Bind(&PPDResolve, base::Passed(&printer), cb)); | 
|  206     } |  221     } | 
|  207  |  | 
|  208     // Ref taken because printer is moved. |  | 
|  209     const chromeos::Printer::PpdReference& ppd_ref = printer->ppd_reference(); |  | 
|  210     ppd_provider_->Resolve(ppd_ref, |  | 
|  211                            base::Bind(&PPDResolve, base::Passed(&printer), cb)); |  | 
|  212   }; |  222   }; | 
|  213  |  223  | 
|  214  private: |  224  private: | 
|  215   chromeos::PrinterPrefManager* prefs_; |  225   chromeos::PrinterPrefManager* prefs_; | 
|  216   std::unique_ptr<chromeos::printing::PpdProvider> ppd_provider_; |  226   scoped_refptr<chromeos::printing::PpdProvider> ppd_provider_; | 
|  217  |  227  | 
|  218   DISALLOW_COPY_AND_ASSIGN(PrinterBackendProxyChromeos); |  228   DISALLOW_COPY_AND_ASSIGN(PrinterBackendProxyChromeos); | 
|  219 }; |  229 }; | 
|  220  |  230  | 
|  221 }  // namespace |  231 }  // namespace | 
|  222  |  232  | 
|  223 std::unique_ptr<PrinterBackendProxy> PrinterBackendProxy::Create( |  233 std::unique_ptr<PrinterBackendProxy> PrinterBackendProxy::Create( | 
|  224     Profile* profile) { |  234     Profile* profile) { | 
|  225   return base::MakeUnique<PrinterBackendProxyChromeos>(profile); |  235   return base::MakeUnique<PrinterBackendProxyChromeos>(profile); | 
|  226 } |  236 } | 
|  227  |  237  | 
|  228 }  // namespace printing |  238 }  // namespace printing | 
| OLD | NEW |