IndexedDB: Protect against use-after-free in ChainedBlobWriter.
[chromium-blink-merge.git] / cc / output / copy_output_request.cc
blobd70bac1bfca245ec6bb2b17e7f8e3c8c3cb56071
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cc/output/copy_output_request.h"
7 #include "base/bind.h"
8 #include "base/callback_helpers.h"
9 #include "base/logging.h"
10 #include "base/trace_event/trace_event.h"
11 #include "cc/output/copy_output_result.h"
12 #include "cc/resources/texture_mailbox.h"
13 #include "third_party/skia/include/core/SkBitmap.h"
15 namespace cc {
17 // static
18 scoped_ptr<CopyOutputRequest> CopyOutputRequest::CreateRelayRequest(
19 const CopyOutputRequest& original_request,
20 const CopyOutputRequestCallback& result_callback) {
21 scoped_ptr<CopyOutputRequest> relay = CreateRequest(result_callback);
22 relay->force_bitmap_result_ = original_request.force_bitmap_result_;
23 relay->has_area_ = original_request.has_area_;
24 relay->area_ = original_request.area_;
25 relay->has_texture_mailbox_ = original_request.has_texture_mailbox_;
26 relay->texture_mailbox_ = original_request.texture_mailbox_;
27 return relay.Pass();
30 CopyOutputRequest::CopyOutputRequest() {}
32 CopyOutputRequest::CopyOutputRequest(
33 bool force_bitmap_result,
34 const CopyOutputRequestCallback& result_callback)
35 : source_(nullptr),
36 force_bitmap_result_(force_bitmap_result),
37 has_area_(false),
38 has_texture_mailbox_(false),
39 result_callback_(result_callback) {
40 DCHECK(!result_callback_.is_null());
41 TRACE_EVENT_ASYNC_BEGIN0("cc", "CopyOutputRequest", this);
44 CopyOutputRequest::~CopyOutputRequest() {
45 if (!result_callback_.is_null())
46 SendResult(CopyOutputResult::CreateEmptyResult().Pass());
49 void CopyOutputRequest::SendResult(scoped_ptr<CopyOutputResult> result) {
50 bool success = !result->IsEmpty();
51 base::ResetAndReturn(&result_callback_).Run(result.Pass());
52 TRACE_EVENT_ASYNC_END1("cc", "CopyOutputRequest", this, "success", success);
55 void CopyOutputRequest::SendEmptyResult() {
56 SendResult(CopyOutputResult::CreateEmptyResult().Pass());
59 void CopyOutputRequest::SendBitmapResult(scoped_ptr<SkBitmap> bitmap) {
60 SendResult(CopyOutputResult::CreateBitmapResult(bitmap.Pass()).Pass());
63 void CopyOutputRequest::SendTextureResult(
64 const gfx::Size& size,
65 const TextureMailbox& texture_mailbox,
66 scoped_ptr<SingleReleaseCallback> release_callback) {
67 DCHECK(texture_mailbox.IsTexture());
68 SendResult(CopyOutputResult::CreateTextureResult(
69 size, texture_mailbox, release_callback.Pass()));
72 void CopyOutputRequest::SetTextureMailbox(
73 const TextureMailbox& texture_mailbox) {
74 DCHECK(!force_bitmap_result_);
75 DCHECK(texture_mailbox.IsTexture());
76 has_texture_mailbox_ = true;
77 texture_mailbox_ = texture_mailbox;
80 } // namespace cc