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

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..44e4f78ee9a7b33192658a3311f5fa2bb4947b16 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
@@ -72,6 +75,8 @@ Response FrameRecorder::StartRecordingFrames(int max_frame_count) {
state_ = Recording;
max_frame_count_ = max_frame_count;
captured_frames_count_ = 0;
+ frame_encoded_callback_.Reset(base::Bind(
dgozman 2015/01/30 12:29:12 Please reset this callback to nothing in stop and
eustas 2015/01/30 12:43:23 .Cancel() actually resets the callback. We should
+ &FrameRecorder::FrameEncoded, weak_factory_.GetWeakPtr()));
last_captured_frame_timestamp_ = base::Time();
std::vector<scoped_refptr<devtools::page::RecordedFrame>> frames;
frames.reserve(max_frame_count);
@@ -90,6 +95,16 @@ Response FrameRecorder::StopRecordingFrames(
return Response::OK();
}
+Response FrameRecorder::CancelRecordingFrames() {
+ frame_encoded_callback_.Cancel();
+ 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;
@@ -113,23 +128,24 @@ void FrameRecorder::FrameCaptured(
inflight_requests_count_--;
base::Time timestamp = last_captured_frame_timestamp_;
last_captured_frame_timestamp_ = base::Time::Now();
- if (timestamp.is_null() || response != READBACK_SUCCESS)
+ if (timestamp.is_null() || response != READBACK_SUCCESS) {
+ MaybeSendResponse();
dgozman 2015/01/30 12:29:11 What's the scenario where this call is required?
eustas 2015/01/30 12:43:23 As you see - we drop the first frame in a sequence
return;
+ }
captured_frames_count_++;
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();
}
« no previous file with comments | « content/browser/devtools/protocol/frame_recorder.h ('k') | content/browser/devtools/protocol/page_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698