Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Unified Diff: content/browser/devtools/protocol/frame_recorder.cc

Issue 888573002: DevTools: FrameRecorder: add cancelRecordingFrames command (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/devtools/protocol/frame_recorder.cc
diff --git a/content/browser/devtools/protocol/frame_recorder.cc b/content/browser/devtools/protocol/frame_recorder.cc
index 34ea03301d7b5fbcb36ec91f70209bc38e05479b..0628bb49cc4c8bddc2683d46a14d9f4904f1307c 100644
--- a/content/browser/devtools/protocol/frame_recorder.cc
+++ b/content/browser/devtools/protocol/frame_recorder.cc
@@ -23,7 +23,8 @@ namespace {
static int kMaxRecordFrameCount = 180;
-std::string EncodeFrame(const SkBitmap& bitmap) {
+scoped_ptr<EncodedFrame> EncodeFrame(
+ const SkBitmap& bitmap, double timestamp) {
std::vector<unsigned char> data;
SkAutoLockPixels lock_image(bitmap);
bool encoded = gfx::PNGCodec::Encode(
@@ -33,15 +34,17 @@ std::string EncodeFrame(const SkBitmap& bitmap) {
bitmap.width() * bitmap.bytesPerPixel(),
false, std::vector<gfx::PNGCodec::Comment>(), &data);
+ scoped_ptr<EncodedFrame> result(new EncodedFrame(std::string(), timestamp));
+
if (!encoded)
- return std::string();
+ return result.Pass();
std::string base_64_data;
base::Base64Encode(
base::StringPiece(reinterpret_cast<char*>(&data[0]), data.size()),
- &base_64_data);
+ &result->first);
- return base_64_data;
+ return result.Pass();
}
} // namespace
@@ -90,6 +93,16 @@ Response FrameRecorder::StopRecordingFrames(
return Response::OK();
}
+Response FrameRecorder::CancelRecordingFrames() {
+ frame_encoded_callback_.Cancel();
dgozman 2015/01/30 10:06:23 Where do you initialize this field?
eustas 2015/01/30 12:08:16 In StartRecoding... Removed too much during cleanu
+ std::vector<scoped_refptr<devtools::page::RecordedFrame>> no_frames;
+ frames_.swap(no_frames);
+ if (state_ == Encoding)
+ callback_.Run(StopRecordingFramesResponse::Create()->set_frames(frames_));
+ state_ = Ready;
+ return Response::OK();
+}
+
void FrameRecorder::OnSwapCompositorFrame() {
if (!host_ || state_ != Recording)
return;
@@ -120,16 +133,15 @@ void FrameRecorder::FrameCaptured(
base::PostTaskAndReplyWithResult(
base::WorkerPool::GetTaskRunner(true).get(),
FROM_HERE,
- base::Bind(&EncodeFrame, bitmap),
- base::Bind(&FrameRecorder::FrameEncoded, weak_factory_.GetWeakPtr(),
- timestamp.ToDoubleT()));
+ base::Bind(&EncodeFrame, bitmap, timestamp.ToDoubleT()),
+ frame_encoded_callback_.callback());
}
void FrameRecorder::FrameEncoded(
- double timestamp, const std::string& encoded_frame) {
+ const scoped_ptr<EncodedFrame>& encoded_frame) {
frames_.push_back(RecordedFrame::Create()
- ->set_data(encoded_frame)
- ->set_timestamp(timestamp));
+ ->set_data(encoded_frame->first)
+ ->set_timestamp(encoded_frame->second));
MaybeSendResponse();
}

Powered by Google App Engine
This is Rietveld 408576698