Index: content/browser/renderer_host/render_view_host_impl.cc |
diff --git a/content/browser/renderer_host/render_view_host_impl.cc b/content/browser/renderer_host/render_view_host_impl.cc |
index 05d75abfecc1fe70379e70b9f9c34141d9f32a54..8e67d5c32a68018d9efc325aa570742dfad09bf3 100644 |
--- a/content/browser/renderer_host/render_view_host_impl.cc |
+++ b/content/browser/renderer_host/render_view_host_impl.cc |
@@ -212,6 +212,7 @@ RenderViewHostImpl::RenderViewHostImpl( |
sudden_termination_allowed_(false), |
render_view_termination_status_(base::TERMINATION_STATUS_STILL_RUNNING), |
virtual_keyboard_requested_(false), |
+ copy_requests_(0), |
weak_factory_(this) { |
DCHECK(instance_.get()); |
CHECK(delegate_); // http://crbug.com/82827 |
@@ -708,7 +709,8 @@ void RenderViewHostImpl::OnSwappedOut(bool timed_out) { |
break; |
case STATE_PENDING_SHUTDOWN: |
DCHECK(!pending_shutdown_on_swap_out_.is_null()); |
- pending_shutdown_on_swap_out_.Run(); |
+ if (copy_requests_ == 0) |
+ pending_shutdown_on_swap_out_.Run(); |
break; |
default: |
NOTREACHED(); |
@@ -717,11 +719,14 @@ void RenderViewHostImpl::OnSwappedOut(bool timed_out) { |
void RenderViewHostImpl::WasSwappedOut( |
const base::Closure& pending_delete_on_swap_out) { |
- Send(new ViewMsg_WasSwappedOut(GetRoutingID())); |
+ if (copy_requests_ == 0) |
+ Send(new ViewMsg_WasSwappedOut(GetRoutingID())); |
if (rvh_state_ == STATE_WAITING_FOR_UNLOAD_ACK) { |
SetState(STATE_PENDING_SWAP_OUT); |
- if (!instance_->active_view_count()) |
+ if (!instance_->active_view_count() || |
+ (instance_->active_view_count() - copy_requests_) == 0) { |
SetPendingShutdown(pending_delete_on_swap_out); |
+ } |
} else if (rvh_state_ == STATE_WAITING_FOR_COMMIT) { |
SetState(STATE_SWAPPED_OUT); |
} else if (rvh_state_ == STATE_DEFAULT) { |
@@ -1794,6 +1799,44 @@ void RenderViewHostImpl::ClearFocusedElement() { |
Send(new ViewMsg_ClearFocusedElement(GetRoutingID())); |
} |
+void RenderViewHostImpl::CopyFromBackingStoreCallback( |
+ const base::Callback<void(bool, const SkBitmap&)>& callback, |
+ bool success, |
+ const SkBitmap& bitmap) { |
+ --copy_requests_; |
+ LOG(ERROR) << "Done with a request: " << copy_requests_; |
+ callback.Run(success, bitmap); |
+ if (copy_requests_ == 0) { |
+ if (!IsRVHStateActive(rvh_state_)) { |
+ Send(new ViewMsg_WasSwappedOut(GetRoutingID())); |
+ instance_->decrement_active_view_count(); |
+ } |
+ |
+ if (rvh_state_ == STATE_PENDING_SHUTDOWN) { |
+ DCHECK(!pending_shutdown_on_swap_out_.is_null()); |
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
+ pending_shutdown_on_swap_out_); |
+ } |
+ } |
+} |
+ |
+void RenderViewHostImpl::CopyFromBackingStore( |
+ const gfx::Rect& src_rect, |
+ const gfx::Size& accelerated_dst_size, |
+ const base::Callback<void(bool, const SkBitmap&)>& callback) { |
+ DCHECK(IsRVHStateActive(rvh_state_)); |
+ if (!IsRVHStateActive(rvh_state_)) { |
+ callback.Run(false, SkBitmap()); |
+ return; |
+ } |
+ ++copy_requests_; |
+ LOG(ERROR) << "Starting a request: " << copy_requests_; |
+ RenderWidgetHostImpl::CopyFromBackingStore(src_rect, accelerated_dst_size, |
+ base::Bind(&RenderViewHostImpl::CopyFromBackingStoreCallback, |
+ weak_factory_.GetWeakPtr(), |
+ callback)); |
+} |
+ |
void RenderViewHostImpl::Zoom(PageZoom zoom) { |
Send(new ViewMsg_Zoom(GetRoutingID(), zoom)); |
} |
@@ -1980,7 +2023,8 @@ void RenderViewHostImpl::SetState(RenderViewHostImplState rvh_state) { |
// swapped out status of this RenderView gets flipped to/from live. |
if (!IsRVHStateActive(rvh_state_) && IsRVHStateActive(rvh_state)) |
instance_->increment_active_view_count(); |
- else if (IsRVHStateActive(rvh_state_) && !IsRVHStateActive(rvh_state)) |
+ else if (IsRVHStateActive(rvh_state_) && !IsRVHStateActive(rvh_state) && |
+ copy_requests_ == 0) |
instance_->decrement_active_view_count(); |
// Whenever we change the RVH state to and from live or swapped out state, we |