1// Copyright (c) 2012 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#ifndef CHROME_BROWSER_CHROMEOS_KIOSK_MODE_KIOSK_MODE_SETTINGS_H_
6#define CHROME_BROWSER_CHROMEOS_KIOSK_MODE_KIOSK_MODE_SETTINGS_H_
7
8#include <string>
9
10#include "base/basictypes.h"
11#include "base/callback_forward.h"
12#include "base/time/time.h"
13#include "chrome/browser/chromeos/policy/app_pack_updater.h"
14#include "chrome/browser/chromeos/settings/device_settings_service.h"
15
16namespace base {
17template <typename T> struct DefaultLazyInstanceTraits;
18}
19
20namespace chromeos {
21
22// This class centralizes all our code to get KioskMode settings; since
23// KioskMode interferes with normal operations all over Chrome, having all
24// data about it pulled from a central location would make future
25// refactorings easier. This class also handles getting trust for the policies
26// via its init method.
27//
28// Note: If Initialize is not called before the various Getters, we'll return
29// invalid values.
30class KioskModeSettings {
31 public:
32  static KioskModeSettings* Get();
33
34  // This method checks if Kiosk Mode is enabled or not.
35  virtual bool IsKioskModeEnabled();
36
37  // Initialize the settings; this will call the callback once trust is
38  // established with the policy settings provider.
39  virtual void Initialize(const base::Closure& notify_initialized);
40  virtual bool is_initialized() const;
41
42  // The path to the screensaver extension. This callback may get called
43  // very late, or even never (depending on the state of the app pack).
44  virtual void GetScreensaverPath(
45      policy::AppPackUpdater::ScreenSaverUpdateCallback callback) const;
46
47  // The timeout before which we'll start showing the screensaver.
48  virtual base::TimeDelta GetScreensaverTimeout() const;
49
50  // NOTE: The idle logout timeout is the time 'till' we show the idle dialog
51  // box. After we show the dialog box, it remains up for an 'additional'
52  // IdleLogoutWarningTimeout seconds, which adds to the total time before the
53  // user is logged out.
54  // The time to logout the user in on idle.
55  virtual base::TimeDelta GetIdleLogoutTimeout() const;
56
57  // The time to show the countdown timer for.
58  virtual base::TimeDelta GetIdleLogoutWarningDuration() const;
59
60  static const int kMaxIdleLogoutTimeout;
61  static const int kMinIdleLogoutTimeout;
62
63  static const int kMaxIdleLogoutWarningDuration;
64  static const int kMinIdleLogoutWarningDuration;
65
66 protected:
67  // Needed here so MockKioskModeSettings can inherit from us.
68  KioskModeSettings();
69  virtual ~KioskModeSettings();
70
71 private:
72  friend struct base::DefaultLazyInstanceTraits<KioskModeSettings>;
73  friend class KioskModeSettingsTest;
74
75  // Makes sure the browser will switch to kiosk mode if cryptohome was not
76  // ready when the browser was starting after a machine reboot.
77  void VerifyModeIsKnown(DeviceSettingsService::OwnershipStatus status);
78
79  bool is_initialized_;
80  bool is_kiosk_mode_;
81
82  // Used for testing.
83  void set_initialized(bool value) { is_initialized_ = value; }
84
85  std::string screensaver_id_;
86  std::string screensaver_path_;
87  base::TimeDelta screensaver_timeout_;
88  base::TimeDelta idle_logout_timeout_;
89  base::TimeDelta idle_logout_warning_duration_;
90
91  DISALLOW_COPY_AND_ASSIGN(KioskModeSettings);
92};
93
94}  // namespace chromeos
95
96#endif  // CHROME_BROWSER_CHROMEOS_KIOSK_MODE_KIOSK_MODE_SETTINGS_H_
97