Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Side by Side Diff: chrome/browser/ui/webui/chromeos/login/demo_mode_detector.cc

Issue 2692793007: cros: Move DemoModeDetector out of webui directory. (Closed)
Patch Set: Initial upload Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/webui/chromeos/login/demo_mode_detector.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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 #include "chrome/browser/ui/webui/chromeos/login/demo_mode_detector.h"
6
7 #include "base/command_line.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "base/sys_info.h"
10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/chromeos/login/ui/login_display_host.h"
12 #include "chrome/common/pref_names.h"
13 #include "chromeos/chromeos_switches.h"
14 #include "components/prefs/pref_registry_simple.h"
15 #include "components/prefs/pref_service.h"
16
17 namespace {
18 const int kDerelectDetectionTimeoutSeconds = 8 * 60 * 60; // 8 hours.
19 const int kDerelectIdleTimeoutSeconds = 5 * 60; // 5 minutes.
20 const int kOobeTimerUpdateIntervalSeconds = 5 * 60; // 5 minutes.
21 } // namespace
22
23 namespace chromeos {
24
25 DemoModeDetector::DemoModeDetector()
26 : demo_launched_(false),
27 weak_ptr_factory_(this) {
28 SetupTimeouts();
29 }
30
31 DemoModeDetector::~DemoModeDetector() {
32 }
33
34 // Public methods.
35
36 void DemoModeDetector::InitDetection() {
37 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
38 switches::kDisableDemoMode))
39 return;
40
41 const bool has_derelict_switch =
42 base::CommandLine::ForCurrentProcess()->HasSwitch(
43 switches::kDerelictDetectionTimeout) ||
44 base::CommandLine::ForCurrentProcess()->HasSwitch(
45 switches::kDerelictIdleTimeout);
46
47 if (base::SysInfo::IsRunningOnChromeOS() && !has_derelict_switch) {
48 std::string track;
49 // We're running on an actual device; if we cannot find our release track
50 // value or if the track contains "testimage", don't start demo mode.
51 if (!base::SysInfo::GetLsbReleaseValue("CHROMEOS_RELEASE_TRACK", &track) ||
52 track.find("testimage") != std::string::npos)
53 return;
54 }
55
56 if (IsDerelict())
57 StartIdleDetection();
58 else
59 StartOobeTimer();
60 }
61
62 void DemoModeDetector::StopDetection() {
63 oobe_timer_.Stop();
64 idle_detector_.reset();
65 }
66
67 // static
68 void DemoModeDetector::RegisterPrefs(PrefRegistrySimple* registry) {
69 registry->RegisterInt64Pref(prefs::kTimeOnOobe, 0);
70 }
71
72 // Private methods.
73
74 void DemoModeDetector::StartIdleDetection() {
75 if (!idle_detector_.get()) {
76 idle_detector_.reset(
77 new IdleDetector(base::Bind(&DemoModeDetector::OnIdle,
78 weak_ptr_factory_.GetWeakPtr())));
79 }
80 idle_detector_->Start(derelict_idle_timeout_);
81 }
82
83 void DemoModeDetector::StartOobeTimer() {
84 if (oobe_timer_.IsRunning())
85 return;
86 oobe_timer_.Start(FROM_HERE,
87 oobe_timer_update_interval_,
88 this,
89 &DemoModeDetector::OnOobeTimerUpdate);
90 }
91
92 void DemoModeDetector::OnIdle() {
93 if (demo_launched_)
94 return;
95 demo_launched_ = true;
96 LoginDisplayHost::default_host()->StartDemoAppLaunch();
97 }
98
99 void DemoModeDetector::OnOobeTimerUpdate() {
100 time_on_oobe_ += oobe_timer_update_interval_;
101
102 PrefService* prefs = g_browser_process->local_state();
103 prefs->SetInt64(prefs::kTimeOnOobe, time_on_oobe_.InSeconds());
104
105 if (IsDerelict()) {
106 oobe_timer_.Stop();
107 StartIdleDetection();
108 }
109 }
110
111 void DemoModeDetector::SetupTimeouts() {
112 base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess();
113 DCHECK(cmdline);
114
115 PrefService* prefs = g_browser_process->local_state();
116 time_on_oobe_ =
117 base::TimeDelta::FromSeconds(prefs->GetInt64(prefs::kTimeOnOobe));
118
119 int derelict_detection_timeout;
120 if (!cmdline->HasSwitch(switches::kDerelictDetectionTimeout) ||
121 !base::StringToInt(
122 cmdline->GetSwitchValueASCII(switches::kDerelictDetectionTimeout),
123 &derelict_detection_timeout)) {
124 derelict_detection_timeout = kDerelectDetectionTimeoutSeconds;
125 }
126 derelict_detection_timeout_ =
127 base::TimeDelta::FromSeconds(derelict_detection_timeout);
128
129 int derelict_idle_timeout;
130 if (!cmdline->HasSwitch(switches::kDerelictIdleTimeout) ||
131 !base::StringToInt(
132 cmdline->GetSwitchValueASCII(switches::kDerelictIdleTimeout),
133 &derelict_idle_timeout)) {
134 derelict_idle_timeout = kDerelectIdleTimeoutSeconds;
135 }
136 derelict_idle_timeout_ = base::TimeDelta::FromSeconds(derelict_idle_timeout);
137
138
139 int oobe_timer_update_interval;
140 if (!cmdline->HasSwitch(switches::kOobeTimerInterval) ||
141 !base::StringToInt(
142 cmdline->GetSwitchValueASCII(switches::kOobeTimerInterval),
143 &oobe_timer_update_interval)) {
144 oobe_timer_update_interval = kOobeTimerUpdateIntervalSeconds;
145 }
146 oobe_timer_update_interval_ =
147 base::TimeDelta::FromSeconds(oobe_timer_update_interval);
148
149 // In case we'd be derelict before our timer is set to trigger, reduce
150 // the interval so we check again when we're scheduled to go derelict.
151 oobe_timer_update_interval_ =
152 std::max(std::min(oobe_timer_update_interval_,
153 derelict_detection_timeout_ - time_on_oobe_),
154 base::TimeDelta::FromSeconds(0));
155 }
156
157 bool DemoModeDetector::IsDerelict() {
158 return time_on_oobe_ >= derelict_detection_timeout_;
159 }
160
161 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/chromeos/login/demo_mode_detector.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698