 Chromium Code Reviews
 Chromium Code Reviews Issue 2003803002:
  Remove dependency of power_save_blocker_android on various content bits  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@power-save-task-runners
    
  
    Issue 2003803002:
  Remove dependency of power_save_blocker_android on various content bits  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@power-save-task-runners| OLD | NEW | 
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "content/browser/wake_lock/wake_lock_service_context.h" | 5 #include "content/browser/wake_lock/wake_lock_service_context.h" | 
| 6 | 6 | 
| 7 #include <utility> | 7 #include <utility> | 
| 8 | 8 | 
| 9 #include "base/bind.h" | 9 #include "base/bind.h" | 
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" | 
| 11 #include "content/browser/power_save_blocker_impl.h" | 11 #include "content/browser/power_save_blocker_impl.h" | 
| 12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" | 
| 13 #include "content/public/browser/power_save_blocker_factory.h" | 13 #include "content/public/browser/power_save_blocker_factory.h" | 
| 14 #include "content/public/browser/render_frame_host.h" | 14 #include "content/public/browser/render_frame_host.h" | 
| 15 #include "content/public/browser/render_process_host.h" | 15 #include "content/public/browser/render_process_host.h" | 
| 16 #include "content/public/browser/web_contents.h" | |
| 16 #include "content/public/common/service_registry.h" | 17 #include "content/public/common/service_registry.h" | 
| 17 | 18 | 
| 18 namespace content { | 19 namespace content { | 
| 19 | 20 | 
| 20 WakeLockServiceContext::WakeLockServiceContext(WebContents* web_contents) | 21 WakeLockServiceContext::WakeLockServiceContext(WebContents* web_contents) | 
| 21 : WebContentsObserver(web_contents), weak_factory_(this) {} | 22 : WebContentsObserver(web_contents), weak_factory_(this) {} | 
| 22 | 23 | 
| 23 WakeLockServiceContext::~WakeLockServiceContext() {} | 24 WakeLockServiceContext::~WakeLockServiceContext() {} | 
| 24 | 25 | 
| 25 void WakeLockServiceContext::CreateService( | 26 void WakeLockServiceContext::CreateService( | 
| 26 int render_process_id, | 27 int render_process_id, | 
| 27 int render_frame_id, | 28 int render_frame_id, | 
| 28 mojo::InterfaceRequest<blink::mojom::WakeLockService> request) { | 29 mojo::InterfaceRequest<blink::mojom::WakeLockService> request) { | 
| 29 new WakeLockServiceImpl(weak_factory_.GetWeakPtr(), render_process_id, | 30 new WakeLockServiceImpl(weak_factory_.GetWeakPtr(), render_process_id, | 
| 30 render_frame_id, std::move(request)); | 31 render_frame_id, std::move(request)); | 
| 31 } | 32 } | 
| 32 | 33 | 
| 33 void WakeLockServiceContext::RenderFrameDeleted( | 34 void WakeLockServiceContext::RenderFrameDeleted( | 
| 34 RenderFrameHost* render_frame_host) { | 35 RenderFrameHost* render_frame_host) { | 
| 35 CancelWakeLock(render_frame_host->GetProcess()->GetID(), | 36 CancelWakeLock(render_frame_host->GetProcess()->GetID(), | 
| 36 render_frame_host->GetRoutingID()); | 37 render_frame_host->GetRoutingID()); | 
| 37 } | 38 } | 
| 38 | 39 | 
| 40 void WakeLockServiceContext::WebContentsDestroyed() { | |
| 41 #if defined(OS_ANDROID) | |
| 42 if (wake_lock_) { | |
| 43 static_cast<PowerSaveBlockerImpl*>(wake_lock_.get()) | |
| 44 ->ClearViewForSleepBlocker(); | |
| 
ncarter (slow)
2016/06/01 22:01:11
Now that there are 2 downcasts, consider making wa
 
ncarter (slow)
2016/06/01 22:02:57
Or don't -- downcasting while assigning a unique_p
 | |
| 45 } | |
| 46 #endif | |
| 47 } | |
| 48 | |
| 39 void WakeLockServiceContext::RequestWakeLock(int render_process_id, | 49 void WakeLockServiceContext::RequestWakeLock(int render_process_id, | 
| 40 int render_frame_id) { | 50 int render_frame_id) { | 
| 41 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 51 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 
| 42 if (!RenderFrameHost::FromID(render_process_id, render_frame_id)) | 52 if (!RenderFrameHost::FromID(render_process_id, render_frame_id)) | 
| 43 return; | 53 return; | 
| 44 | 54 | 
| 45 frames_requesting_lock_.insert( | 55 frames_requesting_lock_.insert( | 
| 46 std::pair<int, int>(render_process_id, render_frame_id)); | 56 std::pair<int, int>(render_process_id, render_frame_id)); | 
| 47 UpdateWakeLock(); | 57 UpdateWakeLock(); | 
| 48 } | 58 } | 
| (...skipping 14 matching lines...) Expand all Loading... | |
| 63 DCHECK(!wake_lock_); | 73 DCHECK(!wake_lock_); | 
| 64 wake_lock_ = CreatePowerSaveBlocker( | 74 wake_lock_ = CreatePowerSaveBlocker( | 
| 65 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, | 75 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, | 
| 66 PowerSaveBlocker::kReasonOther, "Wake Lock API"); | 76 PowerSaveBlocker::kReasonOther, "Wake Lock API"); | 
| 67 | 77 | 
| 68 #if defined(OS_ANDROID) | 78 #if defined(OS_ANDROID) | 
| 69 // On Android, additionaly associate the blocker with this WebContents. | 79 // On Android, additionaly associate the blocker with this WebContents. | 
| 70 DCHECK(web_contents()); | 80 DCHECK(web_contents()); | 
| 71 | 81 | 
| 72 static_cast<PowerSaveBlockerImpl*>(wake_lock_.get()) | 82 static_cast<PowerSaveBlockerImpl*>(wake_lock_.get()) | 
| 73 ->InitDisplaySleepBlocker(web_contents()); | 83 ->InitDisplaySleepBlocker(web_contents()->GetNativeView()); | 
| 74 #endif | 84 #endif | 
| 75 } | 85 } | 
| 76 | 86 | 
| 77 void WakeLockServiceContext::RemoveWakeLock() { | 87 void WakeLockServiceContext::RemoveWakeLock() { | 
| 78 DCHECK(wake_lock_); | 88 DCHECK(wake_lock_); | 
| 79 wake_lock_.reset(); | 89 wake_lock_.reset(); | 
| 80 } | 90 } | 
| 81 | 91 | 
| 82 void WakeLockServiceContext::UpdateWakeLock() { | 92 void WakeLockServiceContext::UpdateWakeLock() { | 
| 83 if (!frames_requesting_lock_.empty()) { | 93 if (!frames_requesting_lock_.empty()) { | 
| 84 if (!wake_lock_) | 94 if (!wake_lock_) | 
| 85 CreateWakeLock(); | 95 CreateWakeLock(); | 
| 86 } else { | 96 } else { | 
| 87 if (wake_lock_) | 97 if (wake_lock_) | 
| 88 RemoveWakeLock(); | 98 RemoveWakeLock(); | 
| 89 } | 99 } | 
| 90 } | 100 } | 
| 91 | 101 | 
| 92 } // namespace content | 102 } // namespace content | 
| OLD | NEW |