| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/pdf_metafile_skia.h" | 5 #include "printing/pdf_metafile_skia.h" |
| 6 | 6 |
| 7 #include "base/containers/hash_tables.h" | 7 #include "base/containers/hash_tables.h" |
| 8 #include "base/file_descriptor_posix.h" | 8 #include "base/file_descriptor_posix.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 return false; | 121 return false; |
| 122 | 122 |
| 123 SkAutoDataUnref data(data_->pdf_stream_.copyToData()); | 123 SkAutoDataUnref data(data_->pdf_stream_.copyToData()); |
| 124 memcpy(dst_buffer, data->bytes(), dst_buffer_size); | 124 memcpy(dst_buffer, data->bytes(), dst_buffer_size); |
| 125 return true; | 125 return true; |
| 126 } | 126 } |
| 127 | 127 |
| 128 bool PdfMetafileSkia::SaveTo(const base::FilePath& file_path) const { | 128 bool PdfMetafileSkia::SaveTo(const base::FilePath& file_path) const { |
| 129 DCHECK_GT(data_->pdf_stream_.getOffset(), 0U); | 129 DCHECK_GT(data_->pdf_stream_.getOffset(), 0U); |
| 130 SkAutoDataUnref data(data_->pdf_stream_.copyToData()); | 130 SkAutoDataUnref data(data_->pdf_stream_.copyToData()); |
| 131 if (file_util::WriteFile(file_path, | 131 if (base::WriteFile(file_path, |
| 132 reinterpret_cast<const char*>(data->data()), | 132 reinterpret_cast<const char*>(data->data()), |
| 133 GetDataSize()) != static_cast<int>(GetDataSize())) { | 133 GetDataSize()) != static_cast<int>(GetDataSize())) { |
| 134 DLOG(ERROR) << "Failed to save file " << file_path.value().c_str(); | 134 DLOG(ERROR) << "Failed to save file " << file_path.value().c_str(); |
| 135 return false; | 135 return false; |
| 136 } | 136 } |
| 137 return true; | 137 return true; |
| 138 } | 138 } |
| 139 | 139 |
| 140 gfx::Rect PdfMetafileSkia::GetPageBounds(unsigned int page_number) const { | 140 gfx::Rect PdfMetafileSkia::GetPageBounds(unsigned int page_number) const { |
| 141 // TODO(vandebo) add a method to get the page size for a given page to | 141 // TODO(vandebo) add a method to get the page size for a given page to |
| 142 // SkPDFDocument. | 142 // SkPDFDocument. |
| 143 NOTIMPLEMENTED(); | 143 NOTIMPLEMENTED(); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 bool PdfMetafileSkia::SaveToFD(const base::FileDescriptor& fd) const { | 196 bool PdfMetafileSkia::SaveToFD(const base::FileDescriptor& fd) const { |
| 197 DCHECK_GT(data_->pdf_stream_.getOffset(), 0U); | 197 DCHECK_GT(data_->pdf_stream_.getOffset(), 0U); |
| 198 | 198 |
| 199 if (fd.fd < 0) { | 199 if (fd.fd < 0) { |
| 200 DLOG(ERROR) << "Invalid file descriptor!"; | 200 DLOG(ERROR) << "Invalid file descriptor!"; |
| 201 return false; | 201 return false; |
| 202 } | 202 } |
| 203 | 203 |
| 204 bool result = true; | 204 bool result = true; |
| 205 SkAutoDataUnref data(data_->pdf_stream_.copyToData()); | 205 SkAutoDataUnref data(data_->pdf_stream_.copyToData()); |
| 206 if (file_util::WriteFileDescriptor(fd.fd, | 206 if (base::WriteFileDescriptor(fd.fd, |
| 207 reinterpret_cast<const char*>(data->data())
, | 207 reinterpret_cast<const char*>(data->data()), |
| 208 GetDataSize()) != | 208 GetDataSize()) != |
| 209 static_cast<int>(GetDataSize())) { | 209 static_cast<int>(GetDataSize())) { |
| 210 DLOG(ERROR) << "Failed to save file with fd " << fd.fd; | 210 DLOG(ERROR) << "Failed to save file with fd " << fd.fd; |
| 211 result = false; | 211 result = false; |
| 212 } | 212 } |
| 213 | 213 |
| 214 if (fd.auto_close) { | 214 if (fd.auto_close) { |
| 215 if (IGNORE_EINTR(close(fd.fd)) < 0) { | 215 if (IGNORE_EINTR(close(fd.fd)) < 0) { |
| 216 DPLOG(WARNING) << "close"; | 216 DPLOG(WARNING) << "close"; |
| 217 result = false; | 217 result = false; |
| 218 } | 218 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 239 if (data->size() == 0) | 239 if (data->size() == 0) |
| 240 return NULL; | 240 return NULL; |
| 241 | 241 |
| 242 PdfMetafileSkia* metafile = new PdfMetafileSkia; | 242 PdfMetafileSkia* metafile = new PdfMetafileSkia; |
| 243 metafile->InitFromData(data->bytes(), | 243 metafile->InitFromData(data->bytes(), |
| 244 base::checked_cast<uint32>(data->size())); | 244 base::checked_cast<uint32>(data->size())); |
| 245 return metafile; | 245 return metafile; |
| 246 } | 246 } |
| 247 | 247 |
| 248 } // namespace printing | 248 } // namespace printing |
| OLD | NEW |