Skip to content

Commit

Permalink
Add the ability to show a demo app on OOBE if a machine is derelict.
Browse files Browse the repository at this point in the history
If a machine has been idle for 8 hours+, we should start showing a demo app everytime the machine is idle for 5 minutes.
This CL depends on https://chrome-internal-review.googlesource.com/#/c/154276/

R=xiyuan@chromium.org, zelidrag@chromium.org
BUG=336585
TEST=Use the derelict-* flags to test demo mode app launching.

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@250666 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
rkc@chromium.org committed Feb 12, 2014
1 parent 8315a7e commit eed749b
Show file tree
Hide file tree
Showing 29 changed files with 388 additions and 24 deletions.
1 change: 1 addition & 0 deletions chrome/browser/browser_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@
<include name="IDR_IMAGE_LOADER_MANIFEST" file="resources\image_loader\manifest.json" type="BINDATA" />
</if>
<if expr="pp_ifdef('chromeos')">
<include name="IDR_DEMO_APP_MANIFEST" file="resources\chromeos\demo_app\manifest.json" type="BINDATA" />
<include name="IDR_WALLPAPERMANAGER_MANIFEST" file="resources\chromeos\wallpaper_manager\manifest.json" type="BINDATA" />
<include name="IDR_FIRST_RUN_DIALOG_MANIFEST" file="resources\chromeos\first_run\app/manifest.json" type="BINDATA" />
</if>
Expand Down
16 changes: 6 additions & 10 deletions chrome/browser/chromeos/app_mode/kiosk_profile_loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,12 @@ class KioskProfileLoader::CryptohomedChecker
////////////////////////////////////////////////////////////////////////////////
// KioskProfileLoader

