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

Side by Side Diff: printing/printed_document.cc

Issue 568633002: Extracted MetafilePlayer interface from printing::MetafilePlayer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@no_expose
Patch Set: Thu Sep 11 22:54:16 PDT 2014 Created 6 years, 3 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 | « printing/printed_document.h ('k') | printing/printed_document_linux.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) 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 "printing/printed_document.h" 5 #include "printing/printed_document.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 30 matching lines...) Expand all
41 LAZY_INSTANCE_INITIALIZER; 41 LAZY_INSTANCE_INITIALIZER;
42 42
43 void DebugDumpPageTask(const base::string16& doc_name, 43 void DebugDumpPageTask(const base::string16& doc_name,
44 const PrintedPage* page) { 44 const PrintedPage* page) {
45 if (g_debug_dump_info.Get().empty()) 45 if (g_debug_dump_info.Get().empty())
46 return; 46 return;
47 47
48 base::string16 filename = doc_name; 48 base::string16 filename = doc_name;
49 filename += 49 filename +=
50 base::ASCIIToUTF16(base::StringPrintf("_%04d", page->page_number())); 50 base::ASCIIToUTF16(base::StringPrintf("_%04d", page->page_number()));
51 base::FilePath file_path =
51 #if defined(OS_WIN) 52 #if defined(OS_WIN)
52 page->metafile()->SaveTo(PrintedDocument::CreateDebugDumpPath( 53 PrintedDocument::CreateDebugDumpPath(filename, FILE_PATH_LITERAL(".emf"));
53 filename, FILE_PATH_LITERAL(".emf")));
54 #else // OS_WIN 54 #else // OS_WIN
55 page->metafile()->SaveTo(PrintedDocument::CreateDebugDumpPath( 55 PrintedDocument::CreateDebugDumpPath(filename, FILE_PATH_LITERAL(".pdf"));
56 filename, FILE_PATH_LITERAL(".pdf")));
57 #endif // OS_WIN 56 #endif // OS_WIN
57 base::File file(file_path,
58 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE);
59 page->metafile()->SaveTo(&file);
58 } 60 }
59 61
60 void DebugDumpDataTask(const base::string16& doc_name, 62 void DebugDumpDataTask(const base::string16& doc_name,
61 const base::FilePath::StringType& extension, 63 const base::FilePath::StringType& extension,
62 const base::RefCountedMemory* data) { 64 const base::RefCountedMemory* data) {
63 base::FilePath path = 65 base::FilePath path =
64 PrintedDocument::CreateDebugDumpPath(doc_name, extension); 66 PrintedDocument::CreateDebugDumpPath(doc_name, extension);
65 if (path.empty()) 67 if (path.empty())
66 return; 68 return;
67 base::WriteFile(path, 69 base::WriteFile(path,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 } 104 }
103 105
104 if (!g_debug_dump_info.Get().empty()) 106 if (!g_debug_dump_info.Get().empty())
105 DebugDumpSettings(name(), settings, blocking_runner); 107 DebugDumpSettings(name(), settings, blocking_runner);
106 } 108 }
107 109
108 PrintedDocument::~PrintedDocument() { 110 PrintedDocument::~PrintedDocument() {
109 } 111 }
110 112
111 void PrintedDocument::SetPage(int page_number, 113 void PrintedDocument::SetPage(int page_number,
112 Metafile* metafile, 114 scoped_ptr<MetafilePlayer> metafile,
113 #if defined(OS_WIN) 115 #if defined(OS_WIN)
114 double shrink, 116 double shrink,
115 #endif // OS_WIN 117 #endif // OS_WIN
116 const gfx::Size& paper_size, 118 const gfx::Size& paper_size,
117 const gfx::Rect& page_rect) { 119 const gfx::Rect& page_rect) {
118 // Notice the page_number + 1, the reason is that this is the value that will 120 // Notice the page_number + 1, the reason is that this is the value that will
119 // be shown. Users dislike 0-based counting. 121 // be shown. Users dislike 0-based counting.
120 scoped_refptr<PrintedPage> page( 122 scoped_refptr<PrintedPage> page(
121 new PrintedPage(page_number + 1, metafile, paper_size, page_rect)); 123 new PrintedPage(page_number + 1, metafile.Pass(), paper_size, page_rect));
122 #if defined(OS_WIN) 124 #if defined(OS_WIN)
123 page->set_shrink_factor(shrink); 125 page->set_shrink_factor(shrink);
124 #endif // OS_WIN 126 #endif // OS_WIN
125 { 127 {
126 base::AutoLock lock(lock_); 128 base::AutoLock lock(lock_);
127 mutable_.pages_[page_number] = page; 129 mutable_.pages_[page_number] = page;
128 130
129 #if defined(OS_POSIX) && !defined(OS_MACOSX) 131 #if defined(OS_POSIX) && !defined(OS_MACOSX)
130 if (page_number < mutable_.first_page) 132 if (page_number < mutable_.first_page)
131 mutable_.first_page = page_number; 133 mutable_.first_page = page_number;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 return false; 172 return false;
171 } 173 }
172 return true; 174 return true;
173 } 175 }
174 176
175 void PrintedDocument::DisconnectSource() { 177 void PrintedDocument::DisconnectSource() {
176 base::AutoLock lock(lock_); 178 base::AutoLock lock(lock_);
177 mutable_.source_ = NULL; 179 mutable_.source_ = NULL;
178 } 180 }
179 181
180 uint32 PrintedDocument::MemoryUsage() const {
181 std::vector< scoped_refptr<PrintedPage> > pages_copy;
182 {
183 base::AutoLock lock(lock_);
184 pages_copy.reserve(mutable_.pages_.size());
185 PrintedPages::const_iterator end = mutable_.pages_.end();
186 for (PrintedPages::const_iterator itr = mutable_.pages_.begin();
187 itr != end; ++itr) {
188 if (itr->second.get()) {
189 pages_copy.push_back(itr->second);
190 }
191 }
192 }
193 uint32 total = 0;
194 for (size_t i = 0; i < pages_copy.size(); ++i) {
195 total += pages_copy[i]->metafile()->GetDataSize();
196 }
197 return total;
198 }
199
200 void PrintedDocument::set_page_count(int max_page) { 182 void PrintedDocument::set_page_count(int max_page) {
201 base::AutoLock lock(lock_); 183 base::AutoLock lock(lock_);
202 DCHECK_EQ(0, mutable_.page_count_); 184 DCHECK_EQ(0, mutable_.page_count_);
203 mutable_.page_count_ = max_page; 185 mutable_.page_count_ = max_page;
204 if (immutable_.settings_.ranges().empty()) { 186 if (immutable_.settings_.ranges().empty()) {
205 mutable_.expected_page_count_ = max_page; 187 mutable_.expected_page_count_ = max_page;
206 } else { 188 } else {
207 // If there is a range, don't bother since expected_page_count_ is already 189 // If there is a range, don't bother since expected_page_count_ is already
208 // initialized. 190 // initialized.
209 DCHECK_NE(mutable_.expected_page_count_, 0); 191 DCHECK_NE(mutable_.expected_page_count_, 0);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 } 264 }
283 265
284 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) 266 #if defined(OS_CHROMEOS) || defined(OS_ANDROID)
285 // This function is not used on aura linux/chromeos or android. 267 // This function is not used on aura linux/chromeos or android.
286 void PrintedDocument::RenderPrintedPage(const PrintedPage& page, 268 void PrintedDocument::RenderPrintedPage(const PrintedPage& page,
287 PrintingContext* context) const { 269 PrintingContext* context) const {
288 } 270 }
289 #endif 271 #endif
290 272
291 } // namespace printing 273 } // namespace printing
OLDNEW
« no previous file with comments | « printing/printed_document.h ('k') | printing/printed_document_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698