1// Copyright (c) 2011 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_WIZARD_CONTROLLER_H_
6#define CHROME_BROWSER_CHROMEOS_LOGIN_WIZARD_CONTROLLER_H_
7#pragma once
8
9#include <string>
10
11#include "base/gtest_prod_util.h"
12#include "base/memory/scoped_ptr.h"
13#include "base/timer.h"
14#include "chrome/browser/chromeos/login/screen_observer.h"
15#include "chrome/browser/chromeos/login/wizard_screen.h"
16#include "googleurl/src/gurl.h"
17#include "testing/gtest/include/gtest/gtest_prod.h"
18#include "ui/gfx/rect.h"
19
20class PrefService;
21class WizardContentsView;
22class WizardScreen;
23
24namespace chromeos {
25class AccountScreen;
26class EnterpriseEnrollmentScreen;
27class EulaScreen;
28class ExistingUserController;
29class HTMLPageScreen;
30class LoginDisplayHost;
31class NetworkScreen;
32class RegistrationScreen;
33class UpdateScreen;
34class UserImageScreen;
35class WizardInProcessBrowserTest;
36}
37
38namespace gfx {
39class Rect;
40}
41
42namespace views {
43class Views;
44class Widget;
45class WidgetGtk;
46}
47
48// Class that manages control flow between wizard screens. Wizard controller
49// interacts with screen controllers to move the user between screens.
50class WizardController : public chromeos::ScreenObserver,
51                         public WizardScreenDelegate {
52 public:
53  explicit WizardController(chromeos::LoginDisplayHost* host,
54                            const gfx::Rect& screen_bounds);
55  ~WizardController();
56
57  // Returns the default wizard controller if it has been created.
58  static WizardController* default_controller() {
59    return default_controller_;
60  }
61
62  // Returns true if EULA has been accepted.
63  static bool IsEulaAccepted();
64
65  // Returns OOBE completion status.
66  static bool IsOobeCompleted();
67
68  // Marks EULA status as accepted.
69  static void MarkEulaAccepted();
70
71  // Marks OOBE process as completed.
72  static void MarkOobeCompleted();
73
74  // Returns device registration completion status, i.e. second part of OOBE.
75  static bool IsDeviceRegistered();
76
77  // Returns true if valid registration URL is defined.
78  static bool IsRegisterScreenDefined();
79
80  // Marks device registered. i.e. second part of OOBE is completed.
81  static void MarkDeviceRegistered();
82
83  // Returns initial locale from local settings.
84  static std::string GetInitialLocale();
85
86  // Sets initial locale in local settings.
87  static void SetInitialLocale(const std::string& locale);
88
89  // Shows the first screen defined by |first_screen_name| or by default
90  // if the parameter is empty. |screen_bounds| are used to calculate position
91  // of the wizard screen.
92  void Init(const std::string& first_screen_name);
93
94  // Returns the view that contains all the other views.
95  views::View* contents() { return contents_; }
96
97  // Skips OOBE update screen if it's currently shown.
98  void CancelOOBEUpdate();
99
100  // Lazy initializers and getters for screens.
101  chromeos::NetworkScreen* GetNetworkScreen();
102  chromeos::AccountScreen* GetAccountScreen();
103  chromeos::UpdateScreen* GetUpdateScreen();
104  chromeos::UserImageScreen* GetUserImageScreen();
105  chromeos::EulaScreen* GetEulaScreen();
106  chromeos::RegistrationScreen* GetRegistrationScreen();
107  chromeos::HTMLPageScreen* GetHTMLPageScreen();
108  chromeos::EnterpriseEnrollmentScreen* GetEnterpriseEnrollmentScreen();
109
110  // Show specific screen.
111  void ShowNetworkScreen();
112  void ShowAccountScreen();
113  void ShowUpdateScreen();
114  void ShowUserImageScreen();
115  void ShowEulaScreen();
116  void ShowRegistrationScreen();
117  void ShowHTMLPageScreen();
118  void ShowEnterpriseEnrollmentScreen();
119
120  // Shows images login screen.
121  void ShowLoginScreen();
122
123  // Returns a pointer to the current screen or NULL if there's no such
124  // screen.
125  WizardScreen* current_screen() const { return current_screen_; }
126
127  // Overrides observer for testing.
128  void set_observer(ScreenObserver* observer) { observer_ = observer; }
129
130  // Set URL to open on browser launch.
131  void set_start_url(const GURL& start_url) { start_url_ = start_url; }
132
133  // If being at register screen proceeds to the next one.
134  void SkipRegistration();
135
136  // Registers OOBE preferences.
137  static void RegisterPrefs(PrefService* local_state);
138
139  static const char kNetworkScreenName[];
140  static const char kLoginScreenName[];
141  static const char kAccountScreenName[];
142  static const char kUpdateScreenName[];
143  static const char kUserImageScreenName[];
144  static const char kRegistrationScreenName[];
145  static const char kOutOfBoxScreenName[];
146  static const char kTestNoScreenName[];
147  static const char kEulaScreenName[];
148  static const char kHTMLPageScreenName[];
149  static const char kEnterpriseEnrollmentScreenName[];
150
151 private:
152  // Exit handlers:
153  void OnNetworkConnected();
154  void OnNetworkOffline();
155  void OnAccountCreateBack();
156  void OnAccountCreated();
157  void OnConnectionFailed();
158  void OnUpdateCompleted();
159  void OnEulaAccepted();
160  void OnUpdateErrorCheckingForUpdate();
161  void OnUpdateErrorUpdating();
162  void OnUserImageSelected();
163  void OnUserImageSkipped();
164  void OnRegistrationSuccess();
165  void OnRegistrationSkipped();
166  void OnEnterpriseEnrollmentDone();
167  void OnOOBECompleted();
168
169  // Shows update screen and starts update process.
170  void InitiateOOBEUpdate();
171
172  // Overridden from chromeos::ScreenObserver:
173  virtual void OnExit(ExitCodes exit_code);
174  virtual void OnSetUserNamePassword(const std::string& username,
175                                     const std::string& password);
176  virtual void set_usage_statistics_reporting(bool val) {
177    usage_statistics_reporting_ = val;
178  }
179  virtual bool usage_statistics_reporting() const {
180    return usage_statistics_reporting_;
181  }
182
183  // Creates wizard screen window with the specified |bounds|.
184  // If |initial_show| initial animation (window & background) is shown.
185  // Otherwise only window is animated.
186  views::Widget* CreateScreenWindow(const gfx::Rect& bounds,
187                                    bool initial_show);
188
189  // Returns bounds for the wizard screen host window in screen coordinates.
190  // Calculates bounds using screen_bounds_.
191  gfx::Rect GetWizardScreenBounds(int screen_width, int screen_height) const;
192
193  // Switches from one screen to another.
194  void SetCurrentScreen(WizardScreen* screen);
195
196  // Switches from one screen to another with delay before showing. Calling
197  // ShowCurrentScreen directly forces screen to be shown immediately.
198  void SetCurrentScreenSmooth(WizardScreen* screen, bool use_smoothing);
199
200  // Changes status area visibility.
201  void SetStatusAreaVisible(bool visible);
202
203  // Overridden from WizardScreenDelegate:
204  virtual views::View* GetWizardView();
205  virtual chromeos::ScreenObserver* GetObserver(WizardScreen* screen);
206  virtual void ShowCurrentScreen();
207
208  // Determines which screen to show first by the parameter, shows it and
209  // sets it as the current one.
210  void ShowFirstScreen(const std::string& first_screen_name);
211
212  // Logs in the specified user via default login screen.
213  void Login(const std::string& username, const std::string& password);
214
215  // Sets delays to zero. MUST be used only for browser tests.
216  static void SetZeroDelays();
217
218  // Widget we're showing in.
219  views::Widget* widget_;
220
221  // Contents view.
222  views::View* contents_;
223
224  // Used to calculate position of the wizard screen.
225  gfx::Rect screen_bounds_;
226
227  // Screens.
228  scoped_ptr<chromeos::NetworkScreen> network_screen_;
229  scoped_ptr<chromeos::AccountScreen> account_screen_;
230  scoped_ptr<chromeos::UpdateScreen> update_screen_;
231  scoped_ptr<chromeos::UserImageScreen> user_image_screen_;
232  scoped_ptr<chromeos::EulaScreen> eula_screen_;
233  scoped_ptr<chromeos::RegistrationScreen> registration_screen_;
234  scoped_ptr<chromeos::HTMLPageScreen> html_page_screen_;
235  scoped_ptr<chromeos::EnterpriseEnrollmentScreen>
236      enterprise_enrollment_screen_;
237
238  // Screen that's currently active.
239  WizardScreen* current_screen_;
240
241  // Holds whether this is initial show.
242  bool initial_show_;
243
244  std::string username_;
245  std::string password_;
246
247  // True if controller is active and should proceed things like Timer.
248  bool is_active_;
249
250  // True if running official BUILD.
251  bool is_official_build_;
252
253  // True if full OOBE flow should be shown.
254  bool is_out_of_box_;
255
256  // Value of the screen name that WizardController was started with.
257  std::string first_screen_name_;
258
259  // OOBE/login display host.
260  chromeos::LoginDisplayHost* host_;
261
262  // NULL by default - controller itself is observer. Mock could be assigned.
263  ScreenObserver* observer_;
264
265  // Default WizardController.
266  static WizardController* default_controller_;
267
268  // URL to open on browser launch.
269  GURL start_url_;
270
271  base::OneShotTimer<WizardController> smooth_show_timer_;
272
273  // State of Usage stat/error reporting checkbox on EULA screen
274  // during wizard lifetime.
275  bool usage_statistics_reporting_;
276
277  FRIEND_TEST_ALL_PREFIXES(WizardControllerTest, SwitchLanguage);
278  friend class WizardControllerFlowTest;
279  friend class chromeos::WizardInProcessBrowserTest;
280
281  DISALLOW_COPY_AND_ASSIGN(WizardController);
282};
283
284#endif  // CHROME_BROWSER_CHROMEOS_LOGIN_WIZARD_CONTROLLER_H_
285