Upstream version 11.39.250.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/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"
20
21 namespace base {
22 class ElapsedTimer;
23 }
24
25 namespace pairing_chromeos {
26 class ControllerPairingController;
27 }
28
29 namespace chromeos {
30
31 class ScreenManager;
32 class ScreenObserver;
33
34 // The screen implementation that links the enterprise enrollment UI into the
35 // OOBE wizard.
36 class EnrollmentScreen
37     : public WizardScreen,
38       public pairing_chromeos::HostPairingController::Observer,
39       public EnrollmentScreenActor::Controller {
40  public:
41   typedef pairing_chromeos::HostPairingController::Stage Stage;
42
43   EnrollmentScreen(ScreenObserver* observer,
44                    EnrollmentScreenActor* actor);
45   virtual ~EnrollmentScreen();
46
47   static EnrollmentScreen* Get(ScreenManager* manager);
48
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.
55   void SetParameters(
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);
62
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;
68
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,
74                              bool send_reports,
75                              const std::string& keyboard_layout) OVERRIDE;
76   virtual void EnrollHost(const std::string& auth_token) OVERRIDE;
77
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;
85
86   // Used for testing.
87   EnrollmentScreenActor* GetActor() {
88     return actor_;
89   }
90
91  private:
92   FRIEND_TEST_ALL_PREFIXES(EnrollmentScreenTest, TestSuccess);
93
94   // Starts the Lockbox storage process.
95   void WriteInstallAttributesData();
96
97   // Kicks off the policy infrastructure to register with the service.
98   void RegisterForDevicePolicy(const std::string& token);
99
100   // Sends an enrollment access token to a remote device.
101   void SendEnrollmentAuthToken(const std::string& token);
102
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);
106
107   // Shows successful enrollment status after all enrollment related file
108   // operations are completed.
109   void ShowEnrollmentStatusOnSuccess(const policy::EnrollmentStatus& status);
110
111   // Logs an UMA event in the kMetricEnrollment or the kMetricEnrollmentRecovery
112   // histogram, depending on |enrollment_mode_|.
113   void UMA(policy::MetricEnrollment sample);
114
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
118   // instead.
119   void UMAFailure(policy::MetricEnrollment sample);
120
121   // Shows the signin screen. Used as a callback to run after auth reset.
122   void ShowSigninScreen();
123
124   // Convenience helper to check for auto enrollment mode.
125   bool is_auto_enrollment() const {
126     return enrollment_mode_ == EnrollmentScreenActor::ENROLLMENT_MODE_AUTO;
127   }
128
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_;
135   std::string user_;
136   std::string auth_token_;
137   int lockbox_init_duration_;
138   scoped_ptr<base::ElapsedTimer> elapsed_timer_;
139   base::WeakPtrFactory<EnrollmentScreen> weak_ptr_factory_;
140
141   DISALLOW_COPY_AND_ASSIGN(EnrollmentScreen);
142 };
143
144 }  // namespace chromeos
145
146 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_ENROLLMENT_ENROLLMENT_SCREEN_H_