| OLD | NEW |
| 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/ui/webui/print_preview/print_preview_handler.h" | 5 #include "chrome/browser/ui/webui/print_preview/print_preview_handler.h" |
| 6 | 6 |
| 7 #include <ctype.h> | 7 #include <ctype.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 } | 179 } |
| 180 | 180 |
| 181 if (settings->empty()) { | 181 if (settings->empty()) { |
| 182 NOTREACHED() << "Print job settings dictionary is empty"; | 182 NOTREACHED() << "Print job settings dictionary is empty"; |
| 183 return NULL; | 183 return NULL; |
| 184 } | 184 } |
| 185 | 185 |
| 186 return settings.release(); | 186 return settings.release(); |
| 187 } | 187 } |
| 188 | 188 |
| 189 void ReportPageCount(const DictionaryValue& settings, | 189 void ReportPageCount(int page_count, const std::string& printer_type) { |
| 190 const std::string& printer_type) { | |
| 191 int count = 0; | |
| 192 const ListValue* page_range_array; | |
| 193 if (settings.GetList(printing::kSettingPageRange, &page_range_array)) { | |
| 194 for (size_t index = 0; index < page_range_array->GetSize(); ++index) { | |
| 195 const DictionaryValue* dict; | |
| 196 if (!page_range_array->GetDictionary(index, &dict)) | |
| 197 continue; | |
| 198 | |
| 199 printing::PageRange range; | |
| 200 if (!dict->GetInteger(printing::kSettingPageRangeFrom, &range.from) || | |
| 201 !dict->GetInteger(printing::kSettingPageRangeTo, &range.to)) { | |
| 202 continue; | |
| 203 } | |
| 204 count += (range.to - range.from) + 1; | |
| 205 } | |
| 206 } | |
| 207 UMA_HISTOGRAM_COUNTS(base::StringPrintf("PrintPreview.PageCount.%s", | 190 UMA_HISTOGRAM_COUNTS(base::StringPrintf("PrintPreview.PageCount.%s", |
| 208 printer_type.c_str()), | 191 printer_type.c_str()), |
| 209 count); | 192 page_count); |
| 210 } | 193 } |
| 211 | 194 |
| 212 // Track the popularity of print settings and report the stats. | 195 // Track the popularity of print settings and report the stats. |
| 213 void ReportPrintSettingsStats(const DictionaryValue& settings) { | 196 void ReportPrintSettingsStats(const DictionaryValue& settings) { |
| 214 bool landscape; | 197 bool landscape; |
| 215 if (settings.GetBoolean(printing::kSettingLandscape, &landscape)) | 198 if (settings.GetBoolean(printing::kSettingLandscape, &landscape)) |
| 216 ReportPrintSettingHistogram(landscape ? LANDSCAPE : PORTRAIT); | 199 ReportPrintSettingHistogram(landscape ? LANDSCAPE : PORTRAIT); |
| 217 | 200 |
| 218 bool collate; | 201 bool collate; |
| 219 if (settings.GetBoolean(printing::kSettingCollate, &collate) && collate) | 202 if (settings.GetBoolean(printing::kSettingCollate, &collate) && collate) |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 #if defined(OS_MACOSX) | 430 #if defined(OS_MACOSX) |
| 448 open_pdf_in_preview = settings->HasKey(printing::kSettingOpenPDFInPreview); | 431 open_pdf_in_preview = settings->HasKey(printing::kSettingOpenPDFInPreview); |
| 449 #endif | 432 #endif |
| 450 | 433 |
| 451 if (!open_pdf_in_preview) { | 434 if (!open_pdf_in_preview) { |
| 452 settings->GetBoolean(printing::kSettingPrintToPDF, &print_to_pdf); | 435 settings->GetBoolean(printing::kSettingPrintToPDF, &print_to_pdf); |
| 453 settings->GetBoolean(printing::kSettingCloudPrintDialog, &is_cloud_dialog); | 436 settings->GetBoolean(printing::kSettingCloudPrintDialog, &is_cloud_dialog); |
| 454 is_cloud_printer = settings->HasKey(printing::kSettingCloudPrintId); | 437 is_cloud_printer = settings->HasKey(printing::kSettingCloudPrintId); |
| 455 } | 438 } |
| 456 | 439 |
| 440 int page_count = 0; |
| 441 settings->GetInteger(printing::kSettingPreviewPageCount, &page_count); |
| 442 |
| 457 if (print_to_pdf) { | 443 if (print_to_pdf) { |
| 458 ReportPageCount(*settings, "PrintToPDF"); | 444 ReportPageCount(page_count, "PrintToPDF"); |
| 459 ReportUserActionHistogram(PRINT_TO_PDF); | 445 ReportUserActionHistogram(PRINT_TO_PDF); |
| 460 PrintToPdf(); | 446 PrintToPdf(); |
| 461 return; | 447 return; |
| 462 } | 448 } |
| 463 | 449 |
| 464 scoped_refptr<base::RefCountedBytes> data; | 450 scoped_refptr<base::RefCountedBytes> data; |
| 465 string16 title; | 451 string16 title; |
| 466 if (!GetPreviewDataAndTitle(&data, &title)) { | 452 if (!GetPreviewDataAndTitle(&data, &title)) { |
| 467 // Nothing to print, no preview available. | 453 // Nothing to print, no preview available. |
| 468 return; | 454 return; |
| 469 } | 455 } |
| 470 | 456 |
| 471 if (is_cloud_printer) { | 457 if (is_cloud_printer) { |
| 472 ReportPageCount(*settings, "PrintToCloudPrint"); | 458 ReportPageCount(page_count, "PrintToCloudPrint"); |
| 473 ReportUserActionHistogram(PRINT_WITH_CLOUD_PRINT); | 459 ReportUserActionHistogram(PRINT_WITH_CLOUD_PRINT); |
| 474 SendCloudPrintJob(data); | 460 SendCloudPrintJob(data); |
| 475 } else if (is_cloud_dialog) { | 461 } else if (is_cloud_dialog) { |
| 476 ReportPageCount(*settings, "PrintToCloudPrintWebDialog"); | 462 ReportPageCount(page_count, "PrintToCloudPrintWebDialog"); |
| 477 PrintWithCloudPrintDialog(data, title); | 463 PrintWithCloudPrintDialog(data, title); |
| 478 } else { | 464 } else { |
| 479 ReportPageCount(*settings, "PrintToPrinter"); | 465 ReportPageCount(page_count, "PrintToPrinter"); |
| 480 ReportUserActionHistogram(PRINT_TO_PRINTER); | 466 ReportUserActionHistogram(PRINT_TO_PRINTER); |
| 481 ReportPrintSettingsStats(*settings); | 467 ReportPrintSettingsStats(*settings); |
| 482 | 468 |
| 483 // This tries to activate the initiator tab as well, so do not clear the | 469 // This tries to activate the initiator tab as well, so do not clear the |
| 484 // association with the initiator tab yet. | 470 // association with the initiator tab yet. |
| 485 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( | 471 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
| 486 web_ui()->GetController()); | 472 web_ui()->GetController()); |
| 487 print_preview_ui->OnHidePreviewDialog(); | 473 print_preview_ui->OnHidePreviewDialog(); |
| 488 | 474 |
| 489 // Do this so the initiator tab can open a new print preview dialog. | 475 // Do this so the initiator tab can open a new print preview dialog. |
| (...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 986 // Nothing to print, no preview available. | 972 // Nothing to print, no preview available. |
| 987 return false; | 973 return false; |
| 988 } | 974 } |
| 989 DCHECK(tmp_data->size() && tmp_data->front()); | 975 DCHECK(tmp_data->size() && tmp_data->front()); |
| 990 | 976 |
| 991 *data = tmp_data; | 977 *data = tmp_data; |
| 992 *title = print_preview_ui->initiator_tab_title(); | 978 *title = print_preview_ui->initiator_tab_title(); |
| 993 return true; | 979 return true; |
| 994 } | 980 } |
| 995 | 981 |
| OLD | NEW |