app_launch_controller.h revision 1e9bf3e0803691d0a228da41fc608347b6db4340
1// Copyright 2013 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_APP_LAUNCH_CONTROLLER_H_
6#define CHROME_BROWSER_CHROMEOS_LOGIN_APP_LAUNCH_CONTROLLER_H_
7
8#include <string>
9
10#include "base/basictypes.h"
11#include "base/callback_forward.h"
12#include "base/memory/ref_counted.h"
13#include "base/memory/weak_ptr.h"
14#include "base/timer/timer.h"
15#include "chrome/browser/chromeos/app_mode/kiosk_app_launch_error.h"
16#include "chrome/browser/chromeos/app_mode/kiosk_profile_loader.h"
17#include "chrome/browser/chromeos/app_mode/startup_app_launcher.h"
18#include "chrome/browser/chromeos/login/app_launch_signin_screen.h"
19#include "chrome/browser/chromeos/login/screens/app_launch_splash_screen_actor.h"
20#include "chrome/browser/chromeos/login/screens/error_screen_actor.h"
21#include "content/public/browser/notification_observer.h"
22#include "content/public/browser/notification_registrar.h"
23
24class Profile;
25
26namespace chromeos {
27
28class LoginDisplayHost;
29class OobeDisplay;
30class UserManager;
31
32// Controller for the kiosk app launch process, responsible for
33// coordinating loading the kiosk profile, launching the app, and
34// updating the splash screen UI.
35class AppLaunchController
36    : public base::SupportsWeakPtr<AppLaunchController>,
37      public AppLaunchSplashScreenActor::Delegate,
38      public KioskProfileLoader::Delegate,
39      public StartupAppLauncher::Observer,
40      public AppLaunchSigninScreen::Delegate,
41      public content::NotificationObserver {
42 public:
43  AppLaunchController(const std::string& app_id,
44                      LoginDisplayHost* host,
45                      OobeDisplay* oobe_display);
46
47  virtual ~AppLaunchController();
48
49  void StartAppLaunch();
50
51  bool waiting_for_network() { return waiting_for_network_; }
52  bool network_wait_timedout() { return network_wait_timedout_; }
53  bool showing_network_dialog() { return showing_network_dialog_; }
54
55  // Customize controller for testing purposes.
56  static void SkipSplashWaitForTesting();
57  static void SetNetworkTimeoutCallbackForTesting(base::Closure* callback);
58  static void SetNetworkWaitForTesting(int wait_time_secs);
59  static void SetUserManagerForTesting(UserManager* user_manager);
60
61 private:
62  // A class to watch app window creation.
63  class AppWindowWatcher;
64
65  void CleanUp();
66  void OnNetworkWaitTimedout();
67  UserManager* GetUserManager();
68
69  // Callback of AppWindowWatcher to notify an app window is created.
70  void OnAppWindowCreated();
71
72  // KioskProfileLoader::Delegate overrides:
73  virtual void OnProfileLoaded(Profile* profile) OVERRIDE;
74  virtual void OnProfileLoadFailed(KioskAppLaunchError::Error error) OVERRIDE;
75
76  // AppLaunchSplashScreenActor::Delegate overrides:
77  virtual void OnConfigureNetwork() OVERRIDE;
78  virtual void OnCancelAppLaunch() OVERRIDE;
79
80  // StartupAppLauncher::Observer overrides:
81  virtual void OnLoadingOAuthFile() OVERRIDE;
82  virtual void OnInitializingTokenService() OVERRIDE;
83  virtual void OnInitializingNetwork() OVERRIDE;
84  virtual void OnInstallingApp() OVERRIDE;
85  virtual void OnReadyToLaunch() OVERRIDE;
86  virtual void OnLaunchSucceeded() OVERRIDE;
87  virtual void OnLaunchFailed(KioskAppLaunchError::Error error) OVERRIDE;
88
89  // AppLaunchSigninScreen::Delegate overrides:
90  virtual void OnOwnerSigninSuccess() OVERRIDE;
91
92  // content::NotificationObserver overrides:
93  virtual void Observe(int type,
94                       const content::NotificationSource& source,
95                       const content::NotificationDetails& details) OVERRIDE;
96
97  Profile* profile_;
98  const std::string app_id_;
99  LoginDisplayHost* host_;
100  OobeDisplay* oobe_display_;
101  AppLaunchSplashScreenActor* app_launch_splash_screen_actor_;
102  ErrorScreenActor* error_screen_actor_;
103  scoped_ptr<KioskProfileLoader> kiosk_profile_loader_;
104  scoped_ptr<StartupAppLauncher> startup_app_launcher_;
105  scoped_ptr<AppLaunchSigninScreen> signin_screen_;
106  scoped_ptr<AppWindowWatcher> app_window_watcher_;
107
108  content::NotificationRegistrar registrar_;
109  bool webui_visible_;
110  bool launcher_ready_;
111
112  base::OneShotTimer<AppLaunchController> network_wait_timer_;
113  bool waiting_for_network_;
114  bool network_wait_timedout_;
115  bool showing_network_dialog_;
116  int64 launch_splash_start_time_;
117
118  static bool skip_splash_wait_;
119  static int network_wait_time_;
120  static base::Closure* network_timeout_callback_;
121  static UserManager* test_user_manager_;
122
123  DISALLOW_COPY_AND_ASSIGN(AppLaunchController);
124};
125
126}  // namespace chromeos
127
128#endif  // CHROME_BROWSER_CHROMEOS_LOGIN_APP_LAUNCH_CONTROLLER_H_
129