summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/ui/idle_logout_dialog_view.h
blob: da6f4d92d817b97c365d8c729c5e1739118335f7 (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// 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_CHROMEOS_UI_IDLE_LOGOUT_DIALOG_VIEW_H_
#define CHROME_BROWSER_CHROMEOS_UI_IDLE_LOGOUT_DIALOG_VIEW_H_

#include "base/gtest_prod_util.h"
#include "base/memory/weak_ptr.h"
#include "base/timer/timer.h"
#include "ui/views/window/dialog_delegate.h"

namespace base {
class TimeDelta;
}
namespace views {
class Label;
}

namespace chromeos {

class IdleLogoutDialogView;
class KioskModeSettings;

// A class that holds the settings for IdleLogoutDialogView; this class
// can be overridden with a mock for testing.
class IdleLogoutSettingsProvider {
 public:
  IdleLogoutSettingsProvider();
  virtual ~IdleLogoutSettingsProvider();

  virtual base::TimeDelta GetCountdownUpdateInterval();
  virtual KioskModeSettings* GetKioskModeSettings();
  virtual void LogoutCurrentUser(IdleLogoutDialogView* dialog);

 private:
  DISALLOW_COPY_AND_ASSIGN(IdleLogoutSettingsProvider);
};

// A class to show the logout on idle dialog if the machine is in retail mode.
class IdleLogoutDialogView : public views::DialogDelegateView {
 public:
  static void ShowDialog();
  static void CloseDialog();

  // views::DialogDelegateView:
  virtual int GetDialogButtons() const OVERRIDE;
  virtual ui::ModalType GetModalType() const OVERRIDE;
  virtual base::string16 GetWindowTitle() const OVERRIDE;
  virtual bool Close() OVERRIDE;

 private:
  friend class MockIdleLogoutSettingsProvider;
  friend class IdleLogoutDialogViewTest;
  FRIEND_TEST_ALL_PREFIXES(IdleLogoutDialogViewTest, ShowDialogAndCloseView);
  FRIEND_TEST_ALL_PREFIXES(IdleLogoutDialogViewTest,
                           ShowDialogAndCloseViewClose);

  IdleLogoutDialogView();
  virtual ~IdleLogoutDialogView();

  // Adds the labels and adds them to the layout.
  void InitAndShow();

  void Show();

  void UpdateCountdown();

  // For testing.
  static IdleLogoutDialogView* current_instance();
  static void set_settings_provider(IdleLogoutSettingsProvider* provider);

  views::Label* restart_label_;

  // Time at which the countdown is over and we should close the dialog.
  base::Time countdown_end_time_;

  base::RepeatingTimer<IdleLogoutDialogView> timer_;

  base::WeakPtrFactory<IdleLogoutDialogView> weak_ptr_factory_;

  static IdleLogoutSettingsProvider* provider_;

  DISALLOW_COPY_AND_ASSIGN(IdleLogoutDialogView);
};

}  // namespace chromeos

#endif  // CHROME_BROWSER_CHROMEOS_UI_IDLE_LOGOUT_DIALOG_VIEW_H_