1// Copyright 2014 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_UI_WEBUI_CHROMEOS_LOGIN_DEMO_MODE_DETECTOR_H_
6#define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_DEMO_MODE_DETECTOR_H_
7
8#include <string>
9
10#include "base/memory/weak_ptr.h"
11#include "base/time/time.h"
12#include "base/timer/timer.h"
13#include "chrome/browser/chromeos/idle_detector.h"
14
15class PrefRegistrySimple;
16
17namespace chromeos {
18
19// Helper for idle state and demo-mode detection.
20// Should be initialized on OOBE start.
21class DemoModeDetector {
22 public:
23  DemoModeDetector();
24  virtual ~DemoModeDetector();
25
26  void InitDetection();
27  void StopDetection();
28
29  // Registers the preference for derelict state.
30  static void RegisterPrefs(PrefRegistrySimple* registry);
31
32 private:
33  void StartIdleDetection();
34  void StartOobeTimer();
35  void OnIdle();
36  void OnOobeTimerUpdate();
37  void SetupTimeouts();
38  bool IsDerelict();
39
40  // Total time this machine has spent on OOBE.
41  base::TimeDelta time_on_oobe_;
42
43  scoped_ptr<IdleDetector> idle_detector_;
44
45  base::RepeatingTimer<DemoModeDetector> oobe_timer_;
46
47  // Timeout to detect if the machine is in a derelict state.
48  base::TimeDelta derelict_detection_timeout_;
49
50  // Timeout before showing our demo app if the machine is in a derelict state.
51  base::TimeDelta derelict_idle_timeout_;
52
53  // Time between updating our total time on oobe.
54  base::TimeDelta oobe_timer_update_interval_;
55
56  bool demo_launched_;
57
58  base::WeakPtrFactory<DemoModeDetector> weak_ptr_factory_;
59
60  DISALLOW_COPY_AND_ASSIGN(DemoModeDetector);
61};
62
63}  // namespace chromeos
64
65#endif  // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_DEMO_MODE_DETECTOR_H_
66