| 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 "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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 const PageRange& range = settings.ranges[i]; | 57 const PageRange& range = settings.ranges[i]; |
| 58 mutable_.expected_page_count_ += range.to - range.from + 1; | 58 mutable_.expected_page_count_ += range.to - range.from + 1; |
| 59 } | 59 } |
| 60 } | 60 } |
| 61 } | 61 } |
| 62 | 62 |
| 63 PrintedDocument::~PrintedDocument() { | 63 PrintedDocument::~PrintedDocument() { |
| 64 } | 64 } |
| 65 | 65 |
| 66 void PrintedDocument::SetPage(int page_number, | 66 void PrintedDocument::SetPage(int page_number, |
| 67 NativeMetafile* metafile, | 67 Metafile* metafile, |
| 68 double shrink, | 68 double shrink, |
| 69 const gfx::Size& paper_size, | 69 const gfx::Size& paper_size, |
| 70 const gfx::Rect& page_rect, | 70 const gfx::Rect& page_rect, |
| 71 bool has_visible_overlays) { | 71 bool has_visible_overlays) { |
| 72 // Notice the page_number + 1, the reason is that this is the value that will | 72 // Notice the page_number + 1, the reason is that this is the value that will |
| 73 // be shown. Users dislike 0-based counting. | 73 // be shown. Users dislike 0-based counting. |
| 74 scoped_refptr<PrintedPage> page( | 74 scoped_refptr<PrintedPage> page( |
| 75 new PrintedPage(page_number + 1, | 75 new PrintedPage(page_number + 1, |
| 76 metafile, | 76 metafile, |
| 77 paper_size, | 77 paper_size, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 | 118 |
| 119 for (; page != PageNumber::npos(); ++page) { | 119 for (; page != PageNumber::npos(); ++page) { |
| 120 #if defined(OS_WIN) || defined(OS_MACOSX) | 120 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 121 const bool metafile_must_be_valid = true; | 121 const bool metafile_must_be_valid = true; |
| 122 #elif defined(OS_POSIX) | 122 #elif defined(OS_POSIX) |
| 123 const bool metafile_must_be_valid = (page.ToInt() == mutable_.first_page); | 123 const bool metafile_must_be_valid = (page.ToInt() == mutable_.first_page); |
| 124 #endif | 124 #endif |
| 125 PrintedPages::const_iterator itr = mutable_.pages_.find(page.ToInt()); | 125 PrintedPages::const_iterator itr = mutable_.pages_.find(page.ToInt()); |
| 126 if (itr == mutable_.pages_.end() || !itr->second.get()) | 126 if (itr == mutable_.pages_.end() || !itr->second.get()) |
| 127 return false; | 127 return false; |
| 128 if (metafile_must_be_valid && !itr->second->native_metafile()) | 128 if (metafile_must_be_valid && !itr->second->metafile()) |
| 129 return false; | 129 return false; |
| 130 } | 130 } |
| 131 return true; | 131 return true; |
| 132 } | 132 } |
| 133 | 133 |
| 134 void PrintedDocument::DisconnectSource() { | 134 void PrintedDocument::DisconnectSource() { |
| 135 base::AutoLock lock(lock_); | 135 base::AutoLock lock(lock_); |
| 136 mutable_.source_ = NULL; | 136 mutable_.source_ = NULL; |
| 137 } | 137 } |
| 138 | 138 |
| 139 uint32 PrintedDocument::MemoryUsage() const { | 139 uint32 PrintedDocument::MemoryUsage() const { |
| 140 std::vector< scoped_refptr<PrintedPage> > pages_copy; | 140 std::vector< scoped_refptr<PrintedPage> > pages_copy; |
| 141 { | 141 { |
| 142 base::AutoLock lock(lock_); | 142 base::AutoLock lock(lock_); |
| 143 pages_copy.reserve(mutable_.pages_.size()); | 143 pages_copy.reserve(mutable_.pages_.size()); |
| 144 PrintedPages::const_iterator end = mutable_.pages_.end(); | 144 PrintedPages::const_iterator end = mutable_.pages_.end(); |
| 145 for (PrintedPages::const_iterator itr = mutable_.pages_.begin(); | 145 for (PrintedPages::const_iterator itr = mutable_.pages_.begin(); |
| 146 itr != end; ++itr) { | 146 itr != end; ++itr) { |
| 147 if (itr->second.get()) { | 147 if (itr->second.get()) { |
| 148 pages_copy.push_back(itr->second); | 148 pages_copy.push_back(itr->second); |
| 149 } | 149 } |
| 150 } | 150 } |
| 151 } | 151 } |
| 152 uint32 total = 0; | 152 uint32 total = 0; |
| 153 for (size_t i = 0; i < pages_copy.size(); ++i) { | 153 for (size_t i = 0; i < pages_copy.size(); ++i) { |
| 154 total += pages_copy[i]->native_metafile()->GetDataSize(); | 154 total += pages_copy[i]->metafile()->GetDataSize(); |
| 155 } | 155 } |
| 156 return total; | 156 return total; |
| 157 } | 157 } |
| 158 | 158 |
| 159 void PrintedDocument::set_page_count(int max_page) { | 159 void PrintedDocument::set_page_count(int max_page) { |
| 160 base::AutoLock lock(lock_); | 160 base::AutoLock lock(lock_); |
| 161 DCHECK_EQ(0, mutable_.page_count_); | 161 DCHECK_EQ(0, mutable_.page_count_); |
| 162 mutable_.page_count_ = max_page; | 162 mutable_.page_count_ = max_page; |
| 163 if (immutable_.settings_.ranges.empty()) { | 163 if (immutable_.settings_.ranges.empty()) { |
| 164 mutable_.expected_page_count_ = max_page; | 164 mutable_.expected_page_count_ = max_page; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 string16 filename; | 256 string16 filename; |
| 257 filename += date(); | 257 filename += date(); |
| 258 filename += ASCIIToUTF16("_"); | 258 filename += ASCIIToUTF16("_"); |
| 259 filename += time(); | 259 filename += time(); |
| 260 filename += ASCIIToUTF16("_"); | 260 filename += ASCIIToUTF16("_"); |
| 261 filename += name(); | 261 filename += name(); |
| 262 filename += ASCIIToUTF16("_"); | 262 filename += ASCIIToUTF16("_"); |
| 263 filename += ASCIIToUTF16(StringPrintf("%02d", page.page_number())); | 263 filename += ASCIIToUTF16(StringPrintf("%02d", page.page_number())); |
| 264 #if defined(OS_WIN) | 264 #if defined(OS_WIN) |
| 265 filename += ASCIIToUTF16("_.emf"); | 265 filename += ASCIIToUTF16("_.emf"); |
| 266 page.native_metafile()->SaveTo( | 266 page.metafile()->SaveTo( |
| 267 g_debug_dump_info.Get().debug_dump_path.Append(filename)); | 267 g_debug_dump_info.Get().debug_dump_path.Append(filename)); |
| 268 #else // OS_WIN | 268 #else // OS_WIN |
| 269 filename += ASCIIToUTF16("_.pdf"); | 269 filename += ASCIIToUTF16("_.pdf"); |
| 270 page.native_metafile()->SaveTo( | 270 page.metafile()->SaveTo( |
| 271 g_debug_dump_info.Get().debug_dump_path.Append(UTF16ToUTF8(filename))); | 271 g_debug_dump_info.Get().debug_dump_path.Append(UTF16ToUTF8(filename))); |
| 272 #endif // OS_WIN | 272 #endif // OS_WIN |
| 273 } | 273 } |
| 274 | 274 |
| 275 void PrintedDocument::set_debug_dump_path(const FilePath& debug_dump_path) { | 275 void PrintedDocument::set_debug_dump_path(const FilePath& debug_dump_path) { |
| 276 g_debug_dump_info.Get().enabled = !debug_dump_path.empty(); | 276 g_debug_dump_info.Get().enabled = !debug_dump_path.empty(); |
| 277 g_debug_dump_info.Get().debug_dump_path = debug_dump_path; | 277 g_debug_dump_info.Get().debug_dump_path = debug_dump_path; |
| 278 } | 278 } |
| 279 | 279 |
| 280 const FilePath& PrintedDocument::debug_dump_path() { | 280 const FilePath& PrintedDocument::debug_dump_path() { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 302 name_(source->RenderSourceName()), | 302 name_(source->RenderSourceName()), |
| 303 url_(source->RenderSourceUrl()), | 303 url_(source->RenderSourceUrl()), |
| 304 cookie_(cookie) { | 304 cookie_(cookie) { |
| 305 SetDocumentDate(); | 305 SetDocumentDate(); |
| 306 } | 306 } |
| 307 | 307 |
| 308 PrintedDocument::Immutable::~Immutable() { | 308 PrintedDocument::Immutable::~Immutable() { |
| 309 } | 309 } |
| 310 | 310 |
| 311 } // namespace printing | 311 } // namespace printing |
| OLD | NEW |