KioskProfileLoader::KioskProfileLoader(KioskAppManager* kiosk_app_manager,
const std::string& app_id,
KioskProfileLoader::KioskProfileLoader(const std::string& app_user_id,
bool force_ephemeral,
Delegate* delegate)
: kiosk_app_manager_(kiosk_app_manager),
app_id_(app_id),
delegate_(delegate) {
KioskAppManager::App app;
CHECK(kiosk_app_manager_->GetApp(app_id_, &app));
user_id_ = app.user_id;
}
: user_id_(app_user_id),
force_ephemeral_(force_ephemeral),
delegate_(delegate) {}

KioskProfileLoader::~KioskProfileLoader() {}

Expand All @@ -137,7 +133,7 @@ void KioskProfileLoader::Start() {

void KioskProfileLoader::LoginAsKioskAccount() {
login_performer_.reset(new LoginPerformer(this));
login_performer_->LoginAsKioskAccount(user_id_);
login_performer_->LoginAsKioskAccount(user_id_, force_ephemeral_);
}

void KioskProfileLoader::ReportLaunchResult(KioskAppLaunchError::Error error) {
Expand Down
7 changes: 3 additions & 4 deletions chrome/browser/chromeos/app_mode/kiosk_profile_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class KioskProfileLoader : public LoginPerformer::Delegate,
virtual ~Delegate() {}
};

KioskProfileLoader(KioskAppManager* kiosk_app_manager,
const std::string& app_id,
KioskProfileLoader(const std::string& app_user_id,
bool force_ephemeral,
Delegate* delegate);

virtual ~KioskProfileLoader();
Expand All @@ -61,9 +61,8 @@ class KioskProfileLoader : public LoginPerformer::Delegate,
// LoginUtils::Delegate implementation:
virtual void OnProfilePrepared(Profile* profile) OVERRIDE;

KioskAppManager* kiosk_app_manager_;
const std::string app_id_;
std::string user_id_;
bool force_ephemeral_;
Delegate* delegate_;
scoped_ptr<CryptohomedChecker> cryptohomed_checker_;
scoped_ptr<LoginPerformer> login_performer_;
Expand Down
45 changes: 45 additions & 0 deletions chrome/browser/chromeos/idle_detector.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2014 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.

#include "chrome/browser/chromeos/idle_detector.h"

#include "ash/shell.h"
#include "ash/wm/user_activity_detector.h"
#include "base/bind.h"
#include "base/logging.h"

namespace chromeos {

IdleDetector::IdleDetector(const base::Closure& on_active_callback,
const base::Closure& on_idle_callback)
: active_callback_(on_active_callback), idle_callback_(on_idle_callback) {}

IdleDetector::~IdleDetector() {
if (ash::Shell::HasInstance() &&
ash::Shell::GetInstance()->user_activity_detector()->HasObserver(this))
ash::Shell::GetInstance()->user_activity_detector()->RemoveObserver(this);
}

void IdleDetector::OnUserActivity(const ui::Event* event) {
if (!active_callback_.is_null())
active_callback_.Run();
ResetTimer();
}

void IdleDetector::Start(const base::TimeDelta& timeout) {
timeout_ = timeout;
if (!ash::Shell::GetInstance()->user_activity_detector()->HasObserver(this))
ash::Shell::GetInstance()->user_activity_detector()->AddObserver(this);
ResetTimer();
}

void IdleDetector::ResetTimer() {
if (timer_.IsRunning()) {
timer_.Reset();
} else {
timer_.Start(FROM_HERE, timeout_, idle_callback_);
}
}

} // namespace chromeos
42 changes: 42 additions & 0 deletions chrome/browser/chromeos/idle_detector.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2014 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_IDLE_DETECTOR_H_
#define CHROME_BROWSER_CHROMEOS_IDLE_DETECTOR_H_

#include "ash/wm/user_activity_observer.h"
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/timer/timer.h"

namespace chromeos {

class IdleDetector : public ash::UserActivityObserver {
public:
IdleDetector(const base::Closure& on_active_callback,
const base::Closure& on_idle_callback);
virtual ~IdleDetector();

void Start(const base::TimeDelta& timeout);

private:
// UserActivityObserver overrides:
virtual void OnUserActivity(const ui::Event* event) OVERRIDE;

// Resets |timer_| to fire when we reach our idle timeout.
void ResetTimer();

base::OneShotTimer<IdleDetector> timer_;

base::Closure active_callback_;
base::Closure idle_callback_;

base::TimeDelta timeout_;

DISALLOW_COPY_AND_ASSIGN(IdleDetector);
};

} // namespace chromeos

#endif // CHROME_BROWSER_CHROMEOS_IDLE_DETECTOR_H_
5 changes: 4 additions & 1 deletion chrome/browser/chromeos/login/app_launch_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,11 @@ void AppLaunchController::StartAppLaunch() {
app_launch_splash_screen_actor_->SetDelegate(this);
app_launch_splash_screen_actor_->Show(app_id_);

KioskAppManager::App app;
CHECK(KioskAppManager::Get() &&
KioskAppManager::Get()->GetApp(app_id_, &app));
kiosk_profile_loader_.reset(
new KioskProfileLoader(KioskAppManager::Get(), app_id_, this));
new KioskProfileLoader(app.user_id, false, this));
kiosk_profile_loader_->Start();
}

Expand Down
4 changes: 3 additions & 1 deletion chrome/browser/chromeos/login/authenticator.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ class Authenticator : public base::RefCountedThreadSafe<Authenticator> {

// Initiates login into kiosk mode account identified by |app_user_id|.
// The |app_user_id| is a generated username for the account.
virtual void LoginAsKioskAccount(const std::string& app_user_id) = 0;
// |force_ephemeral| specifies whether to force the session to be ephemeral.
virtual void LoginAsKioskAccount(
const std::string& app_user_id, bool force_ephemeral) = 0;

// Completes retail mode login.
virtual void OnRetailModeLoginSuccess() = 0;
Expand Down
76 changes: 76 additions & 0 deletions chrome/browser/chromeos/login/demo_mode/demo_app_launcher.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Copyright 2014 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.

#include "chrome/browser/chromeos/login/demo_mode/demo_app_launcher.h"

#include "base/command_line.h"
#include "chrome/browser/chromeos/app_mode/app_session_lifetime.h"
#include "chrome/browser/chromeos/login/login_display_host_impl.h"
#include "chrome/browser/chromeos/login/user_manager.h"
#include "chrome/browser/extensions/component_loader.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/ui/extensions/application_launch.h"
#include "chrome/common/chrome_switches.h"
#include "extensions/browser/extension_system.h"
#include "grit/browser_resources.h"

namespace {

const char kDemoAppUserId[] = "demouser@demo.app.local";

}

namespace chromeos {

DemoAppLauncher::DemoAppLauncher() : profile_(NULL) {}

DemoAppLauncher::~DemoAppLauncher() {}

void DemoAppLauncher::StartDemoAppLaunch() {
DVLOG(1) << "Launching demo app...";
// user_id = DemoAppUserId, force_emphemeral = true, delegate = this.
kiosk_profile_loader_.reset(
new KioskProfileLoader(kDemoAppUserId, true, this));
kiosk_profile_loader_->Start();
}

// static
bool DemoAppLauncher::IsDemoAppSession(const std::string& user_id) {
return user_id == kDemoAppUserId ? true : false;
}

void DemoAppLauncher::OnProfileLoaded(Profile* profile) {
DVLOG(1) << "Profile loaded... Starting demo app launch.";
profile_ = profile;

kiosk_profile_loader_.reset();

// Load our demo app, then launch it.
ExtensionService* extension_service =
extensions::ExtensionSystem::Get(profile_)->extension_service();
std::string extension_id = extension_service->component_loader()->Add(
IDR_DEMO_APP_MANIFEST,
base::FilePath("/usr/share/chromeos-assets/demo_app"));

const extensions::Extension* extension =
extension_service->GetExtensionById(extension_id, true);

CommandLine* command_line = CommandLine::ForCurrentProcess();
command_line->AppendSwitch(switches::kForceAppMode);
command_line->AppendSwitchASCII(switches::kAppId, extension_id);

OpenApplication(AppLaunchParams(
profile_, extension, extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW));
InitAppSession(profile_, extension_id);

UserManager::Get()->SessionStarted();

LoginDisplayHostImpl::default_host()->Finalize();
}

void DemoAppLauncher::OnProfileLoadFailed(KioskAppLaunchError::Error error) {
LOG(ERROR) << "Loading the Kiosk Profile failed.";
}

} // namespace chromeos
38 changes: 38 additions & 0 deletions chrome/browser/chromeos/login/demo_mode/demo_app_launcher.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2014 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_LOGIN_DEMO_MODE_DEMO_APP_LAUNCHER_H_
#define CHROME_BROWSER_CHROMEOS_LOGIN_DEMO_MODE_DEMO_APP_LAUNCHER_H_

#include "base/memory/scoped_ptr.h"
#include "chrome/browser/chromeos/app_mode/kiosk_profile_loader.h"

class Profile;

namespace chromeos {

// Class responsible for launching the demo app under a kiosk session.
class DemoAppLauncher : public KioskProfileLoader::Delegate {
public:
DemoAppLauncher();
virtual ~DemoAppLauncher();

void StartDemoAppLaunch();

static bool IsDemoAppSession(const std::string& user_id);

private:
// KioskProfileLoader::Delegate overrides:
virtual void OnProfileLoaded(Profile* profile) OVERRIDE;
virtual void OnProfileLoadFailed(KioskAppLaunchError::Error error) OVERRIDE;

Profile* profile_;
scoped_ptr<KioskProfileLoader> kiosk_profile_loader_;

DISALLOW_COPY_AND_ASSIGN(DemoAppLauncher);
};

} // namespace chromeos

#endif // CHROME_BROWSER_CHROMEOS_LOGIN_DEMO_MODE_DEMO_APP_LAUNCHER_H_
3 changes: 3 additions & 0 deletions chrome/browser/chromeos/login/login_display_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ class LoginDisplayHost {
// Starts app launch splash screen.
virtual void StartAppLaunch(const std::string& app_id,
bool diagnostic_mode) = 0;

// Starts the demo app launch.
virtual void StartDemoAppLaunch() = 0;
};

} // namespace chromeos
Expand Down
8 changes: 8 additions & 0 deletions chrome/browser/chromeos/login/login_display_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,14 @@ void LoginDisplayHostImpl::PrewarmAuthentication() {
pointer_factory_.GetWeakPtr()));
}

