| Index: content/browser/wake_lock/wake_lock_manager.cc
|
| diff --git a/content/browser/wake_lock/wake_lock_manager.cc b/content/browser/wake_lock/wake_lock_manager.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..e05e1677a706aefdb2a11c94da5f262a06a25f01
|
| --- /dev/null
|
| +++ b/content/browser/wake_lock/wake_lock_manager.cc
|
| @@ -0,0 +1,86 @@
|
| +// Copyright (c) 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "content/browser/wake_lock/wake_lock_manager.h"
|
| +
|
| +#include "content/browser/wake_lock/lock.h"
|
| +#include "content/browser/wake_lock/wake_lock_web_contents_observer.h"
|
| +#include "content/public/browser/render_view_host.h"
|
| +#include "content/public/browser/web_contents.h"
|
| +
|
| +namespace content {
|
| +
|
| +// static
|
| +WakeLockManager* WakeLockManager::GetInstance() {
|
| + return Singleton<WakeLockManager>::get();
|
| +}
|
| +
|
| +WakeLockManager::WakeLockManager() {
|
| +}
|
| +
|
| +WakeLockManager::~WakeLockManager() {
|
| + for (std::set<Lock*>::iterator it = locks_.begin();
|
| + it != locks_.end();
|
| + ++it)
|
| + (*it)->UnlockResource();
|
| +}
|
| +
|
| +void WakeLockManager::createScreenLock(
|
| + int render_process_id, int routed_id) {
|
| + if (!getLock(render_process_id, routed_id)) {
|
| + Lock* lock = new Lock(render_process_id, routed_id);
|
| + locks_.insert(lock);
|
| + }
|
| +}
|
| +
|
| +bool WakeLockManager::releaseScreenLock(
|
| + int render_process_id, int routed_id) {
|
| + if (Lock* lock = getLock(render_process_id, routed_id)) {
|
| + locks_.erase(lock);
|
| + delete lock;
|
| + return true;
|
| + }
|
| + return false;
|
| +}
|
| +
|
| +Lock* WakeLockManager::getLock(
|
| + int render_process_id, int routed_id) {
|
| + for (std::set<Lock*>::iterator it = locks_.begin();
|
| + it != locks_.end();
|
| + ++it) {
|
| + Lock* lock = *it;
|
| + if (lock->GetRenderProcessId() == render_process_id &&
|
| + lock->GetRoutedId() == routed_id)
|
| + return lock;
|
| + }
|
| + return NULL;
|
| +}
|
| +
|
| +void WakeLockManager::tabWasShown(int render_process_id, int routed_id) {
|
| + tabChangeVisibility(render_process_id, routed_id, true);
|
| +}
|
| +
|
| +void WakeLockManager::tabWasHidden(int render_process_id, int routed_id) {
|
| + tabChangeVisibility(render_process_id, routed_id, false);
|
| +}
|
| +
|
| +void WakeLockManager::tabChangeVisibility(
|
| + int render_process_id, int routed_id, bool visible) {
|
| + if (Lock* lock = getLock(render_process_id, routed_id)) {
|
| + if (visible)
|
| + lock->ForceLockResource();
|
| + else
|
| + lock->ForceUnlockResource();
|
| + }
|
| +}
|
| +
|
| +void WakeLockManager::createWebContentsObserver(
|
| + int render_process_id, int routed_id) {
|
| + RenderViewHost* view = RenderViewHost::FromID(
|
| + render_process_id, routed_id);
|
| + WebContents* web_contents = WebContents::FromRenderViewHost(view);
|
| + // TODO(redchenko): check, save and delete it
|
| + new WakeLockWebContentsObserver(web_contents);
|
| +}
|
| +}
|
|
|