- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / notifications / screen_lock_notification_blocker.cc
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/notifications/screen_lock_notification_blocker.h"
6
7 #include "base/time/time.h"
8 #include "chrome/browser/idle.h"
9
10 namespace {
11 const int kUserStatePollingIntervalSeconds = 1;
12 }
13
14 ScreenLockNotificationBlocker::ScreenLockNotificationBlocker(
15     message_center::MessageCenter* message_center)
16     : NotificationBlocker(message_center),
17       is_locked_(false) {
18 }
19
20 ScreenLockNotificationBlocker::~ScreenLockNotificationBlocker() {
21 }
22
23 void ScreenLockNotificationBlocker::CheckState() {
24   bool was_locked = is_locked_;
25   is_locked_ = CheckIdleStateIsLocked();
26   if (is_locked_ != was_locked) {
27     FOR_EACH_OBSERVER(
28         NotificationBlocker::Observer, observers(), OnBlockingStateChanged());
29   }
30
31   if (is_locked_) {
32     timer_.Start(FROM_HERE,
33                  base::TimeDelta::FromSeconds(kUserStatePollingIntervalSeconds),
34                  this,
35                  &ScreenLockNotificationBlocker::CheckState);
36   }
37 }
38
39 bool ScreenLockNotificationBlocker::ShouldShowNotificationAsPopup(
40     const message_center::NotifierId& notifier_id) const {
41   return !is_locked_;
42 }