| 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_factory.h" | |
| 12 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
| 13 #include "content/public/browser/render_frame_host.h" | 12 #include "content/public/browser/render_frame_host.h" |
| 14 #include "content/public/browser/render_process_host.h" | 13 #include "content/public/browser/render_process_host.h" |
| 15 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
| 16 #include "content/public/common/service_registry.h" | 15 #include "content/public/common/service_registry.h" |
| 16 #include "device/power_save_blocker/power_save_blocker.h" |
| 17 #include "device/power_save_blocker/power_save_blocker_impl.h" | 17 #include "device/power_save_blocker/power_save_blocker_impl.h" |
| 18 | 18 |
| 19 namespace content { | 19 namespace content { |
| 20 | 20 |
| 21 WakeLockServiceContext::WakeLockServiceContext(WebContents* web_contents) | 21 WakeLockServiceContext::WakeLockServiceContext(WebContents* web_contents) |
| 22 : WebContentsObserver(web_contents), weak_factory_(this) {} | 22 : WebContentsObserver(web_contents), weak_factory_(this) {} |
| 23 | 23 |
| 24 WakeLockServiceContext::~WakeLockServiceContext() {} | 24 WakeLockServiceContext::~WakeLockServiceContext() {} |
| 25 | 25 |
| 26 void WakeLockServiceContext::CreateService( | 26 void WakeLockServiceContext::CreateService( |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 std::pair<int, int>(render_process_id, render_frame_id)); | 61 std::pair<int, int>(render_process_id, render_frame_id)); |
| 62 UpdateWakeLock(); | 62 UpdateWakeLock(); |
| 63 } | 63 } |
| 64 | 64 |
| 65 bool WakeLockServiceContext::HasWakeLockForTests() const { | 65 bool WakeLockServiceContext::HasWakeLockForTests() const { |
| 66 return !!wake_lock_; | 66 return !!wake_lock_; |
| 67 } | 67 } |
| 68 | 68 |
| 69 void WakeLockServiceContext::CreateWakeLock() { | 69 void WakeLockServiceContext::CreateWakeLock() { |
| 70 DCHECK(!wake_lock_); | 70 DCHECK(!wake_lock_); |
| 71 wake_lock_ = CreatePowerSaveBlocker( | 71 wake_lock_ = device::PowerSaveBlocker::CreateWithTaskRunners( |
| 72 device::PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, | 72 device::PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, |
| 73 device::PowerSaveBlocker::kReasonOther, "Wake Lock API"); | 73 device::PowerSaveBlocker::kReasonOther, "Wake Lock API", |
| 74 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), |
| 75 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); |
| 74 | 76 |
| 75 #if defined(OS_ANDROID) | 77 #if defined(OS_ANDROID) |
| 76 // On Android, additionaly associate the blocker with this WebContents. | 78 // On Android, additionaly associate the blocker with this WebContents. |
| 77 DCHECK(web_contents()); | 79 DCHECK(web_contents()); |
| 78 | 80 |
| 79 if (web_contents()->GetNativeView()) { | 81 if (web_contents()->GetNativeView()) { |
| 80 view_weak_factory_.reset(new base::WeakPtrFactory<ui::ViewAndroid>( | 82 view_weak_factory_.reset(new base::WeakPtrFactory<ui::ViewAndroid>( |
| 81 web_contents()->GetNativeView())); | 83 web_contents()->GetNativeView())); |
| 82 static_cast<device::PowerSaveBlockerImpl*>(wake_lock_.get()) | 84 static_cast<device::PowerSaveBlockerImpl*>(wake_lock_.get()) |
| 83 ->InitDisplaySleepBlocker(view_weak_factory_->GetWeakPtr()); | 85 ->InitDisplaySleepBlocker(view_weak_factory_->GetWeakPtr()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 94 if (!frames_requesting_lock_.empty()) { | 96 if (!frames_requesting_lock_.empty()) { |
| 95 if (!wake_lock_) | 97 if (!wake_lock_) |
| 96 CreateWakeLock(); | 98 CreateWakeLock(); |
| 97 } else { | 99 } else { |
| 98 if (wake_lock_) | 100 if (wake_lock_) |
| 99 RemoveWakeLock(); | 101 RemoveWakeLock(); |
| 100 } | 102 } |
| 101 } | 103 } |
| 102 | 104 |
| 103 } // namespace content | 105 } // namespace content |
| OLD | NEW |