OLD | NEW |
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/print_job_manager.h" | 5 #include "chrome/browser/printing/print_job_manager.h" |
6 | 6 |
7 #include "base/file_util.h" | |
8 #include "base/string_util.h" | |
9 #include "chrome/browser/printing/print_job.h" | 7 #include "chrome/browser/printing/print_job.h" |
10 #include "chrome/browser/printing/printer_query.h" | 8 #include "chrome/browser/printing/printer_query.h" |
11 #include "chrome/browser/printing/printed_document.h" | 9 #include "chrome/browser/printing/printed_document.h" |
12 #include "chrome/browser/printing/printed_page.h" | 10 #include "chrome/browser/printing/printed_page.h" |
13 #include "chrome/common/gfx/emf.h" | 11 #include "chrome/common/gfx/emf.h" |
14 #include "chrome/common/notification_service.h" | 12 #include "chrome/common/notification_service.h" |
15 | 13 |
16 namespace printing { | 14 namespace printing { |
17 | 15 |
18 PrintJobManager::PrintJobManager() | 16 PrintJobManager::PrintJobManager() { |
19 : debug_dump_path_() { | |
20 registrar_.Add(this, NotificationType::PRINT_JOB_EVENT, | 17 registrar_.Add(this, NotificationType::PRINT_JOB_EVENT, |
21 NotificationService::AllSources()); | 18 NotificationService::AllSources()); |
22 registrar_.Add(this, NotificationType::PRINTED_DOCUMENT_UPDATED, | |
23 NotificationService::AllSources()); | |
24 } | 19 } |
25 | 20 |
26 PrintJobManager::~PrintJobManager() { | 21 PrintJobManager::~PrintJobManager() { |
27 AutoLock lock(lock_); | 22 AutoLock lock(lock_); |
28 queued_queries_.clear(); | 23 queued_queries_.clear(); |
29 } | 24 } |
30 | 25 |
31 void PrintJobManager::OnQuit() { | 26 void PrintJobManager::OnQuit() { |
32 // Common case, no print job pending. | 27 // Common case, no print job pending. |
33 if (current_jobs_.empty()) | 28 if (current_jobs_.empty()) |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 | 72 |
78 void PrintJobManager::Observe(NotificationType type, | 73 void PrintJobManager::Observe(NotificationType type, |
79 const NotificationSource& source, | 74 const NotificationSource& source, |
80 const NotificationDetails& details) { | 75 const NotificationDetails& details) { |
81 switch (type.value) { | 76 switch (type.value) { |
82 case NotificationType::PRINT_JOB_EVENT: { | 77 case NotificationType::PRINT_JOB_EVENT: { |
83 OnPrintJobEvent(Source<PrintJob>(source).ptr(), | 78 OnPrintJobEvent(Source<PrintJob>(source).ptr(), |
84 *Details<JobEventDetails>(details).ptr()); | 79 *Details<JobEventDetails>(details).ptr()); |
85 break; | 80 break; |
86 } | 81 } |
87 case NotificationType::PRINTED_DOCUMENT_UPDATED: { | |
88 PrintedPage* printed_page = Details<PrintedPage>(details).ptr(); | |
89 if (printed_page) | |
90 OnPrintedDocumentUpdated(*Source<PrintedDocument>(source).ptr(), | |
91 *printed_page); | |
92 break; | |
93 } | |
94 default: { | 82 default: { |
95 NOTREACHED(); | 83 NOTREACHED(); |
96 break; | 84 break; |
97 } | 85 } |
98 } | 86 } |
99 } | 87 } |
100 | 88 |
101 void PrintJobManager::OnPrintJobEvent( | 89 void PrintJobManager::OnPrintJobEvent( |
102 PrintJob* print_job, | 90 PrintJob* print_job, |
103 const JobEventDetails& event_details) { | 91 const JobEventDetails& event_details) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 // Don't care. | 133 // Don't care. |
146 break; | 134 break; |
147 } | 135 } |
148 default: { | 136 default: { |
149 NOTREACHED(); | 137 NOTREACHED(); |
150 break; | 138 break; |
151 } | 139 } |
152 } | 140 } |
153 } | 141 } |
154 | 142 |
155 void PrintJobManager::OnPrintedDocumentUpdated(const PrintedDocument& document, | |
156 const PrintedPage& page) { | |
157 if (debug_dump_path_.empty()) | |
158 return; | |
159 | |
160 std::wstring filename; | |
161 filename += document.date(); | |
162 filename += L"_"; | |
163 filename += document.time(); | |
164 filename += L"_"; | |
165 filename += document.name(); | |
166 filename += L"_"; | |
167 filename += StringPrintf(L"%02d", page.page_number()); | |
168 filename += L"_.emf"; | |
169 file_util::ReplaceIllegalCharacters(&filename, '_'); | |
170 std::wstring path(debug_dump_path_); | |
171 file_util::AppendToPath(&path, filename); | |
172 page.emf()->SaveTo(path); | |
173 } | |
174 | |
175 } // namespace printing | 143 } // namespace printing |
OLD | NEW |