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

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
« no previous file with comments | « chrome/service/cloud_print/printer_job_handler.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
225 << ", printer name: " << printer_name;
223 return false; 226 return false;
224 } 227 }
225 228
226 std::string content; 229 std::string content;
227 bool res = file_util::ReadFileToString(ppd_path, &content); 230 bool res = file_util::ReadFileToString(ppd_path, &content);
228 231
229 file_util::Delete(ppd_path, false); 232 file_util::Delete(ppd_path, false);
230 233
231 if (res) { 234 if (res) {
232 printer_info->printer_capabilities.swap(content); 235 printer_info->printer_capabilities.swap(content);
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 // http->data_remaining or http->_data_remaining, unfortunately http_t 340 // http->data_remaining or http->_data_remaining, unfortunately http_t
338 // is an internal structure and fields are not exposed in CUPS headers. 341 // is an internal structure and fields are not exposed in CUPS headers.
339 // httpGetLength or httpGetLength2 returning the full content size. 342 // httpGetLength or httpGetLength2 returning the full content size.
340 // Comparing file size against that content length might be unreliable 343 // Comparing file size against that content length might be unreliable
341 // since some http reponses are encoded and content_length > file size. 344 // since some http reponses are encoded and content_length > file size.
342 // Let's just check for the obvious CUPS and http errors here. 345 // Let's just check for the obvious CUPS and http errors here.
343 ppd_path = FilePath(ppd_file_path); 346 ppd_path = FilePath(ppd_file_path);
344 ipp_status_t error_code = cupsLastError(); 347 ipp_status_t error_code = cupsLastError();
345 int http_error = httpError(http.http()); 348 int http_error = httpError(http.http());
346 if (error_code > IPP_OK_EVENTS_COMPLETE || http_error != 0) { 349 if (error_code > IPP_OK_EVENTS_COMPLETE || http_error != 0) {
347 LOG(ERROR) << "Error downloading PPD file for: " << name 350 LOG(ERROR) << "Error downloading PPD file"
351 << ", name: " << name
348 << ", CUPS error: " << static_cast<int>(error_code) 352 << ", CUPS error: " << static_cast<int>(error_code)
349 << ", HTTP error: " << http_error; 353 << ", HTTP error: " << http_error;
350 file_util::Delete(ppd_path, false); 354 file_util::Delete(ppd_path, false);
351 ppd_path.clear(); 355 ppd_path.clear();
352 } 356 }
353 } 357 }
354 } 358 }
355 return ppd_path; 359 return ppd_path;
356 } 360 }
357 361
358 } // namespace printing 362 } // namespace printing
OLDNEW
« no previous file with comments | « chrome/service/cloud_print/printer_job_handler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698