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

Side by Side Diff: chrome/browser/ui/webui/print_preview/print_preview_handler.cc

Issue 10387162: Add additional stats for print preview. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review feedback Created 8 years, 7 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/browser/ui/webui/print_preview/print_preview_handler.h ('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 "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 #include <vector> 10 #include <vector>
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 LANDSCAPE, 88 LANDSCAPE,
89 PORTRAIT, 89 PORTRAIT,
90 COLOR, 90 COLOR,
91 BLACK_AND_WHITE, 91 BLACK_AND_WHITE,
92 COLLATE, 92 COLLATE,
93 SIMPLEX, 93 SIMPLEX,
94 DUPLEX, 94 DUPLEX,
95 PRINT_SETTINGS_BUCKET_BOUNDARY 95 PRINT_SETTINGS_BUCKET_BOUNDARY
96 }; 96 };
97 97
98 enum PrintDestinationBuckets {
99 DESTINATION_SHOWN,
100 DESTINATION_CLOSED_CHANGED,
101 DESTINATION_CLOSED_UNCHANGED,
102 SIGNIN_PROMPT,
103 SIGNIN_TRIGGERED,
104 PRINT_DESTINATION_BUCKET_BOUNDARY
105 };
106
98 void ReportUserActionHistogram(enum UserActionBuckets event) { 107 void ReportUserActionHistogram(enum UserActionBuckets event) {
99 UMA_HISTOGRAM_ENUMERATION("PrintPreview.UserAction", event, 108 UMA_HISTOGRAM_ENUMERATION("PrintPreview.UserAction", event,
100 USERACTION_BUCKET_BOUNDARY); 109 USERACTION_BUCKET_BOUNDARY);
101 } 110 }
102 111
103 void ReportPrintSettingHistogram(enum PrintSettingsBuckets setting) { 112 void ReportPrintSettingHistogram(enum PrintSettingsBuckets setting) {
104 UMA_HISTOGRAM_ENUMERATION("PrintPreview.PrintSettings", setting, 113 UMA_HISTOGRAM_ENUMERATION("PrintPreview.PrintSettings", setting,
105 PRINT_SETTINGS_BUCKET_BOUNDARY); 114 PRINT_SETTINGS_BUCKET_BOUNDARY);
106 } 115 }
107 116
117 void ReportPrintDestinationHistogram(enum PrintDestinationBuckets event) {
118 UMA_HISTOGRAM_ENUMERATION("PrintPreview.DestinationAction", event,
119 PRINT_DESTINATION_BUCKET_BOUNDARY);
120 }
121
108 // Name of a dictionary fielad holdong cloud print related data; 122 // Name of a dictionary fielad holdong cloud print related data;
109 const char kCloudPrintData[] = "cloudPrintData"; 123 const char kCloudPrintData[] = "cloudPrintData";
110 // Name of a dictionary field holding the initiator tab title. 124 // Name of a dictionary field holding the initiator tab title.
111 const char kInitiatorTabTitle[] = "initiatorTabTitle"; 125 const char kInitiatorTabTitle[] = "initiatorTabTitle";
112 // Name of a dictionary field holding the measurement system according to the 126 // Name of a dictionary field holding the measurement system according to the
113 // locale. 127 // locale.
114 const char kMeasurementSystem[] = "measurementSystem"; 128 const char kMeasurementSystem[] = "measurementSystem";
115 // Name of a dictionary field holding the number format according to the locale. 129 // Name of a dictionary field holding the number format according to the locale.
116 const char kNumberFormat[] = "numberFormat"; 130 const char kNumberFormat[] = "numberFormat";
117 // Name of a dictionary field specifying whether to print automatically in 131 // Name of a dictionary field specifying whether to print automatically in
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 217
204 // static 218 // static
205 printing::StickySettings* PrintPreviewHandler::GetStickySettings() { 219 printing::StickySettings* PrintPreviewHandler::GetStickySettings() {
206 return sticky_settings.Pointer(); 220 return sticky_settings.Pointer();
207 } 221 }
208 222
209 PrintPreviewHandler::PrintPreviewHandler() 223 PrintPreviewHandler::PrintPreviewHandler()
210 : print_backend_(printing::PrintBackend::CreateInstance(NULL)), 224 : print_backend_(printing::PrintBackend::CreateInstance(NULL)),
211 regenerate_preview_request_count_(0), 225 regenerate_preview_request_count_(0),
212 manage_printers_dialog_request_count_(0), 226 manage_printers_dialog_request_count_(0),
227 manage_cloud_printers_dialog_request_count_(0),
213 reported_failed_preview_(false), 228 reported_failed_preview_(false),
214 has_logged_printers_count_(false) { 229 has_logged_printers_count_(false) {
215 ReportUserActionHistogram(PREVIEW_STARTED); 230 ReportUserActionHistogram(PREVIEW_STARTED);
216 } 231 }
217 232
218 PrintPreviewHandler::~PrintPreviewHandler() { 233 PrintPreviewHandler::~PrintPreviewHandler() {
219 if (select_file_dialog_.get()) 234 if (select_file_dialog_.get())
220 select_file_dialog_->ListenerDestroyed(); 235 select_file_dialog_->ListenerDestroyed();
221 } 236 }
222 237
(...skipping 30 matching lines...) Expand all
253 base::Unretained(this))); 268 base::Unretained(this)));
254 web_ui()->RegisterMessageCallback("cancelPendingPrintRequest", 269 web_ui()->RegisterMessageCallback("cancelPendingPrintRequest",
255 base::Bind(&PrintPreviewHandler::HandleCancelPendingPrintRequest, 270 base::Bind(&PrintPreviewHandler::HandleCancelPendingPrintRequest,
256 base::Unretained(this))); 271 base::Unretained(this)));
257 web_ui()->RegisterMessageCallback("saveLastPrinter", 272 web_ui()->RegisterMessageCallback("saveLastPrinter",
258 base::Bind(&PrintPreviewHandler::HandleSaveLastPrinter, 273 base::Bind(&PrintPreviewHandler::HandleSaveLastPrinter,
259 base::Unretained(this))); 274 base::Unretained(this)));
260 web_ui()->RegisterMessageCallback("getInitialSettings", 275 web_ui()->RegisterMessageCallback("getInitialSettings",
261 base::Bind(&PrintPreviewHandler::HandleGetInitialSettings, 276 base::Bind(&PrintPreviewHandler::HandleGetInitialSettings,
262 base::Unretained(this))); 277 base::Unretained(this)));
278 web_ui()->RegisterMessageCallback("reportDestinationEvent",
279 base::Bind(&PrintPreviewHandler::HandleReportDestinationEvent,
280 base::Unretained(this)));
263 } 281 }
264 282
265 TabContentsWrapper* PrintPreviewHandler::preview_tab_wrapper() const { 283 TabContentsWrapper* PrintPreviewHandler::preview_tab_wrapper() const {
266 return TabContentsWrapper::GetCurrentWrapperForContents(preview_tab()); 284 return TabContentsWrapper::GetCurrentWrapperForContents(preview_tab());
267 } 285 }
268 286
269 WebContents* PrintPreviewHandler::preview_tab() const { 287 WebContents* PrintPreviewHandler::preview_tab() const {
270 return web_ui()->GetWebContents(); 288 return web_ui()->GetWebContents();
271 } 289 }
272 290
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 547
530 void PrintPreviewHandler::HandleSignin(const ListValue* /*args*/) { 548 void PrintPreviewHandler::HandleSignin(const ListValue* /*args*/) {
531 print_dialog_cloud::CreateCloudPrintSigninDialog( 549 print_dialog_cloud::CreateCloudPrintSigninDialog(
532 base::Bind(&PrintPreviewHandler::OnSigninComplete, AsWeakPtr())); 550 base::Bind(&PrintPreviewHandler::OnSigninComplete, AsWeakPtr()));
533 } 551 }
534 552
535 void PrintPreviewHandler::HandlePrintWithCloudPrint() { 553 void PrintPreviewHandler::HandlePrintWithCloudPrint() {
536 // Record the number of times the user asks to print via cloud print 554 // Record the number of times the user asks to print via cloud print
537 // instead of the print preview dialog. 555 // instead of the print preview dialog.
538 ReportStats(); 556 ReportStats();
539 ReportUserActionHistogram(PRINT_WITH_CLOUD_PRINT);
540 557
541 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( 558 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(
542 web_ui()->GetController()); 559 web_ui()->GetController());
543 scoped_refptr<base::RefCountedBytes> data; 560 scoped_refptr<base::RefCountedBytes> data;
544 print_preview_ui->GetPrintPreviewDataForIndex( 561 print_preview_ui->GetPrintPreviewDataForIndex(
545 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data); 562 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data);
546 if (!data.get()) { 563 if (!data.get()) {
547 NOTREACHED(); 564 NOTREACHED();
548 return; 565 return;
549 } 566 }
550 DCHECK_GT(data->size(), 0U); 567 DCHECK_GT(data->size(), 0U);
551 print_dialog_cloud::CreatePrintDialogForBytes(data, 568 print_dialog_cloud::CreatePrintDialogForBytes(data,
552 string16(print_preview_ui->initiator_tab_title()), 569 string16(print_preview_ui->initiator_tab_title()),
553 string16(), 570 string16(),
554 std::string("application/pdf"), 571 std::string("application/pdf"),
555 true); 572 true);
556 573
557 // Once the cloud print dialog comes up we're no longer in a background 574 // Once the cloud print dialog comes up we're no longer in a background
558 // printing situation. Close the print preview. 575 // printing situation. Close the print preview.
559 // TODO(abodenha@chromium.org) The flow should be changed as described in 576 // TODO(abodenha@chromium.org) The flow should be changed as described in
560 // http://code.google.com/p/chromium/issues/detail?id=44093 577 // http://code.google.com/p/chromium/issues/detail?id=44093
561 ActivateInitiatorTabAndClosePreviewTab(); 578 ActivateInitiatorTabAndClosePreviewTab();
562 } 579 }
563 580
564 void PrintPreviewHandler::HandleManageCloudPrint(const ListValue* /*args*/) { 581 void PrintPreviewHandler::HandleManageCloudPrint(const ListValue* /*args*/) {
582 ++manage_cloud_printers_dialog_request_count_;
565 Browser* browser = BrowserList::GetLastActive(); 583 Browser* browser = BrowserList::GetLastActive();
566 if (browser != NULL) 584 if (browser != NULL)
567 browser->OpenURL(OpenURLParams( 585 browser->OpenURL(OpenURLParams(
568 CloudPrintURL(browser->profile()).GetCloudPrintServiceManageURL(), 586 CloudPrintURL(browser->profile()).GetCloudPrintServiceManageURL(),
569 Referrer(), 587 Referrer(),
570 NEW_FOREGROUND_TAB, 588 NEW_FOREGROUND_TAB,
571 content::PAGE_TRANSITION_LINK, 589 content::PAGE_TRANSITION_LINK,
572 false)); 590 false));
573 } 591 }
574 592
(...skipping 26 matching lines...) Expand all
601 619
602 // Record the number of times the user requests to regenerate preview data 620 // Record the number of times the user requests to regenerate preview data
603 // before cancelling. 621 // before cancelling.
604 UMA_HISTOGRAM_COUNTS("PrintPreview.RegeneratePreviewRequest.BeforeCancel", 622 UMA_HISTOGRAM_COUNTS("PrintPreview.RegeneratePreviewRequest.BeforeCancel",
605 regenerate_preview_request_count_); 623 regenerate_preview_request_count_);
606 } 624 }
607 625
608 void PrintPreviewHandler::ReportStats() { 626 void PrintPreviewHandler::ReportStats() {
609 UMA_HISTOGRAM_COUNTS("PrintPreview.ManagePrinters", 627 UMA_HISTOGRAM_COUNTS("PrintPreview.ManagePrinters",
610 manage_printers_dialog_request_count_); 628 manage_printers_dialog_request_count_);
629 UMA_HISTOGRAM_COUNTS("PrintPreview.ManageCloudPrinters",
630 manage_cloud_printers_dialog_request_count_);
611 } 631 }
612 632
613 void PrintPreviewHandler::GetNumberFormatAndMeasurementSystem( 633 void PrintPreviewHandler::GetNumberFormatAndMeasurementSystem(
614 base::DictionaryValue* settings) { 634 base::DictionaryValue* settings) {
615 635
616 // Getting the measurement system based on the locale. 636 // Getting the measurement system based on the locale.
617 UErrorCode errorCode = U_ZERO_ERROR; 637 UErrorCode errorCode = U_ZERO_ERROR;
618 const char* locale = g_browser_process->GetApplicationLocale().c_str(); 638 const char* locale = g_browser_process->GetApplicationLocale().c_str();
619 UMeasurementSystem system = ulocdata_getMeasurementSystem(locale, &errorCode); 639 UMeasurementSystem system = ulocdata_getMeasurementSystem(locale, &errorCode);
620 if (errorCode > U_ZERO_ERROR || system == UMS_LIMIT) 640 if (errorCode > U_ZERO_ERROR || system == UMS_LIMIT)
621 system = UMS_SI; 641 system = UMS_SI;
622 642
623 // Getting the number formatting based on the locale and writing to 643 // Getting the number formatting based on the locale and writing to
624 // dictionary. 644 // dictionary.
625 settings->SetString(kNumberFormat, base::FormatDouble(123456.78, 2)); 645 settings->SetString(kNumberFormat, base::FormatDouble(123456.78, 2));
626 settings->SetInteger(kMeasurementSystem, system); 646 settings->SetInteger(kMeasurementSystem, system);
627 } 647 }
628 648
629 void PrintPreviewHandler::HandleGetInitialSettings(const ListValue* /*args*/) { 649 void PrintPreviewHandler::HandleGetInitialSettings(const ListValue* /*args*/) {
630 scoped_refptr<PrintSystemTaskProxy> task = 650 scoped_refptr<PrintSystemTaskProxy> task =
631 new PrintSystemTaskProxy(AsWeakPtr(), 651 new PrintSystemTaskProxy(AsWeakPtr(),
632 print_backend_.get(), 652 print_backend_.get(),
633 has_logged_printers_count_); 653 has_logged_printers_count_);
634 BrowserThread::PostTask( 654 BrowserThread::PostTask(
635 BrowserThread::FILE, FROM_HERE, 655 BrowserThread::FILE, FROM_HERE,
636 base::Bind(&PrintSystemTaskProxy::GetDefaultPrinter, task.get())); 656 base::Bind(&PrintSystemTaskProxy::GetDefaultPrinter, task.get()));
637 } 657 }
638 658
659 void PrintPreviewHandler::HandleReportDestinationEvent(const ListValue* args) {
660 int event_number;
661 bool ret = args->GetInteger(0, &event_number);
662 if (!ret)
663 return;
664 enum PrintDestinationBuckets event =
665 static_cast<enum PrintDestinationBuckets>(event_number);
666 if (event >= PRINT_DESTINATION_BUCKET_BOUNDARY)
667 return;
668 ReportPrintDestinationHistogram(event);
669 }
670
639 void PrintPreviewHandler::SendInitialSettings( 671 void PrintPreviewHandler::SendInitialSettings(
640 const std::string& default_printer, 672 const std::string& default_printer,
641 const std::string& cloud_print_data) { 673 const std::string& cloud_print_data) {
642 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( 674 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(
643 web_ui()->GetController()); 675 web_ui()->GetController());
644 676
645 base::DictionaryValue initial_settings; 677 base::DictionaryValue initial_settings;
646 initial_settings.SetString(kInitiatorTabTitle, 678 initial_settings.SetString(kInitiatorTabTitle,
647 print_preview_ui->initiator_tab_title()); 679 print_preview_ui->initiator_tab_title());
648 initial_settings.SetBoolean(printing::kSettingPreviewModifiable, 680 initial_settings.SetBoolean(printing::kSettingPreviewModifiable,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 if (prefs->GetBoolean(prefs::kCloudPrintSubmitEnabled)) { 734 if (prefs->GetBoolean(prefs::kCloudPrintSubmitEnabled)) {
703 GURL gcp_url(CloudPrintURL(profile).GetCloudPrintServiceURL()); 735 GURL gcp_url(CloudPrintURL(profile).GetCloudPrintServiceURL());
704 base::StringValue gcp_url_value(gcp_url.spec()); 736 base::StringValue gcp_url_value(gcp_url.spec());
705 web_ui()->CallJavascriptFunction("setUseCloudPrint", gcp_url_value); 737 web_ui()->CallJavascriptFunction("setUseCloudPrint", gcp_url_value);
706 } 738 }
707 } 739 }
708 } 740 }
709 741
710 void PrintPreviewHandler::SendCloudPrintJob(const DictionaryValue& settings, 742 void PrintPreviewHandler::SendCloudPrintJob(const DictionaryValue& settings,
711 std::string print_ticket) { 743 std::string print_ticket) {
744 ReportUserActionHistogram(PRINT_WITH_CLOUD_PRINT);
712 scoped_refptr<base::RefCountedBytes> data; 745 scoped_refptr<base::RefCountedBytes> data;
713 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( 746 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(
714 web_ui()->GetController()); 747 web_ui()->GetController());
715 print_preview_ui->GetPrintPreviewDataForIndex( 748 print_preview_ui->GetPrintPreviewDataForIndex(
716 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data); 749 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data);
717 if (data.get() && data->size() > 0U && data->front()) { 750 if (data.get() && data->size() > 0U && data->front()) {
718 string16 print_job_title_utf16 = 751 string16 print_job_title_utf16 =
719 preview_tab_wrapper()->print_view_manager()->RenderSourceName(); 752 preview_tab_wrapper()->print_view_manager()->RenderSourceName();
720 std::string print_job_title = UTF16ToUTF8(print_job_title_utf16); 753 std::string print_job_title = UTF16ToUTF8(print_job_title_utf16);
721 std::string printer_id; 754 std::string printer_id;
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 return; 903 return;
871 904
872 // We no longer require the initiator tab details. Remove those details 905 // We no longer require the initiator tab details. Remove those details
873 // associated with the preview tab to allow the initiator tab to create 906 // associated with the preview tab to allow the initiator tab to create
874 // another preview tab. 907 // another preview tab.
875 printing::PrintPreviewTabController* tab_controller = 908 printing::PrintPreviewTabController* tab_controller =
876 printing::PrintPreviewTabController::GetInstance(); 909 printing::PrintPreviewTabController::GetInstance();
877 if (tab_controller) 910 if (tab_controller)
878 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper()); 911 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper());
879 } 912 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/print_preview/print_preview_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698