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.
5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_ENROLLMENT_ENROLLMENT_SCREEN_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_ENROLLMENT_ENROLLMENT_SCREEN_H_
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/gtest_prod_util.h"
13 #include "base/memory/weak_ptr.h"
14 #include "chrome/browser/chromeos/login/enrollment/enrollment_screen_actor.h"
15 #include "chrome/browser/chromeos/login/screens/wizard_screen.h"
16 #include "components/pairing/host_pairing_controller.h"
17 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
18 #include "components/policy/core/common/cloud/enterprise_metrics.h"
20 namespace pairing_chromeos {
21 class ControllerPairingController;
29 // The screen implementation that links the enterprise enrollment UI into the
31 class EnrollmentScreen
32 : public WizardScreen,
33 public pairing_chromeos::HostPairingController::Observer,
34 public EnrollmentScreenActor::Controller {
36 typedef pairing_chromeos::HostPairingController::Stage Stage;
38 EnrollmentScreen(ScreenObserver* observer,
39 EnrollmentScreenActor* actor);
40 virtual ~EnrollmentScreen();
42 static EnrollmentScreen* Get(ScreenManager* manager);
44 // Setup how this screen will handle enrollment.
45 // |auth_token| is an optional OAuth token to attempt to enroll with.
46 // |shark_controller| is an interface that is used to communicate with a
47 // remora device for remote enrollment.
48 // |remora_controller| is an interface that is used to communicate with a
49 // shark device for remote enrollment.
51 EnrollmentScreenActor::EnrollmentMode enrollment_mode,
52 const std::string& management_domain,
53 const std::string& enrollment_user,
54 const std::string& auth_token,
55 pairing_chromeos::ControllerPairingController* shark_controller,
56 pairing_chromeos::HostPairingController* remora_controller);
58 // WizardScreen implementation:
59 virtual void PrepareToShow() OVERRIDE;
60 virtual void Show() OVERRIDE;
61 virtual void Hide() OVERRIDE;
62 virtual std::string GetName() const OVERRIDE;
64 // pairing_chromeos::HostPairingController::Observer:
65 virtual void PairingStageChanged(Stage new_stage) OVERRIDE;
66 virtual void ConfigureHost(bool accepted_eula,
67 const std::string& lang,
68 const std::string& timezone,
70 const std::string& keyboard_layout) OVERRIDE;
71 virtual void EnrollHost(const std::string& auth_token) OVERRIDE;
73 // EnrollmentScreenActor::Controller implementation:
74 virtual void OnLoginDone(const std::string& user) OVERRIDE;
75 virtual void OnAuthError(const GoogleServiceAuthError& error) OVERRIDE;
76 virtual void OnOAuthTokenAvailable(const std::string& oauth_token) OVERRIDE;
77 virtual void OnRetry() OVERRIDE;
78 virtual void OnCancel() OVERRIDE;
79 virtual void OnConfirmationClosed() OVERRIDE;
82 EnrollmentScreenActor* GetActor() {
87 FRIEND_TEST_ALL_PREFIXES(EnrollmentScreenTest, TestSuccess);
89 // Starts the Lockbox storage process.
90 void WriteInstallAttributesData();
92 // Kicks off the policy infrastructure to register with the service.
93 void RegisterForDevicePolicy(const std::string& token);
95 // Sends an enrollment access token to a remote device.
96 void SendEnrollmentAuthToken(const std::string& token);
98 // Handles enrollment completion. Logs a UMA sample and requests the actor to
99 // show the specified enrollment status.
100 void ReportEnrollmentStatus(policy::EnrollmentStatus status);
102 // Shows successful enrollment status after all enrollment related file
103 // operations are completed.
104 void ShowEnrollmentStatusOnSuccess(const policy::EnrollmentStatus& status);
106 // Logs an UMA event in the kMetricEnrollment or the kMetricEnrollmentRecovery
107 // histogram, depending on |enrollment_mode_|.
108 void UMA(policy::MetricEnrollment sample);
110 // Logs an UMA event in the kMetricEnrollment or the kMetricEnrollmentRecovery
111 // histogram, depending on |enrollment_mode_|. If auto-enrollment is on,
112 // |sample| is ignored and a kMetricEnrollmentAutoFailed sample is logged
114 void UMAFailure(policy::MetricEnrollment sample);
116 // Shows the signin screen. Used as a callback to run after auth reset.
117 void ShowSigninScreen();
119 // Convenience helper to check for auto enrollment mode.
120 bool is_auto_enrollment() const {
121 return enrollment_mode_ == EnrollmentScreenActor::ENROLLMENT_MODE_AUTO;
124 pairing_chromeos::ControllerPairingController* shark_controller_;
125 pairing_chromeos::HostPairingController* remora_controller_;
126 EnrollmentScreenActor* actor_;
127 EnrollmentScreenActor::EnrollmentMode enrollment_mode_;
128 bool enrollment_failed_once_;
129 bool remora_token_sent_;
131 std::string auth_token_;
132 int lockbox_init_duration_;
133 base::WeakPtrFactory<EnrollmentScreen> weak_ptr_factory_;
135 DISALLOW_COPY_AND_ASSIGN(EnrollmentScreen);
138 } // namespace chromeos
140 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_ENROLLMENT_ENROLLMENT_SCREEN_H_