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

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

Issue 149148: Remove unused notification in print code to simplify before refactoring.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/printed_document.h" 5 #include "chrome/browser/printing/printed_document.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "app/gfx/font.h" 9 #include "app/gfx/font.h"
10 #include "app/gfx/text_elider.h" 10 #include "app/gfx/text_elider.h"
11 #include "app/win_util.h" 11 #include "app/win_util.h"
12 #include "base/file_util.h"
12 #include "base/message_loop.h" 13 #include "base/message_loop.h"
14 #include "base/singleton.h"
15 #include "base/string_util.h"
13 #include "base/time.h" 16 #include "base/time.h"
14 #include "chrome/browser/printing/page_number.h" 17 #include "chrome/browser/printing/page_number.h"
15 #include "chrome/browser/printing/page_overlays.h" 18 #include "chrome/browser/printing/page_overlays.h"
16 #include "chrome/browser/printing/printed_pages_source.h" 19 #include "chrome/browser/printing/printed_pages_source.h"
17 #include "chrome/browser/printing/printed_page.h" 20 #include "chrome/browser/printing/printed_page.h"
18 #include "chrome/common/gfx/emf.h" 21 #include "chrome/common/gfx/emf.h"
19 #include "chrome/common/time_format.h"
20 #include "chrome/common/notification_service.h"
21 #include "printing/units.h" 22 #include "printing/units.h"
22 #include "skia/ext/platform_device.h" 23 #include "skia/ext/platform_device.h"
23 24
24 using base::Time; 25 using base::Time;
25 26
27 namespace {
28
29 struct PrintDebugDumpPath {
30 PrintDebugDumpPath()
31 : enabled(false) {
32 }
33
34 bool enabled;
35 std::wstring debug_dump_path;
36 };
37
38 Singleton<PrintDebugDumpPath> g_debug_dump_info;
39
40 } // namespace
41
26 namespace printing { 42 namespace printing {
27 43
28 PrintedDocument::PrintedDocument(const PrintSettings& settings, 44 PrintedDocument::PrintedDocument(const PrintSettings& settings,
29 PrintedPagesSource* source, 45 PrintedPagesSource* source,
30 int cookie) 46 int cookie)
31 : mutable_(source), 47 : mutable_(source),
32 immutable_(settings, source, cookie) { 48 immutable_(settings, source, cookie) {
33 49
34 // Records the expected page count if a range is setup. 50 // Records the expected page count if a range is setup.
35 if (!settings.ranges.empty()) { 51 if (!settings.ranges.empty()) {
(...skipping 16 matching lines...) Expand all
52 emf, immutable_.settings_.page_setup_pixels().physical_size())); 68 emf, immutable_.settings_.page_setup_pixels().physical_size()));
53 { 69 {
54 AutoLock lock(lock_); 70 AutoLock lock(lock_);
55 mutable_.pages_[page_number] = page; 71 mutable_.pages_[page_number] = page;
56 if (mutable_.shrink_factor == 0) { 72 if (mutable_.shrink_factor == 0) {
57 mutable_.shrink_factor = shrink; 73 mutable_.shrink_factor = shrink;
58 } else { 74 } else {
59 DCHECK_EQ(mutable_.shrink_factor, shrink); 75 DCHECK_EQ(mutable_.shrink_factor, shrink);
60 } 76 }
61 } 77 }
62 NotificationService::current()->Notify( 78 DebugDump(*page);
63 NotificationType::PRINTED_DOCUMENT_UPDATED,
64 Source<PrintedDocument>(this),
65 Details<PrintedPage>(page));
66 } 79 }
67 80
68 bool PrintedDocument::GetPage(int page_number, 81 bool PrintedDocument::GetPage(int page_number,
69 scoped_refptr<PrintedPage>* page) { 82 scoped_refptr<PrintedPage>* page) {
70 AutoLock lock(lock_); 83 AutoLock lock(lock_);
71 PrintedPages::const_iterator itr = mutable_.pages_.find(page_number); 84 PrintedPages::const_iterator itr = mutable_.pages_.find(page_number);
72 if (itr != mutable_.pages_.end()) { 85 if (itr != mutable_.pages_.end()) {
73 if (itr->second.get()) { 86 if (itr->second.get()) {
74 *page = itr->second; 87 *page = itr->second;
75 return true; 88 return true;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 } 201 }
189 } 202 }
190 size_t total = 0; 203 size_t total = 0;
191 for (size_t i = 0; i < pages_copy.size(); ++i) { 204 for (size_t i = 0; i < pages_copy.size(); ++i) {
192 total += pages_copy[i]->emf()->GetDataSize(); 205 total += pages_copy[i]->emf()->GetDataSize();
193 } 206 }
194 return total; 207 return total;
195 } 208 }
196 209
197 void PrintedDocument::set_page_count(int max_page) { 210 void PrintedDocument::set_page_count(int max_page) {
198 { 211 AutoLock lock(lock_);
199 AutoLock lock(lock_); 212 DCHECK_EQ(0, mutable_.page_count_);
200 DCHECK_EQ(0, mutable_.page_count_); 213 mutable_.page_count_ = max_page;
201 mutable_.page_count_ = max_page; 214 if (immutable_.settings_.ranges.empty()) {
202 if (immutable_.settings_.ranges.empty()) { 215 mutable_.expected_page_count_ = max_page;
203 mutable_.expected_page_count_ = max_page; 216 } else {
204 } else { 217 // If there is a range, don't bother since expected_page_count_ is already
205 // If there is a range, don't bother since expected_page_count_ is already 218 // initialized.
206 // initialized. 219 DCHECK_NE(mutable_.expected_page_count_, 0);
207 DCHECK_NE(mutable_.expected_page_count_, 0);
208 }
209 } 220 }
210 NotificationService::current()->Notify(
211 NotificationType::PRINTED_DOCUMENT_UPDATED,
212 Source<PrintedDocument>(this),
213 NotificationService::NoDetails());
214 } 221 }
215 222
216 int PrintedDocument::page_count() const { 223 int PrintedDocument::page_count() const {
217 AutoLock lock(lock_); 224 AutoLock lock(lock_);
218 return mutable_.page_count_; 225 return mutable_.page_count_;
219 } 226 }
220 227
221 int PrintedDocument::expected_page_count() const { 228 int PrintedDocument::expected_page_count() const {
222 AutoLock lock(lock_); 229 AutoLock lock(lock_);
223 return mutable_.expected_page_count_; 230 return mutable_.expected_page_count_;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 bounding.right() + 1, bounding.bottom() + 1); 297 bounding.right() + 1, bounding.bottom() + 1);
291 DCHECK(result == SIMPLEREGION || result == COMPLEXREGION); 298 DCHECK(result == SIMPLEREGION || result == COMPLEXREGION);
292 TextOut(context, 299 TextOut(context,
293 bounding.x(), bounding.y(), 300 bounding.x(), bounding.y(),
294 output.c_str(), 301 output.c_str(),
295 static_cast<int>(output.size())); 302 static_cast<int>(output.size()));
296 int res = RestoreDC(context, saved_state); 303 int res = RestoreDC(context, saved_state);
297 DCHECK_NE(res, 0); 304 DCHECK_NE(res, 0);
298 } 305 }
299 306
307 void PrintedDocument::DebugDump(const PrintedPage& page)
308 {
309 if (!g_debug_dump_info->enabled)
310 return;
311
312 std::wstring filename;
313 filename += date();
314 filename += L"_";
315 filename += time();
316 filename += L"_";
317 filename += name();
318 filename += L"_";
319 filename += StringPrintf(L"%02d", page.page_number());
320 filename += L"_.emf";
321 file_util::ReplaceIllegalCharacters(&filename, '_');
322 std::wstring path(g_debug_dump_info->debug_dump_path);
323 file_util::AppendToPath(&path, filename);
324 page.emf()->SaveTo(path);
325 }
326
327 void PrintedDocument::set_debug_dump_path(const std::wstring& debug_dump_path) {
328 g_debug_dump_info->enabled = !debug_dump_path.empty();
329 g_debug_dump_info->debug_dump_path = debug_dump_path;
330 }
331
332 const std::wstring& PrintedDocument::debug_dump_path() {
333 return g_debug_dump_info->debug_dump_path;
334 }
335
300 PrintedDocument::Mutable::Mutable(PrintedPagesSource* source) 336 PrintedDocument::Mutable::Mutable(PrintedPagesSource* source)
301 : source_(source), 337 : source_(source),
302 expected_page_count_(0), 338 expected_page_count_(0),
303 page_count_(0), 339 page_count_(0),
304 shrink_factor(0) { 340 shrink_factor(0) {
305 } 341 }
306 342
307 PrintedDocument::Immutable::Immutable(const PrintSettings& settings, 343 PrintedDocument::Immutable::Immutable(const PrintSettings& settings,
308 PrintedPagesSource* source, 344 PrintedPagesSource* source,
309 int cookie) 345 int cookie)
(...skipping 10 matching lines...) Expand all
320 date_ = win_util::FormatSystemDate(systemtime, std::wstring()); 356 date_ = win_util::FormatSystemDate(systemtime, std::wstring());
321 time_ = win_util::FormatSystemTime(systemtime, std::wstring()); 357 time_ = win_util::FormatSystemTime(systemtime, std::wstring());
322 #else 358 #else
323 Time now = Time::Now(); 359 Time now = Time::Now();
324 date_ = TimeFormat::ShortDateNumeric(now); 360 date_ = TimeFormat::ShortDateNumeric(now);
325 time_ = TimeFormat::TimeOfDay(now); 361 time_ = TimeFormat::TimeOfDay(now);
326 #endif // WIN32 362 #endif // WIN32
327 } 363 }
328 364
329 } // namespace printing 365 } // namespace printing
OLDNEW
« no previous file with comments | « chrome/browser/printing/printed_document.h ('k') | chrome/browser/printing/win_printing_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698