enrollment_screen.h revision c2e0dbddbe15c98d52c4786dac06cb8952a8ae6d
1// Copyright (c) 2012 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_CHROMEOS_LOGIN_ENROLLMENT_ENROLLMENT_SCREEN_H_ 6#define CHROME_BROWSER_CHROMEOS_LOGIN_ENROLLMENT_ENROLLMENT_SCREEN_H_ 7 8#include <string> 9 10#include "base/basictypes.h" 11#include "base/compiler_specific.h" 12#include "base/memory/weak_ptr.h" 13#include "base/observer_list.h" 14#include "chrome/browser/chromeos/login/enrollment/enrollment_screen_actor.h" 15#include "chrome/browser/chromeos/login/screens/wizard_screen.h" 16#include "chrome/browser/policy/cloud/cloud_policy_constants.h" 17 18namespace chromeos { 19 20class ScreenObserver; 21 22// The screen implementation that links the enterprise enrollment UI into the 23// OOBE wizard. 24class EnrollmentScreen 25 : public WizardScreen, 26 public EnrollmentScreenActor::Controller { 27 public: 28 // Used in PyAuto testing. 29 class TestingObserver { 30 public: 31 virtual ~TestingObserver() {} 32 33 // Notifies observers of a change in enrollment state. 34 virtual void OnEnrollmentComplete(bool succeeded) = 0; 35 }; 36 37 EnrollmentScreen(ScreenObserver* observer, 38 EnrollmentScreenActor* actor); 39 virtual ~EnrollmentScreen(); 40 41 void SetParameters(bool is_auto_enrollment, 42 bool can_exit_enrollment, 43 const std::string& enrollment_user); 44 45 // WizardScreen implementation: 46 virtual void PrepareToShow() OVERRIDE; 47 virtual void Show() OVERRIDE; 48 virtual void Hide() OVERRIDE; 49 virtual std::string GetName() const OVERRIDE; 50 51 // EnrollmentScreenActor::Controller implementation: 52 virtual void OnLoginDone(const std::string& user) OVERRIDE; 53 virtual void OnAuthError(const GoogleServiceAuthError& error) OVERRIDE; 54 virtual void OnOAuthTokenAvailable(const std::string& oauth_token) OVERRIDE; 55 virtual void OnRetry() OVERRIDE; 56 virtual void OnCancel() OVERRIDE; 57 virtual void OnConfirmationClosed() OVERRIDE; 58 59 // Used for testing. 60 EnrollmentScreenActor* GetActor() { 61 return actor_; 62 } 63 64 // Used for testing. 65 void AddTestingObserver(TestingObserver* observer); 66 void RemoveTestingObserver(TestingObserver* observer); 67 68 private: 69 // Starts the Lockbox storage process. 70 void WriteInstallAttributesData(); 71 72 // Kicks off the policy infrastructure to register with the service. 73 void RegisterForDevicePolicy(const std::string& token); 74 75 // Handles enrollment completion. Logs a UMA sample and requests the actor to 76 // show the specified enrollment status. 77 void ReportEnrollmentStatus(policy::EnrollmentStatus status); 78 79 // Logs a UMA event in the kMetricEnrollment histogram. If auto-enrollment is 80 // on |sample| is ignored and a kMetricEnrollmentAutoFailed sample is logged 81 // instead. 82 void UMAFailure(int sample); 83 84 // Shows the signin screen. Used as a callback to run after auth reset. 85 void ShowSigninScreen(); 86 87 // Notifies testing observers about the result of the enrollment. 88 void NotifyTestingObservers(bool succeeded); 89 90 EnrollmentScreenActor* actor_; 91 bool is_auto_enrollment_; 92 bool can_exit_enrollment_; 93 bool enrollment_failed_once_; 94 std::string user_; 95 int lockbox_init_duration_; 96 base::WeakPtrFactory<EnrollmentScreen> weak_ptr_factory_; 97 98 // Observers. 99 ObserverList<TestingObserver, true> observers_; 100 101 DISALLOW_COPY_AND_ASSIGN(EnrollmentScreen); 102}; 103 104} // namespace chromeos 105 106#endif // CHROME_BROWSER_CHROMEOS_LOGIN_ENROLLMENT_ENROLLMENT_SCREEN_H_ 107