Commit 4768f51d authored by ckitagawa's avatar ckitagawa Committed by Commit Bot

[Paint Preview] Cleanup failed captures

This CL removes failed captures from disk as they happen. This only
applies at a per-SkPicture level. It also cleans up some recorder
behavior to avoid writing an invalid SkPicture to disk.

Bug: 1084657
Change-Id: Idf479f2be824cddd8e47f9ba2bc32f086a5ff4dd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2211907
Commit-Queue: Calder Kitagawa <ckitagawa@chromium.org>
Reviewed-by: default avatarMehran Mahmoudi <mahmoudi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#771626}
parent bcad4fec
......@@ -6,6 +6,7 @@
#include <utility>
#include "base/files/file_util.h"
#include "base/metrics/histogram_functions.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
......@@ -332,9 +333,23 @@ void PaintPreviewClient::OnPaintPreviewCapturedCallback(
// |status|
MarkFrameAsProcessed(guid, frame_guid);
if (status == mojom::PaintPreviewStatus::kOk)
if (status == mojom::PaintPreviewStatus::kOk) {
status = RecordFrame(guid, frame_guid, is_main_frame, filename,
render_frame_id, std::move(response));
} else {
// If the capture failed then cleanup the file.
base::ThreadPool::PostTask(
FROM_HERE, {base::MayBlock(), base::TaskPriority::BEST_EFFORT},
base::BindOnce(base::IgnoreResult(&base::DeleteFile), filename, false));
// If this is the main frame we should just abort the capture.
if (is_main_frame) {
auto it = all_document_data_.find(guid);
if (it != all_document_data_.end())
OnFinished(guid, &it->second);
}
}
auto it = all_document_data_.find(guid);
if (it == all_document_data_.end())
return;
......
......@@ -18,6 +18,7 @@
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/test_renderer_host.h"
#include "content/public/test/test_utils.h"
#include "mojo/public/cpp/bindings/associated_receiver.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
......@@ -223,6 +224,8 @@ TEST_F(PaintPreviewClientRenderViewHostTest, CaptureFailureMock) {
ASSERT_NE(client, nullptr);
client->CapturePaintPreview(params, main_rfh(), std::move(callback));
loop.Run();
content::RunAllTasksUntilIdle();
EXPECT_TRUE(base::IsDirectoryEmpty(temp_dir_.GetPath()));
}
TEST_F(PaintPreviewClientRenderViewHostTest, RenderFrameDeletedNotCapturing) {
......
......@@ -48,7 +48,7 @@ bool SerializeAsSkPicture(sk_sp<const cc::PaintRecord> record,
auto skp = ToSkPicture(
record, SkRect::MakeWH(dimensions.width(), dimensions.height()), nullptr,
custom_callback);
if (!skp)
if (!skp || skp->cullRect().width() == 0 || skp->cullRect().height() == 0)
return false;
TypefaceSerializationContext typeface_context(tracker->GetTypefaceUsageMap());
......
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