OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_handler.h" | 5 #include "chrome/browser/ui/webui/print_preview_handler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/i18n/file_util_icu.h" | 9 #include "base/i18n/file_util_icu.h" |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
11 #include "base/metrics/histogram.h" | |
11 #include "base/path_service.h" | 12 #include "base/path_service.h" |
12 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
13 #include "base/threading/thread_restrictions.h" | 14 #include "base/threading/thread_restrictions.h" |
14 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
15 #include "base/values.h" | 16 #include "base/values.h" |
16 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/platform_util.h" | 18 #include "chrome/browser/platform_util.h" |
18 #include "chrome/browser/printing/background_printing_manager.h" | 19 #include "chrome/browser/printing/background_printing_manager.h" |
19 #include "chrome/browser/printing/printer_manager_dialog.h" | 20 #include "chrome/browser/printing/printer_manager_dialog.h" |
20 #include "chrome/browser/printing/print_preview_tab_controller.h" | 21 #include "chrome/browser/printing/print_preview_tab_controller.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
91 : handler_(handler), | 92 : handler_(handler), |
92 print_backend_(print_backend) { | 93 print_backend_(print_backend) { |
93 } | 94 } |
94 | 95 |
95 void EnumeratePrinters() { | 96 void EnumeratePrinters() { |
96 ListValue* printers = new ListValue; | 97 ListValue* printers = new ListValue; |
97 int default_printer_index = -1; | 98 int default_printer_index = -1; |
98 | 99 |
99 printing::PrinterList printer_list; | 100 printing::PrinterList printer_list; |
100 print_backend_->EnumeratePrinters(&printer_list); | 101 print_backend_->EnumeratePrinters(&printer_list); |
101 int i = 0; | 102 int i = 0; |
Lei Zhang
2011/05/13 22:56:20
This is part of the for loop below. Don't separate
kmadhusu
2011/05/13 23:37:12
Done.
| |
103 | |
104 // Record the total number of printers. | |
105 UMA_HISTOGRAM_COUNTS("PrintPreview.TotalNumberOfPrinters", | |
Lei Zhang
2011/05/13 22:56:20
Can you just name this "NumberOfPrinters" ?
Lei Zhang
2011/05/13 22:56:20
jar: does this record "a user has N printers"? Or
kmadhusu
2011/05/13 23:37:12
Done.
| |
106 printer_list.size()); | |
107 | |
102 for (printing::PrinterList::iterator index = printer_list.begin(); | 108 for (printing::PrinterList::iterator index = printer_list.begin(); |
103 index != printer_list.end(); ++index, ++i) { | 109 index != printer_list.end(); ++index, ++i) { |
104 DictionaryValue* printer_info = new DictionaryValue; | 110 DictionaryValue* printer_info = new DictionaryValue; |
105 std::string printerName; | 111 std::string printerName; |
106 #if defined(OS_MACOSX) | 112 #if defined(OS_MACOSX) |
107 // On Mac, |index->printer_description| specifies the printer name and | 113 // On Mac, |index->printer_description| specifies the printer name and |
108 // |index->printer_name| specifies the device name / printer queue name. | 114 // |index->printer_name| specifies the device name / printer queue name. |
109 printerName = index->printer_description; | 115 printerName = index->printer_description; |
110 #else | 116 #else |
111 printerName = index->printer_name; | 117 printerName = index->printer_name; |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
229 scoped_ptr<printing::Metafile> metafile_; | 235 scoped_ptr<printing::Metafile> metafile_; |
230 | 236 |
231 // The absolute path where the file will be saved. | 237 // The absolute path where the file will be saved. |
232 FilePath path_; | 238 FilePath path_; |
233 }; | 239 }; |
234 | 240 |
235 // static | 241 // static |
236 FilePath* PrintPreviewHandler::last_saved_path_ = NULL; | 242 FilePath* PrintPreviewHandler::last_saved_path_ = NULL; |
237 | 243 |
238 PrintPreviewHandler::PrintPreviewHandler() | 244 PrintPreviewHandler::PrintPreviewHandler() |
239 : print_backend_(printing::PrintBackend::CreateInstance(NULL)) { | 245 : print_backend_(printing::PrintBackend::CreateInstance(NULL)), |
246 regenerate_preview_request_count_(0), | |
247 manage_printers_dialog_request_count_(0), | |
248 print_preview_failed_count_(0) { | |
240 } | 249 } |
241 | 250 |
242 PrintPreviewHandler::~PrintPreviewHandler() { | 251 PrintPreviewHandler::~PrintPreviewHandler() { |
243 if (select_file_dialog_.get()) | 252 if (select_file_dialog_.get()) |
244 select_file_dialog_->ListenerDestroyed(); | 253 select_file_dialog_->ListenerDestroyed(); |
245 } | 254 } |
246 | 255 |
247 void PrintPreviewHandler::RegisterMessages() { | 256 void PrintPreviewHandler::RegisterMessages() { |
248 web_ui_->RegisterMessageCallback("getPrinters", | 257 web_ui_->RegisterMessageCallback("getPrinters", |
249 NewCallback(this, &PrintPreviewHandler::HandleGetPrinters)); | 258 NewCallback(this, &PrintPreviewHandler::HandleGetPrinters)); |
(...skipping 18 matching lines...) Expand all Loading... | |
268 void PrintPreviewHandler::HandleGetPrinters(const ListValue*) { | 277 void PrintPreviewHandler::HandleGetPrinters(const ListValue*) { |
269 scoped_refptr<PrintSystemTaskProxy> task = | 278 scoped_refptr<PrintSystemTaskProxy> task = |
270 new PrintSystemTaskProxy(AsWeakPtr(), print_backend_.get()); | 279 new PrintSystemTaskProxy(AsWeakPtr(), print_backend_.get()); |
271 BrowserThread::PostTask( | 280 BrowserThread::PostTask( |
272 BrowserThread::FILE, FROM_HERE, | 281 BrowserThread::FILE, FROM_HERE, |
273 NewRunnableMethod(task.get(), | 282 NewRunnableMethod(task.get(), |
274 &PrintSystemTaskProxy::EnumeratePrinters)); | 283 &PrintSystemTaskProxy::EnumeratePrinters)); |
275 } | 284 } |
276 | 285 |
277 void PrintPreviewHandler::HandleGetPreview(const ListValue* args) { | 286 void PrintPreviewHandler::HandleGetPreview(const ListValue* args) { |
287 // Increment request count. | |
288 ++regenerate_preview_request_count_; | |
289 | |
278 TabContents* initiator_tab = GetInitiatorTab(); | 290 TabContents* initiator_tab = GetInitiatorTab(); |
279 if (!initiator_tab) { | 291 if (!initiator_tab) { |
292 print_preview_failed_count_++; | |
280 web_ui_->CallJavascriptFunction("printPreviewFailed"); | 293 web_ui_->CallJavascriptFunction("printPreviewFailed"); |
281 return; | 294 return; |
282 } | 295 } |
283 scoped_ptr<DictionaryValue> settings(GetSettingsDictionary(args)); | 296 scoped_ptr<DictionaryValue> settings(GetSettingsDictionary(args)); |
284 if (!settings.get()) | 297 if (!settings.get()) |
285 return; | 298 return; |
286 | 299 |
287 RenderViewHost* rvh = initiator_tab->render_view_host(); | 300 RenderViewHost* rvh = initiator_tab->render_view_host(); |
288 rvh->Send(new PrintMsg_PrintPreview(rvh->routing_id(), *settings)); | 301 rvh->Send(new PrintMsg_PrintPreview(rvh->routing_id(), *settings)); |
289 } | 302 } |
290 | 303 |
291 void PrintPreviewHandler::HandlePrint(const ListValue* args) { | 304 void PrintPreviewHandler::HandlePrint(const ListValue* args) { |
305 ReportStats(); | |
306 UMA_HISTOGRAM_COUNTS("PrintPreview.Print", 1); | |
307 | |
308 // Record the number of times the user requests to regenerate preview data | |
309 // before printing. | |
310 UMA_HISTOGRAM_COUNTS( | |
311 "PrintPreview.RegeneratePreviewRequestCount.BeforePrint", | |
Lei Zhang
2011/05/13 22:56:20
I don't think we need Count in the name.
kmadhusu
2011/05/13 23:37:12
Done.
| |
312 regenerate_preview_request_count_); | |
313 | |
292 TabContents* initiator_tab = GetInitiatorTab(); | 314 TabContents* initiator_tab = GetInitiatorTab(); |
293 if (initiator_tab) { | 315 if (initiator_tab) { |
294 RenderViewHost* rvh = initiator_tab->render_view_host(); | 316 RenderViewHost* rvh = initiator_tab->render_view_host(); |
295 rvh->Send(new PrintMsg_ResetScriptedPrintCount(rvh->routing_id())); | 317 rvh->Send(new PrintMsg_ResetScriptedPrintCount(rvh->routing_id())); |
296 } | 318 } |
297 | 319 |
298 scoped_ptr<DictionaryValue> settings(GetSettingsDictionary(args)); | 320 scoped_ptr<DictionaryValue> settings(GetSettingsDictionary(args)); |
299 if (!settings.get()) | 321 if (!settings.get()) |
300 return; | 322 return; |
301 | 323 |
302 bool print_to_pdf = false; | 324 bool print_to_pdf = false; |
303 settings->GetBoolean(printing::kSettingPrintToPDF, &print_to_pdf); | 325 settings->GetBoolean(printing::kSettingPrintToPDF, &print_to_pdf); |
304 | 326 |
305 TabContentsWrapper* preview_tab_wrapper = | 327 TabContentsWrapper* preview_tab_wrapper = |
306 TabContentsWrapper::GetCurrentWrapperForContents(preview_tab()); | 328 TabContentsWrapper::GetCurrentWrapperForContents(preview_tab()); |
307 | 329 |
308 if (print_to_pdf) { | 330 if (print_to_pdf) { |
331 UMA_HISTOGRAM_COUNTS("PrintPreview.PrintToPDF", 1); | |
332 | |
309 // Pre-populating select file dialog with print job title. | 333 // Pre-populating select file dialog with print job title. |
310 string16 print_job_title_utf16 = | 334 string16 print_job_title_utf16 = |
311 preview_tab_wrapper->print_view_manager()->RenderSourceName(); | 335 preview_tab_wrapper->print_view_manager()->RenderSourceName(); |
312 | 336 |
313 #if defined(OS_WIN) | 337 #if defined(OS_WIN) |
314 FilePath::StringType print_job_title(print_job_title_utf16); | 338 FilePath::StringType print_job_title(print_job_title_utf16); |
315 #elif defined(OS_POSIX) | 339 #elif defined(OS_POSIX) |
316 FilePath::StringType print_job_title = UTF16ToUTF8(print_job_title_utf16); | 340 FilePath::StringType print_job_title = UTF16ToUTF8(print_job_title_utf16); |
317 #endif | 341 #endif |
318 | 342 |
(...skipping 26 matching lines...) Expand all Loading... | |
345 new PrintSystemTaskProxy(AsWeakPtr(), print_backend_.get()); | 369 new PrintSystemTaskProxy(AsWeakPtr(), print_backend_.get()); |
346 | 370 |
347 BrowserThread::PostTask( | 371 BrowserThread::PostTask( |
348 BrowserThread::FILE, FROM_HERE, | 372 BrowserThread::FILE, FROM_HERE, |
349 NewRunnableMethod(task.get(), | 373 NewRunnableMethod(task.get(), |
350 &PrintSystemTaskProxy::GetPrinterCapabilities, | 374 &PrintSystemTaskProxy::GetPrinterCapabilities, |
351 printer_name)); | 375 printer_name)); |
352 } | 376 } |
353 | 377 |
354 void PrintPreviewHandler::HandleShowSystemDialog(const ListValue* args) { | 378 void PrintPreviewHandler::HandleShowSystemDialog(const ListValue* args) { |
379 ReportStats(); | |
380 UMA_HISTOGRAM_COUNTS("PrintPreview.ShowAdvanceSettings", 1); | |
355 TabContents* initiator_tab = GetInitiatorTab(); | 381 TabContents* initiator_tab = GetInitiatorTab(); |
356 if (!initiator_tab) | 382 if (!initiator_tab) |
357 return; | 383 return; |
358 initiator_tab->Activate(); | 384 initiator_tab->Activate(); |
359 | 385 |
360 TabContentsWrapper* wrapper = | 386 TabContentsWrapper* wrapper = |
361 TabContentsWrapper::GetCurrentWrapperForContents(initiator_tab); | 387 TabContentsWrapper::GetCurrentWrapperForContents(initiator_tab); |
362 wrapper->print_view_manager()->PrintNow(); | 388 wrapper->print_view_manager()->PrintNow(); |
363 | 389 |
364 ClosePrintPreviewTab(); | 390 ClosePrintPreviewTab(); |
365 } | 391 } |
366 | 392 |
367 void PrintPreviewHandler::HandleManagePrinters(const ListValue* args) { | 393 void PrintPreviewHandler::HandleManagePrinters(const ListValue* args) { |
394 manage_printers_dialog_request_count_++; | |
Lei Zhang
2011/05/13 22:56:20
nit: can we be consistent about ++i vs i++?
kmadhusu
2011/05/13 23:37:12
Done.
| |
368 printing::PrinterManagerDialog::ShowPrinterManagerDialog(); | 395 printing::PrinterManagerDialog::ShowPrinterManagerDialog(); |
369 } | 396 } |
370 | 397 |
371 void PrintPreviewHandler::HandleClosePreviewTab(const ListValue* args) { | 398 void PrintPreviewHandler::HandleClosePreviewTab(const ListValue* args) { |
399 ReportStats(); | |
400 UMA_HISTOGRAM_COUNTS("PrintPreview.Cancel", 1); | |
401 | |
402 // Record the number of times the user requests to regenerate preview data | |
403 // before cancelling. | |
404 UMA_HISTOGRAM_COUNTS( | |
Lei Zhang
2011/05/13 22:56:20
Do you need to check and see if the count is great
kmadhusu
2011/05/13 23:37:12
(repeating our in-person conversation) I have adde
| |
405 "PrintPreview.RegeneratePreviewRequestCount.BeforeCancel", | |
406 regenerate_preview_request_count_); | |
407 | |
372 ActivateInitiatorTabAndClosePreviewTab(); | 408 ActivateInitiatorTabAndClosePreviewTab(); |
373 } | 409 } |
374 | 410 |
411 void PrintPreviewHandler::ReportStats() { | |
412 if (print_preview_failed_count_ > 0) { | |
413 UMA_HISTOGRAM_COUNTS("PrintPreview.Failed.InitiatorTabDoesNotExist", | |
414 print_preview_failed_count_); | |
415 } | |
416 | |
417 if (manage_printers_dialog_request_count_ > 0) { | |
418 UMA_HISTOGRAM_COUNTS("PrintPreview.ManagePrinters", | |
419 manage_printers_dialog_request_count_); | |
420 } | |
421 } | |
422 | |
375 void PrintPreviewHandler::ActivateInitiatorTabAndClosePreviewTab() { | 423 void PrintPreviewHandler::ActivateInitiatorTabAndClosePreviewTab() { |
376 TabContents* initiator_tab = GetInitiatorTab(); | 424 TabContents* initiator_tab = GetInitiatorTab(); |
377 if (initiator_tab) | 425 if (initiator_tab) |
378 initiator_tab->Activate(); | 426 initiator_tab->Activate(); |
379 ClosePrintPreviewTab(); | 427 ClosePrintPreviewTab(); |
380 } | 428 } |
381 | 429 |
382 void PrintPreviewHandler::SendPrinterCapabilities( | 430 void PrintPreviewHandler::SendPrinterCapabilities( |
383 const DictionaryValue& settings_info) { | 431 const DictionaryValue& settings_info) { |
384 web_ui_->CallJavascriptFunction("updateWithPrinterCapabilities", | 432 web_ui_->CallJavascriptFunction("updateWithPrinterCapabilities", |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
453 metafile->InitFromData(data.first->memory(), data.second); | 501 metafile->InitFromData(data.first->memory(), data.second); |
454 | 502 |
455 // Updating last_saved_path_ to the newly selected folder. | 503 // Updating last_saved_path_ to the newly selected folder. |
456 *last_saved_path_ = path.DirName(); | 504 *last_saved_path_ = path.DirName(); |
457 | 505 |
458 PrintToPdfTask* task = new PrintToPdfTask(metafile, path); | 506 PrintToPdfTask* task = new PrintToPdfTask(metafile, path); |
459 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, task); | 507 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, task); |
460 | 508 |
461 ActivateInitiatorTabAndClosePreviewTab(); | 509 ActivateInitiatorTabAndClosePreviewTab(); |
462 } | 510 } |
OLD | NEW |