void LoginDisplayHostImpl::StartDemoAppLaunch() {
LOG(WARNING) << "Login WebUI >> starting demo app.";
SetStatusAreaVisible(false);

demo_app_launcher_.reset(new DemoAppLauncher());
demo_app_launcher_->StartDemoAppLaunch();
}

void LoginDisplayHostImpl::StartAppLaunch(const std::string& app_id,
bool diagnostic_mode) {
LOG(WARNING) << "Login WebUI >> start app launch.";
Expand Down
5 changes: 5 additions & 0 deletions chrome/browser/chromeos/login/login_display_host_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "base/memory/weak_ptr.h"
#include "chrome/browser/chromeos/login/app_launch_controller.h"
#include "chrome/browser/chromeos/login/auth_prewarmer.h"
#include "chrome/browser/chromeos/login/demo_mode/demo_app_launcher.h"
#include "chrome/browser/chromeos/login/existing_user_controller.h"
#include "chrome/browser/chromeos/login/login_display.h"
#include "chrome/browser/chromeos/login/login_display_host.h"
Expand Down Expand Up @@ -81,6 +82,7 @@ class LoginDisplayHostImpl : public LoginDisplayHost,
virtual void PrewarmAuthentication() OVERRIDE;
virtual void StartAppLaunch(const std::string& app_id,
bool diagnostic_mode) OVERRIDE;
virtual void StartDemoAppLaunch() OVERRIDE;

// Creates WizardController instance.
WizardController* CreateWizardController();
Expand Down Expand Up @@ -203,6 +205,9 @@ class LoginDisplayHostImpl : public LoginDisplayHost,
// App launch controller.
scoped_ptr<AppLaunchController> app_launch_controller_;

// Demo app launcher.
scoped_ptr<DemoAppLauncher> demo_app_launcher_;

// Client for enterprise auto-enrollment check.
scoped_ptr<policy::AutoEnrollmentClient> auto_enrollment_client_;

Expand Down
5 changes: 3 additions & 2 deletions chrome/browser/chromeos/login/login_performer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,13 @@ void LoginPerformer::LoginAsPublicAccount(const std::string& username) {
username));
}

