Skip to content

Commit

Permalink
Fix some nits in PdfMetafileSkia.
Browse files Browse the repository at this point in the history
Change-Id: Iab66904da43d2aaee616f754691e3e0f720637c7
Reviewed-on: https://chromium-review.googlesource.com/826472
Reviewed-by: Wei Li <weili@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#524158}
  • Loading branch information
leizleiz authored and Commit Bot committed Dec 14, 2017
1 parent 9b0c483 commit 662e422
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
21 changes: 9 additions & 12 deletions printing/pdf_metafile_skia.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <vector>

#include "base/files/file.h"
#include "base/memory/ptr_util.h"
#include "base/time/time.h"
#include "cc/paint/paint_record.h"
#include "cc/paint/paint_recorder.h"
Expand Down Expand Up @@ -39,15 +38,14 @@ bool WriteAssetToBuffer(const SkStreamAsset* asset,
// Calling duplicate() keeps original asset state unchanged.
std::unique_ptr<SkStreamAsset> assetCopy(asset->duplicate());
size_t length = assetCopy->getLength();
if (length > size)
return false;
return (length == assetCopy->read(buffer, length));
return length <= size && length == assetCopy->read(buffer, length);
}

} // namespace

namespace printing {

// TODO(thestig): struct members should not have trailing underscore.
struct Page {
Page(SkSize s, sk_sp<cc::PaintRecord> c) : size_(s), content_(std::move(c)) {}
Page(Page&& that) : size_(that.size_), content_(std::move(that.content_)) {}
Expand Down Expand Up @@ -80,6 +78,11 @@ struct PdfMetafileSkiaData {
#endif
};

PdfMetafileSkia::PdfMetafileSkia(SkiaDocumentType type)
: data_(std::make_unique<PdfMetafileSkiaData>()) {
data_->type_ = type;
}

PdfMetafileSkia::~PdfMetafileSkia() = default;

bool PdfMetafileSkia::Init() {
Expand All @@ -91,7 +94,7 @@ bool PdfMetafileSkia::Init() {
// PdfMetafileSkia does.
bool PdfMetafileSkia::InitFromData(const void* src_buffer,
size_t src_buffer_size) {
data_->pdf_data_ = base::MakeUnique<SkMemoryStream>(
data_->pdf_data_ = std::make_unique<SkMemoryStream>(
src_buffer, src_buffer_size, true /* copy_data? */);
return true;
}
Expand Down Expand Up @@ -274,17 +277,11 @@ bool PdfMetafileSkia::SaveTo(base::File* file) const {
return true;
}

PdfMetafileSkia::PdfMetafileSkia(SkiaDocumentType type)
: data_(new PdfMetafileSkiaData) {
data_->type_ = type;
}

std::unique_ptr<PdfMetafileSkia> PdfMetafileSkia::GetMetafileForCurrentPage(
SkiaDocumentType type) {
// If we only ever need the metafile for the last page, should we
// only keep a handle on one PaintRecord?
std::unique_ptr<PdfMetafileSkia> metafile(new PdfMetafileSkia(type));

auto metafile = std::make_unique<PdfMetafileSkia>(type);
if (data_->pages_.size() == 0)
return metafile;

Expand Down
3 changes: 2 additions & 1 deletion printing/pdf_metafile_skia.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ namespace printing {

struct PdfMetafileSkiaData;

// This class uses Skia graphics library to generate a PDF document.
// This class uses Skia graphics library to generate a PDF or MSKP document.
// TODO(thestig): Rename to MetafileSkia.
class PRINTING_EXPORT PdfMetafileSkia : public Metafile {
public:
explicit PdfMetafileSkia(SkiaDocumentType type);
Expand Down

0 comments on commit 662e422

Please sign in to comment.