| Index: content/browser/wake_lock/wake_lock_service_context.cc
|
| diff --git a/content/browser/wake_lock/wake_lock_service_context.cc b/content/browser/wake_lock/wake_lock_service_context.cc
|
| index 7a706e8582da83c58305cda7e8ceb5517e97495a..47aeae42e85e3f3cf46fe39f2e309b3dfa0881a0 100644
|
| --- a/content/browser/wake_lock/wake_lock_service_context.cc
|
| +++ b/content/browser/wake_lock/wake_lock_service_context.cc
|
| @@ -13,6 +13,7 @@
|
| #include "content/public/browser/power_save_blocker_factory.h"
|
| #include "content/public/browser/render_frame_host.h"
|
| #include "content/public/browser/render_process_host.h"
|
| +#include "content/public/browser/web_contents.h"
|
| #include "content/public/common/service_registry.h"
|
|
|
| namespace content {
|
| @@ -36,6 +37,13 @@ void WakeLockServiceContext::RenderFrameDeleted(
|
| render_frame_host->GetRoutingID());
|
| }
|
|
|
| +void WakeLockServiceContext::WebContentsDestroyed() {
|
| +#if defined(OS_ANDROID)
|
| + if (view_weak_factory_)
|
| + view_weak_factory_->InvalidateWeakPtrs();
|
| +#endif
|
| +}
|
| +
|
| void WakeLockServiceContext::RequestWakeLock(int render_process_id,
|
| int render_frame_id) {
|
| DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| @@ -69,8 +77,12 @@ void WakeLockServiceContext::CreateWakeLock() {
|
| // On Android, additionaly associate the blocker with this WebContents.
|
| DCHECK(web_contents());
|
|
|
| - static_cast<PowerSaveBlockerImpl*>(wake_lock_.get())
|
| - ->InitDisplaySleepBlocker(web_contents());
|
| + if (web_contents()->GetNativeView()) {
|
| + view_weak_factory_.reset(new base::WeakPtrFactory<ui::ViewAndroid>(
|
| + web_contents()->GetNativeView()));
|
| + static_cast<PowerSaveBlockerImpl*>(wake_lock_.get())
|
| + ->InitDisplaySleepBlocker(view_weak_factory_->GetWeakPtr());
|
| + }
|
| #endif
|
| }
|
|
|
|
|