Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / login / enrollment / enrollment_screen.h
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/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"
19
20 namespace pairing_chromeos {
21 class ControllerPairingController;
22 }
23
24 namespace chromeos {
25
26 class ScreenManager;
27 class ScreenObserver;
28
29 // The screen implementation that links the enterprise enrollment UI into the
30 // OOBE wizard.
31 class EnrollmentScreen
32     : public WizardScreen,
33       public pairing_chromeos::HostPairingController::Observer,
34       public EnrollmentScreenActor::Controller {
35  public:
36   typedef pairing_chromeos::HostPairingController::Stage Stage;
37
38   EnrollmentScreen(ScreenObserver* observer,
39                    EnrollmentScreenActor* actor);
40   virtual ~EnrollmentScreen();
41
42   static EnrollmentScreen* Get(ScreenManager* manager);
43
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.
50   void SetParameters(
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);
57
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;
63
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,
69                              bool send_reports,
70                              const std::string& keyboard_layout) OVERRIDE;
71   virtual void EnrollHost(const std::string& auth_token) OVERRIDE;
72
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;
80
81   // Used for testing.
82   EnrollmentScreenActor* GetActor() {
83     return actor_;
84   }
85
86  private:
87   FRIEND_TEST_ALL_PREFIXES(EnrollmentScreenTest, TestSuccess);
88
89   // Starts the Lockbox storage process.
90   void WriteInstallAttributesData();
91
92   // Kicks off the policy infrastructure to register with the service.
93   void RegisterForDevicePolicy(const std::string& token);
94
95   // Sends an enrollment access token to a remote device.
96   void SendEnrollmentAuthToken(const std::string& token);
97
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);
101
102   // Shows successful enrollment status after all enrollment related file
103   // operations are completed.
104   void ShowEnrollmentStatusOnSuccess(const policy::EnrollmentStatus& status);
105
106   // Logs an UMA event in the kMetricEnrollment or the kMetricEnrollmentRecovery
107   // histogram, depending on |enrollment_mode_|.
108   void UMA(policy::MetricEnrollment sample);
109
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
113   // instead.
114   void UMAFailure(policy::MetricEnrollment sample);
115
116   // Shows the signin screen. Used as a callback to run after auth reset.
117   void ShowSigninScreen();
118
119   // Convenience helper to check for auto enrollment mode.
120   bool is_auto_enrollment() const {
121     return enrollment_mode_ == EnrollmentScreenActor::ENROLLMENT_MODE_AUTO;
122   }
123
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_;
130   std::string user_;
131   std::string auth_token_;
132   int lockbox_init_duration_;
133   base::WeakPtrFactory<EnrollmentScreen> weak_ptr_factory_;
134
135   DISALLOW_COPY_AND_ASSIGN(EnrollmentScreen);
136 };
137
138 }  // namespace chromeos
139
140 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_ENROLLMENT_ENROLLMENT_SCREEN_H_