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

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

Issue 1232783007: Cleanup: Fix some misc nits in printing code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
« no previous file with comments | « chrome/browser/printing/print_preview_message_handler.h ('k') | printing/pdf_metafile_skia.cc » ('j') | 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/printing/print_preview_message_handler.h" 5 #include "chrome/browser/printing/print_preview_message_handler.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 11 matching lines...) Expand all
22 #include "content/public/browser/web_contents.h" 22 #include "content/public/browser/web_contents.h"
23 #include "content/public/browser/web_ui.h" 23 #include "content/public/browser/web_ui.h"
24 #include "printing/page_size_margins.h" 24 #include "printing/page_size_margins.h"
25 #include "printing/print_job_constants.h" 25 #include "printing/print_job_constants.h"
26 26
27 using content::BrowserThread; 27 using content::BrowserThread;
28 using content::WebContents; 28 using content::WebContents;
29 29
30 DEFINE_WEB_CONTENTS_USER_DATA_KEY(printing::PrintPreviewMessageHandler); 30 DEFINE_WEB_CONTENTS_USER_DATA_KEY(printing::PrintPreviewMessageHandler);
31 31
32 namespace printing {
33
32 namespace { 34 namespace {
33 35
34 void StopWorker(int document_cookie) { 36 void StopWorker(int document_cookie) {
35 if (document_cookie <= 0) 37 if (document_cookie <= 0)
36 return; 38 return;
37 scoped_refptr<printing::PrintQueriesQueue> queue = 39 scoped_refptr<PrintQueriesQueue> queue =
38 g_browser_process->print_job_manager()->queue(); 40 g_browser_process->print_job_manager()->queue();
39 scoped_refptr<printing::PrinterQuery> printer_query = 41 scoped_refptr<PrinterQuery> printer_query =
40 queue->PopPrinterQuery(document_cookie); 42 queue->PopPrinterQuery(document_cookie);
41 if (printer_query.get()) { 43 if (printer_query.get()) {
42 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 44 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
43 base::Bind(&printing::PrinterQuery::StopWorker, 45 base::Bind(&PrinterQuery::StopWorker,
44 printer_query)); 46 printer_query));
45 } 47 }
46 } 48 }
47 49
48 base::RefCountedBytes* GetDataFromHandle(base::SharedMemoryHandle handle, 50 base::RefCountedBytes* GetDataFromHandle(base::SharedMemoryHandle handle,
49 uint32 data_size) { 51 uint32_t data_size) {
50 scoped_ptr<base::SharedMemory> shared_buf( 52 scoped_ptr<base::SharedMemory> shared_buf(
51 new base::SharedMemory(handle, true)); 53 new base::SharedMemory(handle, true));
52 if (!shared_buf->Map(data_size)) { 54 if (!shared_buf->Map(data_size)) {
53 NOTREACHED(); 55 NOTREACHED();
54 return NULL; 56 return nullptr;
55 } 57 }
56 58
57 unsigned char* data_begin = static_cast<unsigned char*>(shared_buf->memory()); 59 unsigned char* data_begin = static_cast<unsigned char*>(shared_buf->memory());
58 std::vector<unsigned char> data(data_begin, data_begin + data_size); 60 std::vector<unsigned char> data(data_begin, data_begin + data_size);
59 return base::RefCountedBytes::TakeVector(&data); 61 return base::RefCountedBytes::TakeVector(&data);
60 } 62 }
61 63
62 } // namespace 64 } // namespace
63 65
64 namespace printing {
65
66 PrintPreviewMessageHandler::PrintPreviewMessageHandler( 66 PrintPreviewMessageHandler::PrintPreviewMessageHandler(
67 WebContents* web_contents) 67 WebContents* web_contents)
68 : content::WebContentsObserver(web_contents) { 68 : content::WebContentsObserver(web_contents) {
69 DCHECK(web_contents); 69 DCHECK(web_contents);
70 } 70 }
71 71
72 PrintPreviewMessageHandler::~PrintPreviewMessageHandler() { 72 PrintPreviewMessageHandler::~PrintPreviewMessageHandler() {
73 } 73 }
74 74
75 WebContents* PrintPreviewMessageHandler::GetPrintPreviewDialog() { 75 WebContents* PrintPreviewMessageHandler::GetPrintPreviewDialog() {
76 PrintPreviewDialogController* dialog_controller = 76 PrintPreviewDialogController* dialog_controller =
77 PrintPreviewDialogController::GetInstance(); 77 PrintPreviewDialogController::GetInstance();
78 if (!dialog_controller) 78 if (!dialog_controller)
79 return NULL; 79 return nullptr;
80 return dialog_controller->GetPrintPreviewForContents(web_contents()); 80 return dialog_controller->GetPrintPreviewForContents(web_contents());
81 } 81 }
82 82
83 PrintPreviewUI* PrintPreviewMessageHandler::GetPrintPreviewUI() { 83 PrintPreviewUI* PrintPreviewMessageHandler::GetPrintPreviewUI() {
84 WebContents* dialog = GetPrintPreviewDialog(); 84 WebContents* dialog = GetPrintPreviewDialog();
85 if (!dialog || !dialog->GetWebUI()) 85 if (!dialog || !dialog->GetWebUI())
86 return NULL; 86 return nullptr;
87 return static_cast<PrintPreviewUI*>(dialog->GetWebUI()->GetController()); 87 return static_cast<PrintPreviewUI*>(dialog->GetWebUI()->GetController());
88 } 88 }
89 89
90 void PrintPreviewMessageHandler::OnRequestPrintPreview( 90 void PrintPreviewMessageHandler::OnRequestPrintPreview(
91 const PrintHostMsg_RequestPrintPreview_Params& params) { 91 const PrintHostMsg_RequestPrintPreview_Params& params) {
92 if (params.webnode_only) { 92 if (params.webnode_only)
93 printing::PrintViewManager::FromWebContents(web_contents())-> 93 PrintViewManager::FromWebContents(web_contents())->PrintPreviewForWebNode();
94 PrintPreviewForWebNode();
95 }
96 PrintPreviewDialogController::PrintPreview(web_contents()); 94 PrintPreviewDialogController::PrintPreview(web_contents());
97 PrintPreviewUI::SetInitialParams(GetPrintPreviewDialog(), params); 95 PrintPreviewUI::SetInitialParams(GetPrintPreviewDialog(), params);
98 } 96 }
99 97
100 void PrintPreviewMessageHandler::OnDidGetPreviewPageCount( 98 void PrintPreviewMessageHandler::OnDidGetPreviewPageCount(
101 const PrintHostMsg_DidGetPreviewPageCount_Params& params) { 99 const PrintHostMsg_DidGetPreviewPageCount_Params& params) {
102 if (params.page_count <= 0) { 100 if (params.page_count <= 0) {
103 NOTREACHED(); 101 NOTREACHED();
104 return; 102 return;
105 } 103 }
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 IPC_MESSAGE_HANDLER(PrintHostMsg_PrintPreviewInvalidPrinterSettings, 221 IPC_MESSAGE_HANDLER(PrintHostMsg_PrintPreviewInvalidPrinterSettings,
224 OnInvalidPrinterSettings) 222 OnInvalidPrinterSettings)
225 IPC_MESSAGE_HANDLER(PrintHostMsg_SetOptionsFromDocument, 223 IPC_MESSAGE_HANDLER(PrintHostMsg_SetOptionsFromDocument,
226 OnSetOptionsFromDocument) 224 OnSetOptionsFromDocument)
227 IPC_MESSAGE_UNHANDLED(handled = false) 225 IPC_MESSAGE_UNHANDLED(handled = false)
228 IPC_END_MESSAGE_MAP() 226 IPC_END_MESSAGE_MAP()
229 return handled; 227 return handled;
230 } 228 }
231 229
232 } // namespace printing 230 } // namespace printing
OLDNEW
« no previous file with comments | « chrome/browser/printing/print_preview_message_handler.h ('k') | printing/pdf_metafile_skia.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698