| 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_capabilities.h" | 5 #include "chrome/browser/ui/webui/print_preview/printer_capabilities.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/strings/string_piece.h" | 13 #include "base/strings/string_piece.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/common/cloud_print/cloud_print_cdd_conversion.h" | 15 #include "chrome/common/cloud_print/cloud_print_cdd_conversion.h" |
| 16 #include "chrome/common/crash_keys.h" | 16 #include "chrome/common/crash_keys.h" |
| 17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 18 #include "printing/backend/print_backend.h" | 18 #include "printing/backend/print_backend.h" |
| 19 #include "printing/backend/print_backend_consts.h" | 19 #include "printing/backend/print_backend_consts.h" |
| 20 | 20 |
| 21 namespace printing { | 21 namespace printing { |
| 22 | 22 |
| 23 const char kPrinterId[] = "printerId"; | 23 const char kPrinterId[] = "printerId"; |
| 24 const char kPrinterCapabilities[] = "capabilities"; | 24 const char kPrinterCapabilities[] = "capabilities"; |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 // Returns a Dictionary representing printer capabilities as CDD. | 28 // Returns a dictionary representing printer capabilities as CDD. Returns |
| 29 // nullptr if a dictionary could not be generated. |
| 29 std::unique_ptr<base::DictionaryValue> | 30 std::unique_ptr<base::DictionaryValue> |
| 30 GetPrinterCapabilitiesOnBlockingPoolThread(const std::string& device_name) { | 31 GetPrinterCapabilitiesOnBlockingPoolThread(const std::string& device_name) { |
| 31 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | 32 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
| 32 DCHECK(!device_name.empty()); | 33 DCHECK(!device_name.empty()); |
| 33 | 34 |
| 34 scoped_refptr<PrintBackend> print_backend( | 35 scoped_refptr<PrintBackend> print_backend( |
| 35 PrintBackend::CreateInstance(nullptr)); | 36 PrintBackend::CreateInstance(nullptr)); |
| 36 | 37 |
| 37 VLOG(1) << "Get printer capabilities start for " << device_name; | 38 VLOG(1) << "Get printer capabilities start for " << device_name; |
| 38 crash_keys::ScopedPrinterInfo crash_key( | 39 crash_keys::ScopedPrinterInfo crash_key( |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 const auto printer_name_description = | 88 const auto printer_name_description = |
| 88 GetPrinterNameAndDescription(basic_info); | 89 GetPrinterNameAndDescription(basic_info); |
| 89 const std::string& printer_name = printer_name_description.first; | 90 const std::string& printer_name = printer_name_description.first; |
| 90 const std::string& printer_description = printer_name_description.second; | 91 const std::string& printer_description = printer_name_description.second; |
| 91 | 92 |
| 92 auto printer_info = base::MakeUnique<base::DictionaryValue>(); | 93 auto printer_info = base::MakeUnique<base::DictionaryValue>(); |
| 93 printer_info->SetString(kPrinterId, device_name); | 94 printer_info->SetString(kPrinterId, device_name); |
| 94 printer_info->SetString(kSettingPrinterName, printer_name); | 95 printer_info->SetString(kSettingPrinterName, printer_name); |
| 95 printer_info->SetString(kSettingPrinterDescription, printer_description); | 96 printer_info->SetString(kSettingPrinterDescription, printer_description); |
| 96 | 97 |
| 97 printer_info->Set(kPrinterCapabilities, | 98 std::unique_ptr<base::DictionaryValue> capabilities = |
| 98 GetPrinterCapabilitiesOnBlockingPoolThread(device_name)); | 99 GetPrinterCapabilitiesOnBlockingPoolThread(device_name); |
| 100 if (capabilities) |
| 101 printer_info->Set(kPrinterCapabilities, std::move(capabilities)); |
| 102 |
| 99 return printer_info; | 103 return printer_info; |
| 100 } | 104 } |
| 101 | 105 |
| 102 } // namespace printing | 106 } // namespace printing |
| OLD | NEW |