Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(421)

Side by Side Diff: content/browser/wake_lock/wake_lock_service_context.cc

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
Patch Set: . Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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(
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 DCHECK(!wake_lock_); 64 DCHECK(!wake_lock_);
64 wake_lock_ = CreatePowerSaveBlocker( 65 wake_lock_ = CreatePowerSaveBlocker(
65 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, 66 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep,
66 PowerSaveBlocker::kReasonOther, "Wake Lock API"); 67 PowerSaveBlocker::kReasonOther, "Wake Lock API");
67 68
68 #if defined(OS_ANDROID) 69 #if defined(OS_ANDROID)
69 // On Android, additionaly associate the blocker with this WebContents. 70 // On Android, additionaly associate the blocker with this WebContents.
70 DCHECK(web_contents()); 71 DCHECK(web_contents());
71 72
72 static_cast<PowerSaveBlockerImpl*>(wake_lock_.get()) 73 static_cast<PowerSaveBlockerImpl*>(wake_lock_.get())
73 ->InitDisplaySleepBlocker(web_contents()); 74 ->InitDisplaySleepBlocker(web_contents()->GetNativeView());
74 #endif 75 #endif
75 } 76 }
76 77
77 void WakeLockServiceContext::RemoveWakeLock() { 78 void WakeLockServiceContext::RemoveWakeLock() {
78 DCHECK(wake_lock_); 79 DCHECK(wake_lock_);
79 wake_lock_.reset(); 80 wake_lock_.reset();
80 } 81 }
81 82
82 void WakeLockServiceContext::UpdateWakeLock() { 83 void WakeLockServiceContext::UpdateWakeLock() {
83 if (!frames_requesting_lock_.empty()) { 84 if (!frames_requesting_lock_.empty()) {
84 if (!wake_lock_) 85 if (!wake_lock_)
85 CreateWakeLock(); 86 CreateWakeLock();
86 } else { 87 } else {
87 if (wake_lock_) 88 if (wake_lock_)
88 RemoveWakeLock(); 89 RemoveWakeLock();
89 } 90 }
90 } 91 }
91 92
92 } // namespace content 93 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698