enrollment_screen.h revision 46d4c2bc3267f3f028f39e7e311b0f89aba2e4fd
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/policy/core/common/cloud/cloud_policy_constants.h"
17
18namespace chromeos {
19
20class ScreenObserver;
21
22// The screen implementation that links the enterprise enrollment UI into the
23// OOBE wizard.
24class EnrollmentScreen
25    : public WizardScreen,
26      public EnrollmentScreenActor::Controller {
27 public:
28  EnrollmentScreen(ScreenObserver* observer,
29                   EnrollmentScreenActor* actor);
30  virtual ~EnrollmentScreen();
31
32  void SetParameters(EnrollmentScreenActor::EnrollmentMode enrollment_mode,
33                     const std::string& management_domain,
34                     const std::string& enrollment_user);
35
36  // WizardScreen implementation:
37  virtual void PrepareToShow() OVERRIDE;
38  virtual void Show() OVERRIDE;
39  virtual void Hide() OVERRIDE;
40  virtual std::string GetName() const OVERRIDE;
41
42  // EnrollmentScreenActor::Controller implementation:
43  virtual void OnLoginDone(const std::string& user) OVERRIDE;
44  virtual void OnAuthError(const GoogleServiceAuthError& error) OVERRIDE;
45  virtual void OnOAuthTokenAvailable(const std::string& oauth_token) OVERRIDE;
46  virtual void OnRetry() OVERRIDE;
47  virtual void OnCancel() OVERRIDE;
48  virtual void OnConfirmationClosed() OVERRIDE;
49
50  // Used for testing.
51  EnrollmentScreenActor* GetActor() {
52    return actor_;
53  }
54
55 private:
56  FRIEND_TEST_ALL_PREFIXES(EnrollmentScreenTest, TestSuccess);
57
58  // Starts the Lockbox storage process.
59  void WriteInstallAttributesData();
60
61  // Kicks off the policy infrastructure to register with the service.
62  void RegisterForDevicePolicy(const std::string& token);
63
64  // Handles enrollment completion. Logs a UMA sample and requests the actor to
65  // show the specified enrollment status.
66  void ReportEnrollmentStatus(policy::EnrollmentStatus status);
67
68  // Shows successful enrollment status after all enrollment related file
69  // operations are completed.
70  void ShowEnrollmentStatusOnSuccess(const policy::EnrollmentStatus& status);
71
72  // Logs a UMA event in the kMetricEnrollment histogram. If auto-enrollment is
73  // on |sample| is ignored and a kMetricEnrollmentAutoFailed sample is logged
74  // instead.
75  void UMAFailure(int sample);
76
77  // Shows the signin screen. Used as a callback to run after auth reset.
78  void ShowSigninScreen();
79
80  // Convenience helper to check for auto enrollment mode.
81  bool is_auto_enrollment() const {
82    return enrollment_mode_ == EnrollmentScreenActor::ENROLLMENT_MODE_AUTO;
83  }
84
85  EnrollmentScreenActor* actor_;
86  EnrollmentScreenActor::EnrollmentMode enrollment_mode_;
87  bool enrollment_failed_once_;
88  std::string user_;
89  int lockbox_init_duration_;
90  base::WeakPtrFactory<EnrollmentScreen> weak_ptr_factory_;
91
92  DISALLOW_COPY_AND_ASSIGN(EnrollmentScreen);
93};
94
95}  // namespace chromeos
96
97#endif  // CHROME_BROWSER_CHROMEOS_LOGIN_ENROLLMENT_ENROLLMENT_SCREEN_H_
98