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 "chrome/browser/printing/print_dialog_gtk.h" | 5 #include "chrome/browser/printing/print_dialog_gtk.h" |
6 | 6 |
7 #include <fcntl.h> | 7 #include <fcntl.h> |
8 #include <gtk/gtkpagesetupunixdialog.h> | 8 #include <gtk/gtkpagesetupunixdialog.h> |
9 #include <gtk/gtkprintjob.h> | 9 #include <gtk/gtkprintjob.h> |
10 #include <sys/stat.h> | 10 #include <sys/stat.h> |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 void PrintDialogGtk::SaveDocumentToDisk(const NativeMetafile* metafile, | 149 void PrintDialogGtk::SaveDocumentToDisk(const NativeMetafile* metafile, |
150 const string16& document_name) { | 150 const string16& document_name) { |
151 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 151 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
152 | 152 |
153 bool error = false; | 153 bool error = false; |
154 if (!file_util::CreateTemporaryFile(&path_to_pdf_)) { | 154 if (!file_util::CreateTemporaryFile(&path_to_pdf_)) { |
155 LOG(ERROR) << "Creating temporary file failed"; | 155 LOG(ERROR) << "Creating temporary file failed"; |
156 error = true; | 156 error = true; |
157 } | 157 } |
158 | 158 |
159 if (!error) { | 159 if (!error && !metafile->SaveTo(path_to_pdf_)) { |
160 base::FileDescriptor temp_file_fd; | 160 LOG(ERROR) << "Saving metafile failed"; |
161 temp_file_fd.fd = open(path_to_pdf_.value().c_str(), O_WRONLY); | 161 file_util::Delete(path_to_pdf_, false); |
162 temp_file_fd.auto_close = true; | 162 error = true; |
163 if (!metafile->SaveTo(temp_file_fd)) { | |
164 LOG(ERROR) << "Saving metafile failed"; | |
165 file_util::Delete(path_to_pdf_, false); | |
166 error = true; | |
167 } | |
168 } | 163 } |
169 | 164 |
170 // Done saving, let PrintDialogGtk::PrintDocument() continue. | 165 // Done saving, let PrintDialogGtk::PrintDocument() continue. |
171 save_document_event_->Signal(); | 166 save_document_event_->Signal(); |
172 | 167 |
173 if (error) { | 168 if (error) { |
174 Release(); | 169 Release(); |
175 } else { | 170 } else { |
176 // No errors, continue printing. | 171 // No errors, continue printing. |
177 BrowserThread::PostTask( | 172 BrowserThread::PostTask( |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 NULL); | 207 NULL); |
213 // Printing finished. | 208 // Printing finished. |
214 Release(); | 209 Release(); |
215 } | 210 } |
216 | 211 |
217 void PrintDialogGtk::set_save_document_event(base::WaitableEvent* event) { | 212 void PrintDialogGtk::set_save_document_event(base::WaitableEvent* event) { |
218 DCHECK(event); | 213 DCHECK(event); |
219 DCHECK(!save_document_event_); | 214 DCHECK(!save_document_event_); |
220 save_document_event_ = event; | 215 save_document_event_ = event; |
221 } | 216 } |
OLD | NEW |