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

Side by Side Diff: components/printing/test/mock_printer.cc

Issue 2835193007: Revert of clean up printing::Image and printing::Metafile (Closed)
Patch Set: Created 3 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
« no previous file with comments | « components/printing/test/mock_printer.h ('k') | printing/emf_win.h » ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/printing/test/mock_printer.h" 5 #include "components/printing/test/mock_printer.h"
6 6
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/memory/shared_memory.h" 8 #include "base/memory/shared_memory.h"
9 #include "base/strings/string16.h" 9 #include "base/strings/string16.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 int scale_factor, 44 int scale_factor,
45 PrintMsg_Print_Params* params) { 45 PrintMsg_Print_Params* params) {
46 params->page_size = page_size; 46 params->page_size = page_size;
47 params->scale_factor = static_cast<double>(scale_factor) / 100.0; 47 params->scale_factor = static_cast<double>(scale_factor) / 100.0;
48 } 48 }
49 49
50 } // namespace 50 } // namespace
51 51
52 MockPrinterPage::MockPrinterPage(const void* source_data, 52 MockPrinterPage::MockPrinterPage(const void* source_data,
53 uint32_t source_size, 53 uint32_t source_size,
54 printing::Image image) 54 const printing::Image& image)
55 : source_size_(source_size), image_(std::move(image)) { 55 : source_size_(source_size), image_(image) {
56 // Create copies of the source data 56 // Create copies of the source data
57 source_data_.reset(new uint8_t[source_size]); 57 source_data_.reset(new uint8_t[source_size]);
58 if (source_data_.get()) 58 if (source_data_.get())
59 memcpy(source_data_.get(), source_data, source_size); 59 memcpy(source_data_.get(), source_data, source_size);
60 } 60 }
61 61
62 MockPrinterPage::~MockPrinterPage() { 62 MockPrinterPage::~MockPrinterPage() {
63 } 63 }
64 64
65 MockPrinter::MockPrinter() 65 MockPrinter::MockPrinter()
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 EXPECT_EQ(page_number_, params.page_number); 202 EXPECT_EQ(page_number_, params.page_number);
203 EXPECT_LE(params.page_number, number_pages_); 203 EXPECT_LE(params.page_number, number_pages_);
204 204
205 #if defined(OS_WIN) || defined(OS_MACOSX) 205 #if defined(OS_WIN) || defined(OS_MACOSX)
206 // Load the data sent from a RenderView object and create a PageData object. 206 // Load the data sent from a RenderView object and create a PageData object.
207 // We duplicate the given file handle when creating a base::SharedMemory 207 // We duplicate the given file handle when creating a base::SharedMemory
208 // instance so that its destructor closes the copy. 208 // instance so that its destructor closes the copy.
209 EXPECT_GT(params.data_size, 0U); 209 EXPECT_GT(params.data_size, 0U);
210 base::SharedMemory metafile_data(params.metafile_data_handle, true); 210 base::SharedMemory metafile_data(params.metafile_data_handle, true);
211 metafile_data.Map(params.data_size); 211 metafile_data.Map(params.data_size);
212 printing::Image image(metafile_data.memory(), params.data_size); 212 #if defined(OS_MACOSX)
213 scoped_refptr<MockPrinterPage> page(new MockPrinterPage( 213 printing::PdfMetafileCg metafile;
214 metafile_data.memory(), params.data_size, std::move(image))); 214 #else
215 printing::PdfMetafileSkia metafile(printing::PDF_SKIA_DOCUMENT_TYPE);
216 #endif
217 metafile.InitFromData(metafile_data.memory(), params.data_size);
218 printing::Image image(metafile);
219 MockPrinterPage* page_data =
220 new MockPrinterPage(metafile_data.memory(), params.data_size, image);
221 scoped_refptr<MockPrinterPage> page(page_data);
215 pages_.push_back(page); 222 pages_.push_back(page);
216 #endif 223 #endif
217 224
218 // We finish printing a printing job. 225 // We finish printing a printing job.
219 // Reset the job status and the printer status. 226 // Reset the job status and the printer status.
220 ++page_number_; 227 ++page_number_;
221 if (number_pages_ == page_number_) 228 if (number_pages_ == page_number_)
222 ResetPrinter(); 229 ResetPrinter();
223 } 230 }
224 231
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 params->margin_left = margin_left_; 296 params->margin_left = margin_left_;
290 params->margin_top = margin_top_; 297 params->margin_top = margin_top_;
291 params->is_first_request = is_first_request_; 298 params->is_first_request = is_first_request_;
292 params->print_scaling_option = print_scaling_option_; 299 params->print_scaling_option = print_scaling_option_;
293 params->print_to_pdf = print_to_pdf_; 300 params->print_to_pdf = print_to_pdf_;
294 params->preview_request_id = preview_request_id_; 301 params->preview_request_id = preview_request_id_;
295 params->display_header_footer = display_header_footer_; 302 params->display_header_footer = display_header_footer_;
296 params->title = title_; 303 params->title = title_;
297 params->url = url_; 304 params->url = url_;
298 } 305 }
OLDNEW
« no previous file with comments | « components/printing/test/mock_printer.h ('k') | printing/emf_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698