#include "base/callback_helpers.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
#include "base/message_loop/message_loop_proxy.h"
#include "base/metrics/histogram.h"
#include "base/sequenced_task_runner.h"
#include "base/threading/thread.h"
#include "base/threading/thread_checker.h"
#include "base/time/time.h"
-#include "content/browser/renderer_host/media/video_capture_device_impl.h"
+#include "content/browser/renderer_host/media/content_video_capture_device_core.h"
#include "content/browser/renderer_host/media/video_capture_oracle.h"
#include "content/browser/renderer_host/media/web_contents_capture_util.h"
#include "content/browser/renderer_host/render_widget_host_impl.h"
// this seems disadvantageous.
class WebContentsCaptureMachine
: public VideoCaptureMachine,
- public WebContentsObserver,
- public base::SupportsWeakPtr<WebContentsCaptureMachine> {
+ public WebContentsObserver {
public:
WebContentsCaptureMachine(int render_process_id, int render_view_id);
virtual ~WebContentsCaptureMachine();
// oracle, and initiating captures accordingly.
scoped_ptr<ContentCaptureSubscription> subscription_;
+ // Weak pointer factory used to invalidate callbacks.
+ base::WeakPtrFactory<WebContentsCaptureMachine> weak_ptr_factory_;
+
DISALLOW_COPY_AND_ASSIGN(WebContentsCaptureMachine);
};
int render_view_id)
: initial_render_process_id_(render_process_id),
initial_render_view_id_(render_view_id),
- fullscreen_widget_id_(MSG_ROUTING_NONE) {}
+ fullscreen_widget_id_(MSG_ROUTING_NONE),
+ weak_ptr_factory_(this) {}
WebContentsCaptureMachine::~WebContentsCaptureMachine() {
BrowserThread::PostBlockingPoolTask(
Observe(NULL);
}
+ // Any callback that intend to use render_thread_ will not work after it is
+ // passed.
+ weak_ptr_factory_.InvalidateWeakPtrs();
+
// The render thread cannot be stopped on the UI thread, so post a message
// to the thread pool used for blocking operations.
BrowserThread::PostBlockingPoolTask(
rwh->GetSnapshotFromRenderer(
gfx::Rect(),
base::Bind(&WebContentsCaptureMachine::DidCopyFromBackingStore,
- this->AsWeakPtr(), start_time, target, deliver_frame_cb));
+ weak_ptr_factory_.GetWeakPtr(),
+ start_time, target, deliver_frame_cb));
} else if (view->CanCopyToVideoFrame()) {
view->CopyFromCompositingSurfaceToVideoFrame(
gfx::Rect(view_size),
target,
base::Bind(&WebContentsCaptureMachine::
DidCopyFromCompositingSurfaceToVideoFrame,
- this->AsWeakPtr(), start_time, deliver_frame_cb));
+ weak_ptr_factory_.GetWeakPtr(),
+ start_time, deliver_frame_cb));
} else {
rwh->CopyFromBackingStore(
gfx::Rect(),
fitted_size, // Size here is a request not always honored.
base::Bind(&WebContentsCaptureMachine::DidCopyFromBackingStore,
- this->AsWeakPtr(), start_time, target, deliver_frame_cb));
+ weak_ptr_factory_.GetWeakPtr(),
+ start_time, target, deliver_frame_cb));
}
}
WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents());
if (contents) {
- contents->IncrementCapturerCount();
+ contents->IncrementCapturerCount(oracle_proxy_->GetCaptureSize());
fullscreen_widget_id_ = contents->GetFullscreenWidgetRoutingID();
RenewFrameSubscription();
return true;
return;
subscription_.reset(new ContentCaptureSubscription(*rwh, oracle_proxy_,
- base::Bind(&WebContentsCaptureMachine::Capture, this->AsWeakPtr())));
+ base::Bind(&WebContentsCaptureMachine::Capture,
+ weak_ptr_factory_.GetWeakPtr())));
}
} // namespace
WebContentsVideoCaptureDevice::WebContentsVideoCaptureDevice(
int render_process_id, int render_view_id)
- : impl_(new VideoCaptureDeviceImpl(scoped_ptr<VideoCaptureMachine>(
+ : core_(new ContentVideoCaptureDeviceCore(scoped_ptr<VideoCaptureMachine>(
new WebContentsCaptureMachine(render_process_id, render_view_id)))) {}
WebContentsVideoCaptureDevice::~WebContentsVideoCaptureDevice() {
const media::VideoCaptureParams& params,
scoped_ptr<Client> client) {
DVLOG(1) << "Allocating " << params.requested_format.frame_size.ToString();
- impl_->AllocateAndStart(params, client.Pass());
+ core_->AllocateAndStart(params, client.Pass());
}
void WebContentsVideoCaptureDevice::StopAndDeAllocate() {
- impl_->StopAndDeAllocate();
+ core_->StopAndDeAllocate();
}
} // namespace content