Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1195)

Side by Side Diff: printing/backend/print_backend_cups.cc

Issue 10808086: Standardize log message style for cloudprint service and display printer id (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "printing/backend/print_backend.h" 5 #include "printing/backend/print_backend.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #include <dlfcn.h> 9 #include <dlfcn.h>
10 #include <errno.h> 10 #include <errno.h>
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 blocking_(blocking) { 139 blocking_(blocking) {
140 } 140 }
141 141
142 bool PrintBackendCUPS::EnumeratePrinters(PrinterList* printer_list) { 142 bool PrintBackendCUPS::EnumeratePrinters(PrinterList* printer_list) {
143 DCHECK(printer_list); 143 DCHECK(printer_list);
144 printer_list->clear(); 144 printer_list->clear();
145 145
146 cups_dest_t* destinations = NULL; 146 cups_dest_t* destinations = NULL;
147 int num_dests = GetDests(&destinations); 147 int num_dests = GetDests(&destinations);
148 if ((num_dests == 0) && (cupsLastError() > IPP_OK_EVENTS_COMPLETE)) { 148 if ((num_dests == 0) && (cupsLastError() > IPP_OK_EVENTS_COMPLETE)) {
149 VLOG(1) << "CP_CUPS: Error getting printers from CUPS server. Server: " 149 VLOG(1) << "CUPS: Error getting printers from CUPS server"
150 << print_server_url_ 150 << ", server: " << print_server_url_
151 << " Error: " 151 << ", error: " << static_cast<int>(cupsLastError());
152 << static_cast<int>(cupsLastError());
153 return false; 152 return false;
154 } 153 }
155 154
156 for (int printer_index = 0; printer_index < num_dests; printer_index++) { 155 for (int printer_index = 0; printer_index < num_dests; printer_index++) {
157 const cups_dest_t& printer = destinations[printer_index]; 156 const cups_dest_t& printer = destinations[printer_index];
158 157
159 // CUPS can have 'printers' that are actually scanners. (not MFC) 158 // CUPS can have 'printers' that are actually scanners. (not MFC)
160 // At least on Mac. Check for scanners and skip them. 159 // At least on Mac. Check for scanners and skip them.
161 const char* type_str = cupsGetOption(kCUPSPrinterTypeOpt, 160 const char* type_str = cupsGetOption(kCUPSPrinterTypeOpt,
162 printer.num_options, printer.options); 161 printer.num_options, printer.options);
(...skipping 27 matching lines...) Expand all
190 for (int opt_index = 0; opt_index < printer.num_options; opt_index++) { 189 for (int opt_index = 0; opt_index < printer.num_options; opt_index++) {
191 printer_info.options[printer.options[opt_index].name] = 190 printer_info.options[printer.options[opt_index].name] =
192 printer.options[opt_index].value; 191 printer.options[opt_index].value;
193 } 192 }
194 193
195 printer_list->push_back(printer_info); 194 printer_list->push_back(printer_info);
196 } 195 }
197 196
198 cupsFreeDests(num_dests, destinations); 197 cupsFreeDests(num_dests, destinations);
199 198
200 VLOG(1) << "CUPS: Enumerated " << printer_list->size() << " printers."; 199 VLOG(1) << "CUPS: Enumerated printers"
200 << ", server: " << print_server_url_
201 << ", # of printers: " << printer_list->size();
201 return true; 202 return true;
202 } 203 }
203 204
204 std::string PrintBackendCUPS::GetDefaultPrinterName() { 205 std::string PrintBackendCUPS::GetDefaultPrinterName() {
205 // Not using cupsGetDefault() because it lies about the default printer. 206 // Not using cupsGetDefault() because it lies about the default printer.
206 cups_dest_t* dests; 207 cups_dest_t* dests;
207 int num_dests = GetDests(&dests); 208 int num_dests = GetDests(&dests);
208 cups_dest_t* dest = cupsGetDest(NULL, NULL, num_dests, dests); 209 cups_dest_t* dest = cupsGetDest(NULL, NULL, num_dests, dests);
209 return dest ? std::string(dest->name) : std::string(); 210 return dest ? std::string(dest->name) : std::string();
210 } 211 }
211 212
212 bool PrintBackendCUPS::GetPrinterCapsAndDefaults( 213 bool PrintBackendCUPS::GetPrinterCapsAndDefaults(
213 const std::string& printer_name, 214 const std::string& printer_name,
214 PrinterCapsAndDefaults* printer_info) { 215 PrinterCapsAndDefaults* printer_info) {
215 DCHECK(printer_info); 216 DCHECK(printer_info);
216 217
217 VLOG(1) << "CUPS: Getting Caps and Defaults for: " << printer_name; 218 VLOG(1) << "CUPS: Getting caps and defaults"
219 << ", printer name: " << printer_name;
218 220
219 FilePath ppd_path(GetPPD(printer_name.c_str())); 221 FilePath ppd_path(GetPPD(printer_name.c_str()));
220 // In some cases CUPS failed to get ppd file. 222 // In some cases CUPS failed to get ppd file.
221 if (ppd_path.empty()) { 223 if (ppd_path.empty()) {
222 LOG(ERROR) << "CUPS: Failed to get PPD for: " << printer_name; 224 LOG(ERROR) << "CUPS: Failed to get PPD, printer name: " << printer_name;
223 return false; 225 return false;
224 } 226 }
225 227
226 std::string content; 228 std::string content;
227 bool res = file_util::ReadFileToString(ppd_path, &content); 229 bool res = file_util::ReadFileToString(ppd_path, &content);
228 230
229 file_util::Delete(ppd_path, false); 231 file_util::Delete(ppd_path, false);
230 232
231 if (res) { 233 if (res) {
232 printer_info->printer_capabilities.swap(content); 234 printer_info->printer_capabilities.swap(content);
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 << ", HTTP error: " << http_error; 351 << ", HTTP error: " << http_error;
350 file_util::Delete(ppd_path, false); 352 file_util::Delete(ppd_path, false);
351 ppd_path.clear(); 353 ppd_path.clear();
352 } 354 }
353 } 355 }
354 } 356 }
355 return ppd_path; 357 return ppd_path;
356 } 358 }
357 359
358 } // namespace printing 360 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698