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/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
15 #include "chrome/browser/chromeos/login/enrollment/enrollment_screen_actor.h"
16 #include "chrome/browser/chromeos/login/screens/wizard_screen.h"
17 #include "components/pairing/host_pairing_controller.h"
18 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
19 #include "components/policy/core/common/cloud/enterprise_metrics.h"
25 namespace pairing_chromeos {
26 class ControllerPairingController;
34 // The screen implementation that links the enterprise enrollment UI into the
36 class EnrollmentScreen
37 : public WizardScreen,
38 public pairing_chromeos::HostPairingController::Observer,
39 public EnrollmentScreenActor::Controller {
41 typedef pairing_chromeos::HostPairingController::Stage Stage;
43 EnrollmentScreen(ScreenObserver* observer,
44 EnrollmentScreenActor* actor);
45 virtual ~EnrollmentScreen();
47 static EnrollmentScreen* Get(ScreenManager* manager);
49 // Setup how this screen will handle enrollment.
50 // |auth_token| is an optional OAuth token to attempt to enroll with.
51 // |shark_controller| is an interface that is used to communicate with a
52 // remora device for remote enrollment.
53 // |remora_controller| is an interface that is used to communicate with a
54 // shark device for remote enrollment.
56 EnrollmentScreenActor::EnrollmentMode enrollment_mode,
57 const std::string& management_domain,
58 const std::string& enrollment_user,
59 const std::string& auth_token,
60 pairing_chromeos::ControllerPairingController* shark_controller,
61 pairing_chromeos::HostPairingController* remora_controller);
63 // WizardScreen implementation:
64 virtual void PrepareToShow() OVERRIDE;
65 virtual void Show() OVERRIDE;
66 virtual void Hide() OVERRIDE;
67 virtual std::string GetName() const OVERRIDE;
69 // pairing_chromeos::HostPairingController::Observer:
70 virtual void PairingStageChanged(Stage new_stage) OVERRIDE;
71 virtual void ConfigureHost(bool accepted_eula,
72 const std::string& lang,
73 const std::string& timezone,
75 const std::string& keyboard_layout) OVERRIDE;
76 virtual void EnrollHost(const std::string& auth_token) OVERRIDE;
78 // EnrollmentScreenActor::Controller implementation:
79 virtual void OnLoginDone(const std::string& user) OVERRIDE;
80 virtual void OnAuthError(const GoogleServiceAuthError& error) OVERRIDE;
81 virtual void OnOAuthTokenAvailable(const std::string& oauth_token) OVERRIDE;
82 virtual void OnRetry() OVERRIDE;
83 virtual void OnCancel() OVERRIDE;
84 virtual void OnConfirmationClosed() OVERRIDE;
87 EnrollmentScreenActor* GetActor() {
92 FRIEND_TEST_ALL_PREFIXES(EnrollmentScreenTest, TestSuccess);
94 // Starts the Lockbox storage process.
95 void WriteInstallAttributesData();
97 // Kicks off the policy infrastructure to register with the service.
98 void RegisterForDevicePolicy(const std::string& token);
100 // Sends an enrollment access token to a remote device.
101 void SendEnrollmentAuthToken(const std::string& token);
103 // Handles enrollment completion. Logs a UMA sample and requests the actor to
104 // show the specified enrollment status.
105 void ReportEnrollmentStatus(policy::EnrollmentStatus status);
107 // Shows successful enrollment status after all enrollment related file
108 // operations are completed.
109 void ShowEnrollmentStatusOnSuccess(const policy::EnrollmentStatus& status);
111 // Logs an UMA event in the kMetricEnrollment or the kMetricEnrollmentRecovery
112 // histogram, depending on |enrollment_mode_|.
113 void UMA(policy::MetricEnrollment sample);
115 // Logs an UMA event in the kMetricEnrollment or the kMetricEnrollmentRecovery
116 // histogram, depending on |enrollment_mode_|. If auto-enrollment is on,
117 // |sample| is ignored and a kMetricEnrollmentAutoFailed sample is logged
119 void UMAFailure(policy::MetricEnrollment sample);
121 // Shows the signin screen. Used as a callback to run after auth reset.
122 void ShowSigninScreen();
124 // Convenience helper to check for auto enrollment mode.
125 bool is_auto_enrollment() const {
126 return enrollment_mode_ == EnrollmentScreenActor::ENROLLMENT_MODE_AUTO;
129 pairing_chromeos::ControllerPairingController* shark_controller_;
130 pairing_chromeos::HostPairingController* remora_controller_;
131 EnrollmentScreenActor* actor_;
132 EnrollmentScreenActor::EnrollmentMode enrollment_mode_;
133 bool enrollment_failed_once_;
134 bool remora_token_sent_;
136 std::string auth_token_;
137 int lockbox_init_duration_;
138 scoped_ptr<base::ElapsedTimer> elapsed_timer_;
139 base::WeakPtrFactory<EnrollmentScreen> weak_ptr_factory_;
141 DISALLOW_COPY_AND_ASSIGN(EnrollmentScreen);
144 } // namespace chromeos
146 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_ENROLLMENT_ENROLLMENT_SCREEN_H_