Elim cr-checkbox
[chromium-blink-merge.git] / chrome / browser / chromeos / login / enrollment / enrollment_screen.h
blobb932144d45bf9f20567b7e849f87ebd561919d30
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_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/callback_forward.h"
12 #include "base/compiler_specific.h"
13 #include "base/gtest_prod_util.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h"
16 #include "chrome/browser/chromeos/login/enrollment/enrollment_screen_actor.h"
17 #include "chrome/browser/chromeos/login/enrollment/enterprise_enrollment_helper.h"
18 #include "chrome/browser/chromeos/login/screens/base_screen.h"
19 #include "chrome/browser/chromeos/policy/enrollment_config.h"
20 #include "components/pairing/host_pairing_controller.h"
21 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
22 #include "components/policy/core/common/cloud/enterprise_metrics.h"
24 namespace base {
25 class ElapsedTimer;
28 namespace pairing_chromeos {
29 class ControllerPairingController;
32 namespace chromeos {
34 class BaseScreenDelegate;
35 class ScreenManager;
37 // The screen implementation that links the enterprise enrollment UI into the
38 // OOBE wizard.
39 class EnrollmentScreen
40 : public BaseScreen,
41 public pairing_chromeos::HostPairingController::Observer,
42 public EnterpriseEnrollmentHelper::EnrollmentStatusConsumer,
43 public EnrollmentScreenActor::Controller {
44 public:
45 typedef pairing_chromeos::HostPairingController::Stage Stage;
47 EnrollmentScreen(BaseScreenDelegate* base_screen_delegate,
48 EnrollmentScreenActor* actor);
49 ~EnrollmentScreen() override;
51 static EnrollmentScreen* Get(ScreenManager* manager);
53 // Setup how this screen will handle enrollment.
54 // |shark_controller| is an interface that is used to communicate with a
55 // remora device for remote enrollment.
56 // |remora_controller| is an interface that is used to communicate with a
57 // shark device for remote enrollment.
58 void SetParameters(
59 const policy::EnrollmentConfig& enrollment_config,
60 pairing_chromeos::ControllerPairingController* shark_controller,
61 pairing_chromeos::HostPairingController* remora_controller);
63 // BaseScreen implementation:
64 void PrepareToShow() override;
65 void Show() override;
66 void Hide() override;
67 std::string GetName() const override;
69 // pairing_chromeos::HostPairingController::Observer:
70 void PairingStageChanged(Stage new_stage) override;
71 void EnrollHostRequested(const std::string& auth_token) override;
73 // EnrollmentScreenActor::Controller implementation:
74 void OnLoginDone(const std::string& user,
75 const std::string& auth_code) override;
76 void OnRetry() override;
77 void OnCancel() override;
78 void OnConfirmationClosed() override;
79 void OnDeviceAttributeProvided(const std::string& asset_id,
80 const std::string& location) override;
82 // EnterpriseEnrollmentHelper::EnrollmentStatusConsumer implementation:
83 void OnAuthError(const GoogleServiceAuthError& error) override;
84 void OnEnrollmentError(policy::EnrollmentStatus status) override;
85 void OnOtherError(EnterpriseEnrollmentHelper::OtherError error) override;
86 void OnDeviceEnrolled(const std::string& additional_token) override;
87 void OnDeviceAttributeUploadCompleted(bool success) override;
88 void OnDeviceAttributeUpdatePermission(bool granted) override;
90 // Used for testing.
91 EnrollmentScreenActor* GetActor() {
92 return actor_;
95 private:
96 FRIEND_TEST_ALL_PREFIXES(EnrollmentScreenTest, TestSuccess);
98 // Creates an enrollment helper.
99 void CreateEnrollmentHelper();
101 // Clears auth in |enrollment_helper_|. Deletes |enrollment_helper_| and runs
102 // |callback| on completion. See the comment for
103 // EnterpriseEnrollmentHelper::ClearAuth for details.
104 void ClearAuth(const base::Closure& callback);
106 // Used as a callback for EnterpriseEnrollmentHelper::ClearAuth.
107 virtual void OnAuthCleared(const base::Closure& callback);
109 // Sends an enrollment access token to a remote device.
110 void SendEnrollmentAuthToken(const std::string& token);
112 // Shows successful enrollment status after all enrollment related file
113 // operations are completed.
114 void ShowEnrollmentStatusOnSuccess();
116 // Logs an UMA event in one of the "Enrollment.*" histograms, depending on
117 // |enrollment_mode_|.
118 void UMA(policy::MetricEnrollment sample);
120 // Shows the signin screen. Used as a callback to run after auth reset.
121 void ShowSigninScreen();
123 // Shows the device attribute prompt screen.
124 // Used as a callback to run after successful enrollment.
125 void ShowAttributePromptScreen();
127 void OnAnyEnrollmentError();
129 pairing_chromeos::ControllerPairingController* shark_controller_;
130 pairing_chromeos::HostPairingController* remora_controller_;
131 EnrollmentScreenActor* actor_;
132 policy::EnrollmentConfig enrollment_config_;
133 bool enrollment_failed_once_;
134 std::string enrolling_user_domain_;
135 scoped_ptr<base::ElapsedTimer> elapsed_timer_;
136 scoped_ptr<EnterpriseEnrollmentHelper> enrollment_helper_;
137 base::WeakPtrFactory<EnrollmentScreen> weak_ptr_factory_;
139 DISALLOW_COPY_AND_ASSIGN(EnrollmentScreen);
142 } // namespace chromeos
144 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_ENROLLMENT_ENROLLMENT_SCREEN_H_