void LoginPerformer::LoginAsKioskAccount(const std::string& app_user_id) {
void LoginPerformer::LoginAsKioskAccount(
const std::string& app_user_id, bool force_ephemeral) {
authenticator_ = LoginUtils::Get()->CreateAuthenticator(this);
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&Authenticator::LoginAsKioskAccount, authenticator_.get(),
app_user_id));
app_user_id, force_ephemeral));
}

void LoginPerformer::RecoverEncryptedData(const std::string& old_password) {
Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/chromeos/login/login_performer.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ class LoginPerformer : public LoginStatusConsumer,
void LoginAsPublicAccount(const std::string& username);

// Performs a login into the kiosk mode account with |app_user_id|.
void LoginAsKioskAccount(const std::string& app_user_id);
void LoginAsKioskAccount(const std::string& app_user_id,
bool force_ephemeral);

// Migrates cryptohome using |old_password| specified.
void RecoverEncryptedData(const std::string& old_password);
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/chromeos/login/mock_authenticator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void MockAuthenticator::LoginAsPublicAccount(const std::string& username) {
}

void MockAuthenticator::LoginAsKioskAccount(
const std::string& app_user_id) {
const std::string& app_user_id, bool force_ephemeral) {
consumer_->OnLoginSuccess(UserContext(expected_username_,
std::string(),
std::string(),
Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/chromeos/login/mock_authenticator.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class MockAuthenticator : public Authenticator {
const UserContext& user_context) OVERRIDE;
virtual void LoginRetailMode() OVERRIDE;
virtual void LoginAsPublicAccount(const std::string& username) OVERRIDE;
virtual void LoginAsKioskAccount(const std::string& app_user_id) OVERRIDE;
virtual void LoginAsKioskAccount(
const std::string& app_user_id, bool force_ephemeral) OVERRIDE;
virtual void LoginOffTheRecord() OVERRIDE;

virtual void OnRetailModeLoginSuccess() OVERRIDE;
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/chromeos/login/mock_login_display_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class MockLoginDisplayHost : public LoginDisplayHost {
MOCK_METHOD0(OnPreferencesChanged, void(void));
MOCK_METHOD0(PrewarmAuthentication, void(void));
MOCK_METHOD2(StartAppLaunch, void(const std::string&, bool));
MOCK_METHOD0(StartDemoAppLaunch, void(void));

private:
DISALLOW_COPY_AND_ASSIGN(MockLoginDisplayHost);
Expand Down
Loading

0 comments on commit eed749b

Please sign in to comment.