| 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/file_descriptor_posix.h" | 7 #include "base/file_descriptor_posix.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/hash_tables.h" | 9 #include "base/hash_tables.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 bool PdfMetafileSkia::GetData(void* dst_buffer, | 117 bool PdfMetafileSkia::GetData(void* dst_buffer, |
| 118 uint32 dst_buffer_size) const { | 118 uint32 dst_buffer_size) const { |
| 119 if (dst_buffer_size < GetDataSize()) | 119 if (dst_buffer_size < GetDataSize()) |
| 120 return false; | 120 return false; |
| 121 | 121 |
| 122 SkAutoDataUnref data(data_->pdf_stream_.copyToData()); | 122 SkAutoDataUnref data(data_->pdf_stream_.copyToData()); |
| 123 memcpy(dst_buffer, data->bytes(), dst_buffer_size); | 123 memcpy(dst_buffer, data->bytes(), dst_buffer_size); |
| 124 return true; | 124 return true; |
| 125 } | 125 } |
| 126 | 126 |
| 127 bool PdfMetafileSkia::SaveTo(const FilePath& file_path) const { | 127 bool PdfMetafileSkia::SaveTo(const base::FilePath& file_path) const { |
| 128 DCHECK_GT(data_->pdf_stream_.getOffset(), 0U); | 128 DCHECK_GT(data_->pdf_stream_.getOffset(), 0U); |
| 129 SkAutoDataUnref data(data_->pdf_stream_.copyToData()); | 129 SkAutoDataUnref data(data_->pdf_stream_.copyToData()); |
| 130 if (file_util::WriteFile(file_path, | 130 if (file_util::WriteFile(file_path, |
| 131 reinterpret_cast<const char*>(data->data()), | 131 reinterpret_cast<const char*>(data->data()), |
| 132 GetDataSize()) != static_cast<int>(GetDataSize())) { | 132 GetDataSize()) != static_cast<int>(GetDataSize())) { |
| 133 DLOG(ERROR) << "Failed to save file " << file_path.value().c_str(); | 133 DLOG(ERROR) << "Failed to save file " << file_path.value().c_str(); |
| 134 return false; | 134 return false; |
| 135 } | 135 } |
| 136 return true; | 136 return true; |
| 137 } | 137 } |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 if (data->size() == 0) | 238 if (data->size() == 0) |
| 239 return NULL; | 239 return NULL; |
| 240 | 240 |
| 241 PdfMetafileSkia* metafile = new PdfMetafileSkia; | 241 PdfMetafileSkia* metafile = new PdfMetafileSkia; |
| 242 metafile->InitFromData(data->bytes(), | 242 metafile->InitFromData(data->bytes(), |
| 243 base::checked_numeric_cast<uint32>(data->size())); | 243 base::checked_numeric_cast<uint32>(data->size())); |
| 244 return metafile; | 244 return metafile; |
| 245 } | 245 } |
| 246 | 246 |
| 247 } // namespace printing | 247 } // namespace printing |
| OLD | NEW |