Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / login / enrollment / auto_enrollment_check_screen.h
1 // Copyright 2014 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_AUTO_ENROLLMENT_CHECK_SCREEN_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_ENROLLMENT_AUTO_ENROLLMENT_CHECK_SCREEN_H_
7
8 #include "base/compiler_specific.h"
9 #include "base/macros.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "chrome/browser/chromeos/login/enrollment/auto_enrollment_check_screen_actor.h"
12 #include "chrome/browser/chromeos/login/enrollment/auto_enrollment_controller.h"
13 #include "chrome/browser/chromeos/login/screens/error_screen.h"
14 #include "chromeos/network/portal_detector/network_portal_detector.h"
15
16 namespace chromeos {
17
18 class ScreenManager;
19 class ScreenObserver;
20
21 // Handles the control flow after OOBE auto-update completes to wait for the
22 // enterprise auto-enrollment check that happens as part of OOBE. This includes
23 // keeping track of current auto-enrollment state and displaying and updating
24 // the error screen upon failures. Similar to a screen controller, but it
25 // doesn't actually drive a dedicated screen.
26 class AutoEnrollmentCheckScreen
27     : public AutoEnrollmentCheckScreenActor::Delegate,
28       public WizardScreen,
29       public NetworkPortalDetector::Observer {
30  public:
31   AutoEnrollmentCheckScreen(
32       ScreenObserver* observer,
33       AutoEnrollmentCheckScreenActor* actor);
34   virtual ~AutoEnrollmentCheckScreen();
35
36   static AutoEnrollmentCheckScreen* Get(ScreenManager* manager);
37
38   // Hands over OOBE control to this AutoEnrollmentCheckStep. It'll return the
39   // flow back to the caller via the |screen_observer_|'s OnExit function.
40   void Start();
41
42   void set_auto_enrollment_controller(
43       AutoEnrollmentController* auto_enrollment_controller) {
44     auto_enrollment_controller_ = auto_enrollment_controller;
45   }
46
47   // WizardScreen implementation:
48   virtual void PrepareToShow() OVERRIDE;
49   virtual void Show() OVERRIDE;
50   virtual void Hide() OVERRIDE;
51   virtual std::string GetName() const OVERRIDE;
52
53   // AutoEnrollmentCheckScreenActor::Delegate implementation:
54   virtual void OnExit() OVERRIDE;
55   virtual void OnActorDestroyed(AutoEnrollmentCheckScreenActor* actor) OVERRIDE;
56
57   // NetworkPortalDetector::Observer implementation:
58   virtual void OnPortalDetectionCompleted(
59       const NetworkState* network,
60       const NetworkPortalDetector::CaptivePortalState& state) OVERRIDE;
61
62  private:
63   // Handles update notifications regarding the auto-enrollment check.
64   void OnAutoEnrollmentCheckProgressed(policy::AutoEnrollmentState state);
65
66   // Handles a state update, updating the UI and saving the state.
67   void UpdateState(
68       NetworkPortalDetector::CaptivePortalStatus new_captive_portal_status,
69       policy::AutoEnrollmentState new_auto_enrollment_state);
70
71   // Configures the UI to reflect |new_captive_portal_status|. Returns true if
72   // and only if a UI change has been made.
73   bool UpdateCaptivePortalStatus(
74       NetworkPortalDetector::CaptivePortalStatus new_captive_portal_status);
75
76   // Configures the UI to reflect |auto_enrollment_state|. Returns true if and
77   // only if a UI change has been made.
78   bool UpdateAutoEnrollmentState(
79       policy::AutoEnrollmentState auto_enrollment_state);
80
81   // Configures the error screen.
82   void ShowErrorScreen(ErrorScreen::ErrorState error_state);
83
84   // Signals completion. No further code should run after a call to this
85   // function as the owner might destroy |this| in response.
86   void SignalCompletion();
87
88   // Checks if the enrollment status check is needed. It can be disabled either
89   // by command line flags, build configuration or might have finished already.
90   bool IsStartNeeded();
91
92   AutoEnrollmentCheckScreenActor* actor_;
93   AutoEnrollmentController* auto_enrollment_controller_;
94
95   scoped_ptr<AutoEnrollmentController::ProgressCallbackList::Subscription>
96       auto_enrollment_progress_subscription_;
97
98   NetworkPortalDetector::CaptivePortalStatus captive_portal_status_;
99   policy::AutoEnrollmentState auto_enrollment_state_;
100
101   DISALLOW_COPY_AND_ASSIGN(AutoEnrollmentCheckScreen);
102 };
103
104 }  // namespace chromeos
105
106 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_ENROLLMENT_AUTO_ENROLLMENT_CHECK_SCREEN_H_