Skip to content

Commit

Permalink
Change demo mode derelict detection.
Browse files Browse the repository at this point in the history
This CL changes the demo mode derelict detection to now take the total time on OOBE instead of idle time on OOBE. This is a much more accurate representation of a derelict state than idle time since a machine can be not idle for 8 hours at a stretch and still be effectively derelict if it is still sitting at OOBE after 8 hours.

R=xiyuan@chromium.org
BUG=345436
TEST=Use the --oobe-timer-interval flag to test the new functionality and verify it works correctly.

Review URL: https://codereview.chromium.org/184033002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@254267 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
rkc@chromium.org committed Feb 28, 2014
1 parent 0cffe28 commit 14ffc08
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 29 deletions.
82 changes: 60 additions & 22 deletions chrome/browser/ui/webui/chromeos/login/network_screen_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "chrome/browser/ui/webui/chromeos/login/network_screen_handler.h"

#include <algorithm>

#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/command_line.h"
Expand Down Expand Up @@ -48,8 +50,9 @@ const char kJsApiNetworkOnTimezoneChanged[] = "networkOnTimezoneChanged";

const char kUSlayout[] = "xkb:us::eng";

const int64 kDerelectDetectionTimeoutSeconds = 8 * 60 * 60; // 8 hours.
const int64 kDerelectIdleTimeoutSeconds = 5 * 60; // 5 minutes.
const int kDerelectDetectionTimeoutSeconds = 8 * 60 * 60; // 8 hours.
const int kDerelectIdleTimeoutSeconds = 5 * 60; // 5 minutes.
const int kOobeTimerUpdateIntervalSeconds = 5 * 60; // 5 minutes.

// Returns true if element was inserted.
bool InsertString(const std::string& str, std::set<std::string>& to) {
Expand Down Expand Up @@ -77,7 +80,6 @@ NetworkScreenHandler::NetworkScreenHandler(CoreOobeActor* core_oobe_actor)
screen_(NULL),
core_oobe_actor_(core_oobe_actor),
is_continue_enabled_(false),
is_derelict_(false),
show_on_init_(false),
weak_ptr_factory_(this) {
DCHECK(core_oobe_actor_);
Expand Down Expand Up @@ -105,7 +107,14 @@ void NetworkScreenHandler::Show() {
}

ShowScreen(OobeUI::kScreenOobeNetwork, NULL);
StartIdleDetection();

if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableDemoMode))
return;

if (IsDerelict())
StartIdleDetection();
else
StartOobeTimer();
}

void NetworkScreenHandler::Hide() {
Expand Down Expand Up @@ -192,7 +201,7 @@ void NetworkScreenHandler::RegisterMessages() {

// static
void NetworkScreenHandler::RegisterPrefs(PrefRegistrySimple* registry) {
registry->RegisterBooleanPref(prefs::kDerelictMachine, false);
registry->RegisterInt64Pref(prefs::kTimeOnOobe, 0);
}

// NetworkScreenHandler, private: ----------------------------------------------
Expand Down Expand Up @@ -275,29 +284,35 @@ void NetworkScreenHandler::OnSystemTimezoneChanged() {
}

void NetworkScreenHandler::StartIdleDetection() {
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableDemoMode))
return;

if (!detector_.get()) {
detector_.reset(
new IdleDetector(base::Closure(),
base::Bind(&NetworkScreenHandler::OnIdle,
weak_ptr_factory_.GetWeakPtr())));
}
detector_->Start(derelict_idle_timeout_);
}

detector_->Start(
is_derelict_ ? derelict_idle_timeout_ : derelict_detection_timeout_);
void NetworkScreenHandler::StartOobeTimer() {
oobe_timer_.Start(FROM_HERE,
oobe_timer_update_interval_,
this,
&NetworkScreenHandler::OnOobeTimerUpdate);
}

