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