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

Side by Side Diff: chrome/browser/printing/print_system_task_proxy.cc

Issue 10867004: Notify print preview UI if getting capabilityes failed. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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 "chrome/browser/printing/print_system_task_proxy.h" 5 #include "chrome/browser/printing/print_system_task_proxy.h"
6 6
7 #include <ctype.h> 7 #include <ctype.h>
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 print_backend_(print_backend), 312 print_backend_(print_backend),
313 has_logged_printers_count_(has_logged_printers_count) { 313 has_logged_printers_count_(has_logged_printers_count) {
314 } 314 }
315 315
316 PrintSystemTaskProxy::~PrintSystemTaskProxy() { 316 PrintSystemTaskProxy::~PrintSystemTaskProxy() {
317 } 317 }
318 318
319 void PrintSystemTaskProxy::GetDefaultPrinter() { 319 void PrintSystemTaskProxy::GetDefaultPrinter() {
320 VLOG(1) << "Get default printer start"; 320 VLOG(1) << "Get default printer start";
321 321
322 std::string* default_printer = NULL;
323 default_printer = new std::string(print_backend_->GetDefaultPrinterName());
324
325 VLOG(1) << "Get default printer finished, found: " 322 VLOG(1) << "Get default printer finished, found: "
326 << *default_printer; 323 << print_backend_->GetDefaultPrinterName();
327
328 std::string* cloud_print_data = new std::string;
329 324
330 BrowserThread::PostTask( 325 BrowserThread::PostTask(
331 BrowserThread::UI, FROM_HERE, 326 BrowserThread::UI, FROM_HERE,
332 base::Bind(&PrintSystemTaskProxy::SendDefaultPrinter, this, 327 base::Bind(&PrintSystemTaskProxy::SendDefaultPrinter, this,
333 default_printer, cloud_print_data)); 328 print_backend_->GetDefaultPrinterName(),
329 std::string()));
334 } 330 }
335 331
336 void PrintSystemTaskProxy::SendDefaultPrinter( 332 void PrintSystemTaskProxy::SendDefaultPrinter(
337 const std::string* default_printer, const std::string* cloud_print_data) { 333 const std::string& default_printer,
334 const std::string& cloud_print_data) {
338 if (handler_) 335 if (handler_)
339 handler_->SendInitialSettings(*default_printer, *cloud_print_data); 336 handler_->SendInitialSettings(default_printer, cloud_print_data);
340 delete default_printer;
341 } 337 }
342 338
343 void PrintSystemTaskProxy::EnumeratePrinters() { 339 void PrintSystemTaskProxy::EnumeratePrinters() {
344 VLOG(1) << "Enumerate printers start"; 340 VLOG(1) << "Enumerate printers start";
345 ListValue* printers = new ListValue; 341 ListValue* printers = new ListValue;
346 printing::PrinterList printer_list; 342 printing::PrinterList printer_list;
347 print_backend_->EnumeratePrinters(&printer_list); 343 print_backend_->EnumeratePrinters(&printer_list);
348 344
349 if (!has_logged_printers_count_) { 345 if (!has_logged_printers_count_) {
350 // Record the total number of printers. 346 // Record the total number of printers.
(...skipping 25 matching lines...) Expand all
376 base::Bind(&PrintSystemTaskProxy::SetupPrinterList, this, printers)); 372 base::Bind(&PrintSystemTaskProxy::SetupPrinterList, this, printers));
377 } 373 }
378 374
379 void PrintSystemTaskProxy::SetupPrinterList(ListValue* printers) { 375 void PrintSystemTaskProxy::SetupPrinterList(ListValue* printers) {
380 if (handler_) 376 if (handler_)
381 handler_->SetupPrinterList(*printers); 377 handler_->SetupPrinterList(*printers);
382 delete printers; 378 delete printers;
383 } 379 }
384 380
385 #if defined(USE_CUPS) 381 #if defined(USE_CUPS)
386 // static 382 bool PrintSystemTaskProxy::ParsePrinterCapabilities(
Albert Bodenhamer 2012/08/22 01:02:23 Prototype is the same on all platforms. Move the
Vitaly Buka (NO REVIEWS) 2012/08/22 02:58:02 Done.
387 bool PrintSystemTaskProxy::GetPrinterCapabilitiesCUPS(
388 const printing::PrinterCapsAndDefaults& printer_info, 383 const printing::PrinterCapsAndDefaults& printer_info,
389 const std::string& printer_name, 384 const std::string& printer_name,
390 bool* set_color_as_default, 385 bool* set_color_as_default,
391 int* printer_color_space_for_color, 386 int* printer_color_space_for_color,
392 int* printer_color_space_for_black, 387 int* printer_color_space_for_black,
393 bool* set_duplex_as_default, 388 bool* set_duplex_as_default,
394 int* default_duplex_setting_value) { 389 int* default_duplex_setting_value) {
395 FilePath ppd_file_path; 390 FilePath ppd_file_path;
396 if (!file_util::CreateTemporaryFile(&ppd_file_path)) 391 if (!file_util::CreateTemporaryFile(&ppd_file_path))
397 return false; 392 return false;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 getProcessColorModelSettings( 442 getProcessColorModelSettings(
448 ppd, printer_color_space_for_black, 443 ppd, printer_color_space_for_black,
449 printer_color_space_for_color, set_color_as_default))) { 444 printer_color_space_for_color, set_color_as_default))) {
450 VLOG(1) << "Unknown printer color model"; 445 VLOG(1) << "Unknown printer color model";
451 } 446 }
452 ppdClose(ppd); 447 ppdClose(ppd);
453 } 448 }
454 file_util::Delete(ppd_file_path, false); 449 file_util::Delete(ppd_file_path, false);
455 return true; 450 return true;
456 } 451 }
457 #endif // defined(USE_CUPS)
458 452
459 #if defined(OS_WIN) 453 #elif defined(OS_WIN)
460 void PrintSystemTaskProxy::GetPrinterCapabilitiesWin( 454
455 bool PrintSystemTaskProxy::ParsePrinterCapabilities(
461 const printing::PrinterCapsAndDefaults& printer_info, 456 const printing::PrinterCapsAndDefaults& printer_info,
457 const std::string& printer_name,
462 bool* set_color_as_default, 458 bool* set_color_as_default,
463 int* printer_color_space_for_color, 459 int* printer_color_space_for_color,
464 int* printer_color_space_for_black, 460 int* printer_color_space_for_black,
465 bool* set_duplex_as_default, 461 bool* set_duplex_as_default,
466 int* default_duplex_setting_value) { 462 int* default_duplex_setting_value) {
467 // According to XPS 1.0 spec, only color printers have psk:Color. 463 // According to XPS 1.0 spec, only color printers have psk:Color.
468 // Therefore we don't need to parse the whole XML file, we just need to 464 // Therefore we don't need to parse the whole XML file, we just need to
469 // search the string. The spec can be found at: 465 // search the string. The spec can be found at:
470 // http://msdn.microsoft.com/en-us/windows/hardware/gg463431. 466 // http://msdn.microsoft.com/en-us/windows/hardware/gg463431.
471 if (printer_info.printer_capabilities.find(kPskColor) != std::string::npos) 467 if (printer_info.printer_capabilities.find(kPskColor) != std::string::npos)
(...skipping 16 matching lines...) Expand all
488 484
489 if (printer_info.printer_defaults.find(kPskDuplexFeature) != 485 if (printer_info.printer_defaults.find(kPskDuplexFeature) !=
490 std::string::npos) { 486 std::string::npos) {
491 if (printer_info.printer_defaults.find(kPskTwoSided) != 487 if (printer_info.printer_defaults.find(kPskTwoSided) !=
492 std::string::npos) { 488 std::string::npos) {
493 *default_duplex_setting_value = printing::LONG_EDGE; 489 *default_duplex_setting_value = printing::LONG_EDGE;
494 } else { 490 } else {
495 *default_duplex_setting_value = printing::SIMPLEX; 491 *default_duplex_setting_value = printing::SIMPLEX;
496 } 492 }
497 } 493 }
494 return true;
495 }
496
497 #else
498
499 bool PrintSystemTaskProxy::ParsePrinterCapabilities(
500 const printing::PrinterCapsAndDefaults& printer_info,
501 const std::string& printer_name,
502 bool* set_color_as_default,
503 int* printer_color_space_for_color,
504 int* printer_color_space_for_black,
505 bool* set_duplex_as_default,
506 int* default_duplex_setting_value) {
507 NOTIMPLEMENTED();
508 return false;
498 } 509 }
499 #endif // defined(OS_WIN) 510 #endif // defined(OS_WIN)
500 511
501 void PrintSystemTaskProxy::GetPrinterCapabilities( 512 void PrintSystemTaskProxy::GetPrinterCapabilities(
502 const std::string& printer_name) { 513 const std::string& printer_name) {
503 VLOG(1) << "Get printer capabilities start for " << printer_name; 514 VLOG(1) << "Get printer capabilities start for " << printer_name;
504 child_process_logging::ScopedPrinterInfoSetter prn_info( 515 child_process_logging::ScopedPrinterInfoSetter prn_info(
505 print_backend_->GetPrinterDriverInfo(printer_name)); 516 print_backend_->GetPrinterDriverInfo(printer_name));
506 517
507 bool set_color_as_default = false; 518 bool set_color_as_default = false;
508 bool set_duplex_as_default = false; 519 bool set_duplex_as_default = false;
509 int printer_color_space_for_color = printing::UNKNOWN_COLOR_MODEL; 520 int printer_color_space_for_color = printing::UNKNOWN_COLOR_MODEL;
510 int printer_color_space_for_black = printing::UNKNOWN_COLOR_MODEL; 521 int printer_color_space_for_black = printing::UNKNOWN_COLOR_MODEL;
511 int default_duplex_setting_value = printing::UNKNOWN_DUPLEX_MODE; 522 int default_duplex_setting_value = printing::UNKNOWN_DUPLEX_MODE;
512 523
513 printing::PrinterCapsAndDefaults printer_info; 524 printing::PrinterCapsAndDefaults printer_info;
514 if (print_backend_->GetPrinterCapsAndDefaults(printer_name, 525 if (!print_backend_->GetPrinterCapsAndDefaults(printer_name,
515 &printer_info)) { 526 &printer_info) ||
516 #if defined(USE_CUPS) 527 !ParsePrinterCapabilities(printer_info,
517 if (!GetPrinterCapabilitiesCUPS(printer_info, 528 printer_name,
518 printer_name, 529 &set_color_as_default,
519 &set_color_as_default, 530 &printer_color_space_for_color,
520 &printer_color_space_for_color, 531 &printer_color_space_for_black,
521 &printer_color_space_for_black, 532 &set_duplex_as_default,
522 &set_duplex_as_default, 533 &default_duplex_setting_value)) {
523 &default_duplex_setting_value)) { 534 BrowserThread::PostTask(
524 return; 535 BrowserThread::UI, FROM_HERE,
525 } 536 base::Bind(&PrintSystemTaskProxy::SendFailedToGetPrinterCapabilities,
526 #elif defined(OS_WIN) 537 this, printer_name));
527 GetPrinterCapabilitiesWin(printer_info, 538 return;
528 &set_color_as_default,
529 &printer_color_space_for_color,
530 &printer_color_space_for_black,
531 &set_duplex_as_default,
532 &default_duplex_setting_value);
533 #else
534 NOTIMPLEMENTED();
535 #endif
536 } 539 }
537 bool disable_color_options = (!printer_color_space_for_color || 540 bool disable_color_options = (!printer_color_space_for_color ||
538 !printer_color_space_for_black || 541 !printer_color_space_for_black ||
539 (printer_color_space_for_color == 542 (printer_color_space_for_color ==
540 printer_color_space_for_black)); 543 printer_color_space_for_black));
541 544
542 DictionaryValue settings_info; 545 DictionaryValue settings_info;
543 settings_info.SetString(kPrinterId, printer_name); 546 settings_info.SetString(kPrinterId, printer_name);
544 settings_info.SetBoolean(kDisableColorOption, disable_color_options); 547 settings_info.SetBoolean(kDisableColorOption, disable_color_options);
545 if (printer_color_space_for_color == printing::UNKNOWN_COLOR_MODEL) 548 if (printer_color_space_for_color == printing::UNKNOWN_COLOR_MODEL)
(...skipping 16 matching lines...) Expand all
562 base::Bind(&PrintSystemTaskProxy::SendPrinterCapabilities, this, 565 base::Bind(&PrintSystemTaskProxy::SendPrinterCapabilities, this,
563 settings_info.DeepCopy())); 566 settings_info.DeepCopy()));
564 } 567 }
565 568
566 void PrintSystemTaskProxy::SendPrinterCapabilities( 569 void PrintSystemTaskProxy::SendPrinterCapabilities(
567 DictionaryValue* settings_info) { 570 DictionaryValue* settings_info) {
568 if (handler_) 571 if (handler_)
569 handler_->SendPrinterCapabilities(*settings_info); 572 handler_->SendPrinterCapabilities(*settings_info);
570 delete settings_info; 573 delete settings_info;
571 } 574 }
575
576 void PrintSystemTaskProxy::SendFailedToGetPrinterCapabilities(
577 const std::string& printer_name) {
578 if (handler_)
579 handler_->SendFailedToGetPrinterCapabilities(printer_name);
Robert Toscano 2012/08/22 01:05:31 Is it Google C++ to leave off curlies on one-liner
Albert Bodenhamer 2012/08/22 01:09:41 It's the preferred Chrome style. I personally dis
Vitaly Buka (NO REVIEWS) 2012/08/22 02:58:02 Both styles are allowed.
580 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698