void NetworkScreenHandler::OnIdle() {
if (is_derelict_) {
LoginDisplayHost* host = LoginDisplayHostImpl::default_host();
host->StartDemoAppLaunch();
} else {
is_derelict_ = true;
PrefService* prefs = g_browser_process->local_state();
prefs->SetBoolean(prefs::kDerelictMachine, true);
LoginDisplayHost* host = LoginDisplayHostImpl::default_host();
host->StartDemoAppLaunch();
}

void NetworkScreenHandler::OnOobeTimerUpdate() {
time_on_oobe_ += oobe_timer_update_interval_;

PrefService* prefs = g_browser_process->local_state();
prefs->SetInt64(prefs::kTimeOnOobe, time_on_oobe_.InSeconds());

if (IsDerelict()) {
oobe_timer_.Stop();
StartIdleDetection();
}
}
Expand All @@ -307,26 +322,49 @@ void NetworkScreenHandler::SetupTimeouts() {
DCHECK(cmdline);

PrefService* prefs = g_browser_process->local_state();
is_derelict_ = prefs->GetBoolean(prefs::kDerelictMachine);
time_on_oobe_ =
base::TimeDelta::FromSeconds(prefs->GetInt64(prefs::kTimeOnOobe));

int64 derelict_detection_timeout;
int derelict_detection_timeout;
if (!cmdline->HasSwitch(switches::kDerelictDetectionTimeout) ||
!base::StringToInt64(
!base::StringToInt(
cmdline->GetSwitchValueASCII(switches::kDerelictDetectionTimeout),
&derelict_detection_timeout)) {
derelict_detection_timeout = kDerelectDetectionTimeoutSeconds;
}
derelict_detection_timeout_ =
base::TimeDelta::FromSeconds(derelict_detection_timeout);

int64 derelict_idle_timeout;
int derelict_idle_timeout;
if (!cmdline->HasSwitch(switches::kDerelictIdleTimeout) ||
!base::StringToInt64(
!base::StringToInt(
cmdline->GetSwitchValueASCII(switches::kDerelictIdleTimeout),
&derelict_idle_timeout)) {
derelict_idle_timeout = kDerelectIdleTimeoutSeconds;
}
derelict_idle_timeout_ = base::TimeDelta::FromSeconds(derelict_idle_timeout);


int oobe_timer_update_interval;
if (!cmdline->HasSwitch(switches::kOobeTimerInterval) ||
!base::StringToInt(
cmdline->GetSwitchValueASCII(switches::kOobeTimerInterval),
&oobe_timer_update_interval)) {
oobe_timer_update_interval = kOobeTimerUpdateIntervalSeconds;
}
oobe_timer_update_interval_ =
base::TimeDelta::FromSeconds(oobe_timer_update_interval);

// In case we'd be derelict before our timer is set to trigger, reduce
// the interval so we check again when we're scheduled to go derelict.
oobe_timer_update_interval_ =
std::max(std::min(oobe_timer_update_interval_,
derelict_detection_timeout_ - time_on_oobe_),
base::TimeDelta::FromSeconds(0));
}

bool NetworkScreenHandler::IsDerelict() {
return time_on_oobe_ >= derelict_detection_timeout_;
}

// static
Expand Down
14 changes: 11 additions & 3 deletions chrome/browser/ui/webui/chromeos/login/network_screen_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "base/compiler_specific.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "chrome/browser/chromeos/login/screens/network_screen_actor.h"
#include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/browser/ui/webui/chromeos/login/base_screen_handler.h"
Expand Down Expand Up @@ -76,10 +77,13 @@ class NetworkScreenHandler : public NetworkScreenActor,
// Callback when the system timezone settings is changed.
void OnSystemTimezoneChanged();

// Idle detection related methods.
// Demo mode detection methods.
void StartIdleDetection();
void StartOobeTimer();
void OnIdle();
void OnOobeTimerUpdate();
void SetupTimeouts();
bool IsDerelict();

// Returns available languages. Caller gets the ownership. Note, it does
// depend on the current locale.
Expand All @@ -97,8 +101,8 @@ class NetworkScreenHandler : public NetworkScreenActor,

bool is_continue_enabled_;

// Flag set if we believe this is an abandoned machine.
bool is_derelict_;
// Total time this machine has spent on OOBE.
base::TimeDelta time_on_oobe_;

// Keeps whether screen should be shown right after initialization.
bool show_on_init_;
Expand All @@ -110,10 +114,14 @@ class NetworkScreenHandler : public NetworkScreenActor,

scoped_ptr<IdleDetector> detector_;

base::RepeatingTimer<NetworkScreenHandler> oobe_timer_;

// Timeout to detect if the machine is in a derelict state.
base::TimeDelta derelict_detection_timeout_;
// Timeout before showing our demo up if the machine is in a derelict state.
base::TimeDelta derelict_idle_timeout_;
// Time between updating our total time on oobe.
base::TimeDelta oobe_timer_update_interval_;

base::WeakPtrFactory<NetworkScreenHandler> weak_ptr_factory_;

Expand Down
6 changes: 3 additions & 3 deletions chrome/common/pref_names.cc
Original file line number Diff line number Diff line change
Expand Up @@ -895,9 +895,9 @@ const char kSAMLOfflineSigninTimeLimit[] = "saml.offline_signin_time_limit";
// base::Time::ToInternalValue().
const char kSAMLLastGAIASignInTime[] = "saml.last_gaia_sign_in_time";

// Setting used to determine if the machine is in a 'derelict' state. This is
// determined by the time a machine spends on OOBE without any activity.
const char kDerelictMachine[] = "settings.is_machine_derelict";
// The total number of seconds that the machine has spent sitting on the
// OOBE screen.
const char kTimeOnOobe[] = "settings.time_on_oobe";
#endif // defined(OS_CHROMEOS)

// The disabled messages in IPC logging.
Expand Down
2 changes: 1 addition & 1 deletion chrome/common/pref_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ extern const char kMultiProfileUserBehavior[];
extern const char kFirstRunTutorialShown[];
extern const char kSAMLOfflineSigninTimeLimit[];
extern const char kSAMLLastGAIASignInTime[];
extern const char kDerelictMachine[];
extern const char kTimeOnOobe[];
#endif // defined(OS_CHROMEOS)
extern const char kIpcDisabledMessages[];
extern const char kShowHomeButton[];
Expand Down
3 changes: 3 additions & 0 deletions chromeos/chromeos_switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ const char kNaturalScrollDefault[] = "enable-natural-scroll-default";
// Skips all other OOBE pages after user login.
const char kOobeSkipPostLogin[] = "oobe-skip-postlogin";

// Interval at which we check for total time on OOBE.
const char kOobeTimerInterval[] = "oobe-timer-interval";

// Integer flag that sets the DeviceRegistered local state pref.
const char kDeviceRegistered[] = "device-registered";

Expand Down
1 change: 1 addition & 0 deletions chromeos/chromeos_switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ CHROMEOS_EXPORT extern const char kLoginProfile[];
CHROMEOS_EXPORT extern const char kLoginUser[];
CHROMEOS_EXPORT extern const char kNaturalScrollDefault[];
CHROMEOS_EXPORT extern const char kOobeSkipPostLogin[];
CHROMEOS_EXPORT extern const char kOobeTimerInterval[];
CHROMEOS_EXPORT extern const char kDeviceRegistered[];
CHROMEOS_EXPORT extern const char kSkipHWIDCheck[];
CHROMEOS_EXPORT extern const char kSmsTestMessages[];
Expand Down

0 comments on commit 14ffc08

Please sign in to comment.