Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / notifications / message_center_notification_manager_win.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/message_center_notification_manager.h"
6
7 #include "ui/message_center/message_center_tray.h"
8
9 void MessageCenterNotificationManager::DisplayFirstRunBalloon() {
10   // Store for posterity the fact that we've shown the first-run balloon.
11   DCHECK(tray_.get());
12   first_run_pref_.SetValue(true);
13   tray_->DisplayFirstRunBalloon();
14 }
15
16 void MessageCenterNotificationManager::SetFirstRunTimeoutForTest(
17     base::TimeDelta timeout) {
18   first_run_idle_timeout_ = timeout;
19 }
20
21 bool MessageCenterNotificationManager::FirstRunTimerIsActive() const {
22   return first_run_balloon_timer_.IsRunning();
23 }
24
25 void MessageCenterNotificationManager::CheckFirstRunTimer() {
26   // If there is no tray_, we can't display a balloon here anyway.
27   // Also, we only want to display the first run balloon once, so the pref will
28   // store the flag on disk based on whether we ever showed the balloon.
29   DCHECK(tray_.get());
30   if (first_run_pref_.GetValue())
31     return;
32
33   // If there are popups, the message center is visible, or there are no more
34   // notifications, don't continue the timer since it will be annoying or
35   // useless.
36   if (message_center_->HasPopupNotifications() ||
37       message_center_->IsMessageCenterVisible() ||
38       0 == message_center_->NotificationCount()) {
39     first_run_balloon_timer_.Stop();
40     return;
41   }
42
43   // No need to restart the timer if it's already going.
44   if (first_run_balloon_timer_.IsRunning())
45     return;
46
47   first_run_balloon_timer_.Start(
48       FROM_HERE,
49       first_run_idle_timeout_,
50       base::Bind(&MessageCenterNotificationManager::DisplayFirstRunBalloon,
51                  weak_factory_.GetWeakPtr()));
52 }