summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/views/critical_notification_bubble_view.h
blob: 2b6b4d13de944b601935188f28770d86d55c7a42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright (c) 2012 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.

#ifndef CHROME_BROWSER_UI_VIEWS_CRITICAL_NOTIFICATION_BUBBLE_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_CRITICAL_NOTIFICATION_BUBBLE_VIEW_H_

#include "base/timer.h"
#include "ui/views/bubble/bubble_delegate.h"
#include "ui/views/controls/button/button.h"

namespace ui {
class Accelerator;
}

namespace views {
class Label;
class NativeTextButton;
}

class CriticalNotificationBubbleView : public views::BubbleDelegateView,
                                       public views::ButtonListener {
 public:
  explicit CriticalNotificationBubbleView(views::View* anchor_view);
  virtual ~CriticalNotificationBubbleView();

  // views::ButtonListener overrides:
  virtual void ButtonPressed(views::Button* sender,
                             const ui::Event& event) OVERRIDE;

  // views::WidgetDelegate overrides:
  virtual void WindowClosing() OVERRIDE;

  // views::View overrides:
  virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
  virtual void ViewHierarchyChanged(
      bool is_add, View* parent, View* child) OVERRIDE;

 protected:
  // views::BubbleDelegateView overrides:
  virtual bool AcceleratorPressed(
      const ui::Accelerator& accelerator) OVERRIDE;
  virtual void Init() OVERRIDE;

 private:
  // Helper function to calculate the remaining time (in seconds) until
  // spontaneous reboot.
  int GetRemainingTime();

  // Helper function to set the headline for the bubble.
  void UpdateBubbleHeadline(int seconds);

  // Called when the timer fires each time the clock ticks.
  void OnCountdown();

  // The headline and buttons on the bubble.
  views::Label* headline_;
  views::NativeTextButton* restart_button_;
  views::NativeTextButton* dismiss_button_;

  // A timer to refresh the bubble to show new countdown value.
  base::RepeatingTimer<CriticalNotificationBubbleView> refresh_timer_;

  // When the bubble was created.
  base::Time bubble_created_;

  DISALLOW_COPY_AND_ASSIGN(CriticalNotificationBubbleView);
};

#endif  // CHROME_BROWSER_UI_VIEWS_CRITICAL_NOTIFICATION_BUBBLE_VIEW_H_