Commit d6442a26 authored by Victor Costan's avatar Victor Costan Committed by Commit Bot

AppCache: Clarify ownership transfer in WrappedPickleIOBuffer.

Change-Id: Id77e608825b627ffd389d4a476594592083283e1
Reviewed-on: https://chromium-review.googlesource.com/1189342
Commit-Queue: Joshua Bell <jsbell@chromium.org>
Reviewed-by: default avatarJoshua Bell <jsbell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#586287}
parent 0b602e98
......@@ -31,20 +31,19 @@ namespace {
// Disk cache entry data indices.
enum { kResponseInfoIndex, kResponseContentIndex, kResponseMetadataIndex };
// An IOBuffer that wraps a pickle's data. Ownership of the
// pickle is transfered to the WrappedPickleIOBuffer object.
// An IOBuffer that wraps a pickle's data.
class WrappedPickleIOBuffer : public net::WrappedIOBuffer {
public:
explicit WrappedPickleIOBuffer(const base::Pickle* pickle)
explicit WrappedPickleIOBuffer(std::unique_ptr<const base::Pickle> pickle)
: net::WrappedIOBuffer(reinterpret_cast<const char*>(pickle->data())),
pickle_(pickle) {
DCHECK(pickle->data());
pickle_(std::move(pickle)) {
DCHECK(pickle_->data());
}
private:
~WrappedPickleIOBuffer() override {}
~WrappedPickleIOBuffer() override = default;
std::unique_ptr<const base::Pickle> pickle_;
const std::unique_ptr<const base::Pickle> pickle_;
};
} // anon namespace
......@@ -358,10 +357,11 @@ void AppCacheResponseWriter::ContinueWriteInfo() {
const bool kSkipTransientHeaders = true;
const bool kTruncated = false;
base::Pickle* pickle = new base::Pickle;
info_buffer_->http_info->Persist(pickle, kSkipTransientHeaders, kTruncated);
std::unique_ptr<base::Pickle> pickle = std::make_unique<base::Pickle>();
info_buffer_->http_info->Persist(pickle.get(), kSkipTransientHeaders,
kTruncated);
write_amount_ = static_cast<int>(pickle->size());
buffer_ = new WrappedPickleIOBuffer(pickle); // takes ownership of pickle
buffer_ = base::MakeRefCounted<WrappedPickleIOBuffer>(std::move(pickle));
WriteRaw(kResponseInfoIndex, 0, buffer_.get(), write_amount_);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment