Skip to content

Commit

Permalink
Draft implementation of host pairing UI.
Browse files Browse the repository at this point in the history
Implemented paring UI for host side. This implementation lacks styling,
transitions, images and real strings. However it is fully functional, and can
be used with FakeHostPairingController or with real controller when it will be
implemented.
For testing purposes "show-host-pairing-demo" switch was added. If this
switch is set, paring procedure will be emulated during OOBE. Demo
flow can be configured with a value of "show-host-pairing-demo" option, if the
value is empty default config is used.
For config format see comments in fake_host_pairing_controller.h.

BUG=375191
TEST=none

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@281447 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
dzhioev@chromium.org committed Jul 4, 2014
1 parent 1b129fb commit dec99e3
Show file tree
Hide file tree
Showing 23 changed files with 603 additions and 1 deletion.
126 changes: 126 additions & 0 deletions chrome/browser/chromeos/login/screens/host_pairing_screen.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
// 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/screens/host_pairing_screen.h"

#include "base/command_line.h"
#include "chrome/browser/chromeos/login/wizard_controller.h"
#include "chromeos/chromeos_switches.h"
#include "chromeos/pairing/fake_host_pairing_controller.h"

namespace chromeos {

using namespace host_pairing;

HostPairingScreen::HostPairingScreen(ScreenObserver* observer,
HostPairingScreenActor* actor)
: WizardScreen(observer),
actor_(actor),
current_stage_(HostPairingController::STAGE_NONE) {
actor_->SetDelegate(this);
std::string controller_config =
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kShowHostPairingDemo);
controller_.reset(new FakeHostPairingController(controller_config));
controller_->AddObserver(this);
}

HostPairingScreen::~HostPairingScreen() {
if (actor_)
actor_->SetDelegate(NULL);
controller_->RemoveObserver(this);
}

void HostPairingScreen::CommitContextChanges() {
if (!context_.HasChanges())
return;
base::DictionaryValue diff;
context_.GetChangesAndReset(&diff);
if (actor_)
actor_->OnContextChanged(diff);
}

void HostPairingScreen::PrepareToShow() {
}

void HostPairingScreen::Show() {
if (actor_)
actor_->Show();
controller_->StartPairing();
}

void HostPairingScreen::Hide() {
if (actor_)
actor_->Hide();
}

std::string HostPairingScreen::GetName() const {
return WizardController::kHostPairingScreenName;
}

void HostPairingScreen::PairingStageChanged(Stage new_stage) {
DCHECK(new_stage != current_stage_);

std::string desired_page;
switch (new_stage) {
case HostPairingController::STAGE_WAITING_FOR_CONTROLLER:
case HostPairingController::STAGE_WAITING_FOR_CONTROLLER_AFTER_UPDATE: {
desired_page = kPageWelcome;
break;
}
case HostPairingController::STAGE_WAITING_FOR_CODE_CONFIRMATION: {
desired_page = kPageCodeConfirmation;
context_.SetString(kContextKeyConfirmationCode,
controller_->GetConfirmationCode());
break;
}
case HostPairingController::STAGE_UPDATING: {
desired_page = kPageUpdate;
context_.SetDouble(kContextKeyUpdateProgress, 0.0);
break;
}
case HostPairingController::STAGE_WAITING_FOR_CREDENTIALS: {
desired_page = kPageEnrollmentIntroduction;
break;
}
case HostPairingController::STAGE_ENROLLING: {
desired_page = kPageEnrollment;
context_.SetString(kContextKeyEnrollmentDomain,
controller_->GetEnrollmentDomain());
break;
}
case HostPairingController::STAGE_ENROLLMENT_ERROR: {
desired_page = kPageEnrollmentError;
break;
}
case HostPairingController::STAGE_PAIRING_DONE: {
desired_page = kPagePairingDone;
break;
}
case HostPairingController::STAGE_FINISHED: {
get_screen_observer()->OnExit(WizardController::HOST_PAIRING_FINISHED);
break;
}
default: {
NOTREACHED();
break;
}
}
current_stage_ = new_stage;
context_.SetString(kContextKeyDeviceName, controller_->GetDeviceName());
context_.SetString(kContextKeyPage, desired_page);
CommitContextChanges();
}

void HostPairingScreen::UpdateAdvanced(const UpdateProgress& progress) {
context_.SetDouble(kContextKeyUpdateProgress, progress.progress);
CommitContextChanges();
}

void HostPairingScreen::OnActorDestroyed(HostPairingScreenActor* actor) {
if (actor_ == actor)
actor_ = NULL;
}

} // namespace chromeos
60 changes: 60 additions & 0 deletions chrome/browser/chromeos/login/screens/host_pairing_screen.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// 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_SCREENS_HOST_PAIRING_SCREEN_H_
#define CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_HOST_PAIRING_SCREEN_H_

#include "base/macros.h"
#include "chrome/browser/chromeos/login/screens/host_pairing_screen_actor.h"
#include "chrome/browser/chromeos/login/screens/screen_context.h"
#include "chrome/browser/chromeos/login/screens/wizard_screen.h"
#include "chromeos/pairing/host_pairing_controller.h"

namespace chromeos {

class HostPairingScreen : public WizardScreen,
public HostPairingController::Observer,
public HostPairingScreenActor::Delegate {
public:
HostPairingScreen(ScreenObserver* observer, HostPairingScreenActor* actor);
virtual ~HostPairingScreen();

private:
typedef HostPairingController::Stage Stage;
typedef HostPairingController::UpdateProgress UpdateProgress;

void CommitContextChanges();

// Overridden from WizardScreen:
virtual void PrepareToShow() OVERRIDE;
virtual void Show() OVERRIDE;
virtual void Hide() OVERRIDE;
virtual std::string GetName() const OVERRIDE;

// Overridden from HostPairingController::Observer:
virtual void PairingStageChanged(Stage new_stage) OVERRIDE;
virtual void UpdateAdvanced(const UpdateProgress& progress) OVERRIDE;

// Overridden from ControllerPairingView::Delegate:
virtual void OnActorDestroyed(HostPairingScreenActor* actor) OVERRIDE;

// Context for sharing data between C++ and JS.
// TODO(dzhioev): move to BaseScreen when possible.
ScreenContext context_;

HostPairingScreenActor* actor_;

// Controller performing pairing. Owned by the screen for now.
// TODO(dzhioev): move to proper place later.
scoped_ptr<HostPairingController> controller_;

// Current stage of pairing process.
Stage current_stage_;

DISALLOW_COPY_AND_ASSIGN(HostPairingScreen);
};

} // namespace chromeos

#endif // CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_HOST_PAIRING_SCREEN_H_
35 changes: 35 additions & 0 deletions chrome/browser/chromeos/login/screens/host_pairing_screen_actor.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// 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/screens/host_pairing_screen_actor.h"

namespace chromeos {

namespace host_pairing {

// Keep these constants synced with corresponding constants defined in
// oobe_screen_host_pairing.js.
const char kContextKeyPage[] = "page";
const char kContextKeyDeviceName[] = "deviceName";
const char kContextKeyConfirmationCode[] = "code";
const char kContextKeyEnrollmentDomain[] = "enrollmentDomain";
const char kContextKeyUpdateProgress[] = "updateProgress";

const char kPageWelcome[] = "welcome";
const char kPageCodeConfirmation[] = "code-confirmation";
const char kPageUpdate[] = "update";
const char kPageEnrollmentIntroduction[] = "enrollment-introduction";
const char kPageEnrollment[] = "enrollment";
const char kPageEnrollmentError[] = "enrollment-error";
const char kPagePairingDone[] = "pairing-done";

} // namespace host_pairing

HostPairingScreenActor::HostPairingScreenActor() {
}

HostPairingScreenActor::~HostPairingScreenActor() {
}

} // namespace chromeos
60 changes: 60 additions & 0 deletions chrome/browser/chromeos/login/screens/host_pairing_screen_actor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// 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_SCREENS_HOST_PAIRING_SCREEN_ACTOR_H_
#define CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_HOST_PAIRING_SCREEN_ACTOR_H_

#include "base/macros.h"

namespace base {
class DictionaryValue;
}

namespace chromeos {

namespace host_pairing {

// Keep these constants synced with corresponding constants defined in
// oobe_screen_host_pairing.js.
// Conxtext keys.
extern const char kContextKeyPage[];
extern const char kContextKeyDeviceName[];
extern const char kContextKeyConfirmationCode[];
extern const char kContextKeyEnrollmentDomain[];
extern const char kContextKeyUpdateProgress[];

// Pages names.
extern const char kPageWelcome[];
extern const char kPageCodeConfirmation[];
extern const char kPageUpdate[];
extern const char kPageEnrollmentIntroduction[];
extern const char kPageEnrollment[];
extern const char kPageEnrollmentError[];
extern const char kPagePairingDone[];

} // namespace host_pairing

class HostPairingScreenActor {
public:
class Delegate {
public:
virtual ~Delegate() {}
virtual void OnActorDestroyed(HostPairingScreenActor* actor) = 0;
};

HostPairingScreenActor();
virtual ~HostPairingScreenActor();

virtual void Show() = 0;
virtual void Hide() = 0;
virtual void SetDelegate(Delegate* delegate) = 0;
virtual void OnContextChanged(const base::DictionaryValue& diff) = 0;

private:
DISALLOW_COPY_AND_ASSIGN(HostPairingScreenActor);
};

} // namespace chromeos

#endif // CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_HOST_PAIRING_SCREEN_ACTOR_H_
1 change: 1 addition & 0 deletions chrome/browser/chromeos/login/screens/screen_observer.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class ScreenObserver {
TERMS_OF_SERVICE_ACCEPTED = 19,
WRONG_HWID_WARNING_SKIPPED = 20,
CONTROLLER_PAIRING_FINISHED = 21,
HOST_PAIRING_FINISHED = 22,
EXIT_CODES_COUNT // not a real code, must be the last
};

Expand Down
3 changes: 3 additions & 0 deletions chrome/browser/chromeos/login/ui/oobe_display.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class EnrollmentScreenActor;
class ErrorScreenActor;
class EulaScreenActor;
class HIDDetectionScreenActor;
class HostPairingScreenActor;
class KioskAutolaunchScreenActor;
class KioskEnableScreenActor;
class LocallyManagedUserCreationScreenHandler;
Expand Down Expand Up @@ -58,6 +59,7 @@ class OobeDisplay {
SCREEN_CONFIRM_PASSWORD,
SCREEN_FATAL_ERROR,
SCREEN_OOBE_CONTROLLER_PAIRING,
SCREEN_OOBE_HOST_PAIRING,
SCREEN_UNKNOWN
};

Expand All @@ -84,6 +86,7 @@ class OobeDisplay {
GetLocallyManagedUserCreationScreenActor() = 0;
virtual AppLaunchSplashScreenActor* GetAppLaunchSplashScreenActor() = 0;
virtual ControllerPairingScreenActor* GetControllerPairingScreenActor() = 0;
virtual HostPairingScreenActor* GetHostPairingScreenActor() = 0;

// Returns if JS side is fully loaded and ready to accept messages.
// If |false| is returned, then |display_is_ready_callback| is stored
Expand Down
Loading

0 comments on commit dec99e3

Please sign in to comment.