Upstream version 5.34.92.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / login / app_launch_controller.h
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/timer/timer.h"
13 #include "chrome/browser/chromeos/app_mode/kiosk_app_launch_error.h"
14 #include "chrome/browser/chromeos/app_mode/kiosk_profile_loader.h"
15 #include "chrome/browser/chromeos/app_mode/startup_app_launcher.h"
16 #include "chrome/browser/chromeos/login/app_launch_signin_screen.h"
17 #include "chrome/browser/chromeos/login/screens/app_launch_splash_screen_actor.h"
18 #include "content/public/browser/notification_observer.h"
19 #include "content/public/browser/notification_registrar.h"
20
21 class Profile;
22
23 namespace chromeos {
24
25 class LoginDisplayHost;
26 class OobeDisplay;
27 class UserManager;
28
29 // Controller for the kiosk app launch process, responsible for
30 // coordinating loading the kiosk profile, launching the app, and
31 // updating the splash screen UI.
32 class AppLaunchController
33     : public AppLaunchSplashScreenActor::Delegate,
34       public KioskProfileLoader::Delegate,
35       public StartupAppLauncher::Delegate,
36       public AppLaunchSigninScreen::Delegate,
37       public content::NotificationObserver {
38  public:
39   typedef base::Callback<bool()> ReturnBoolCallback;
40
41   AppLaunchController(const std::string& app_id,
42                       LoginDisplayHost* host,
43                       OobeDisplay* oobe_display);
44
45   virtual ~AppLaunchController();
46
47   void StartAppLaunch();
48
49   bool waiting_for_network() { return waiting_for_network_; }
50   bool network_wait_timedout() { return network_wait_timedout_; }
51   bool showing_network_dialog() { return showing_network_dialog_; }
52
53   // Customize controller for testing purposes.
54   static void SkipSplashWaitForTesting();
55   static void SetNetworkTimeoutCallbackForTesting(base::Closure* callback);
56   static void SetNetworkWaitForTesting(int wait_time_secs);
57   static void SetCanConfigureNetworkCallbackForTesting(
58       ReturnBoolCallback* can_configure_network_callback);
59   static void SetNeedOwnerAuthToConfigureNetworkCallbackForTesting(
60       ReturnBoolCallback* need_owner_auth_callback);
61
62  private:
63   // A class to watch app window creation.
64   class AppWindowWatcher;
65
66   void CleanUp();
67   void OnNetworkWaitTimedout();
68
69   // Callback of AppWindowWatcher to notify an app window is created.
70   void OnAppWindowCreated();
71
72   // Whether the network could be configured during launching.
73   bool CanConfigureNetwork();
74
75   // Whether the owner password is needed to configure network.
76   bool NeedOwnerAuthToConfigureNetwork();
77
78   // Show network configuration UI if it is allowed. For consumer mode,
79   // owner password might be checked before showing the network configure UI.
80   void MaybeShowNetworkConfigureUI();
81
82   // KioskProfileLoader::Delegate overrides:
83   virtual void OnProfileLoaded(Profile* profile) OVERRIDE;
84   virtual void OnProfileLoadFailed(KioskAppLaunchError::Error error) OVERRIDE;
85
86   // AppLaunchSplashScreenActor::Delegate overrides:
87   virtual void OnConfigureNetwork() OVERRIDE;
88   virtual void OnCancelAppLaunch() OVERRIDE;
89   virtual void OnNetworkStateChanged(bool online) OVERRIDE;
90
91   // StartupAppLauncher::Delegate overrides:
92   virtual void InitializeNetwork() OVERRIDE;
93   virtual void OnLoadingOAuthFile() OVERRIDE;
94   virtual void OnInitializingTokenService() OVERRIDE;
95   virtual void OnInstallingApp() OVERRIDE;
96   virtual void OnReadyToLaunch() OVERRIDE;
97   virtual void OnLaunchSucceeded() OVERRIDE;
98   virtual void OnLaunchFailed(KioskAppLaunchError::Error error) OVERRIDE;
99
100   // AppLaunchSigninScreen::Delegate overrides:
101   virtual void OnOwnerSigninSuccess() OVERRIDE;
102
103   // content::NotificationObserver overrides:
104   virtual void Observe(int type,
105                        const content::NotificationSource& source,
106                        const content::NotificationDetails& details) OVERRIDE;
107
108   Profile* profile_;
109   const std::string app_id_;
110   LoginDisplayHost* host_;
111   OobeDisplay* oobe_display_;
112   AppLaunchSplashScreenActor* app_launch_splash_screen_actor_;
113   scoped_ptr<KioskProfileLoader> kiosk_profile_loader_;
114   scoped_ptr<StartupAppLauncher> startup_app_launcher_;
115   scoped_ptr<AppLaunchSigninScreen> signin_screen_;
116   scoped_ptr<AppWindowWatcher> app_window_watcher_;
117
118   content::NotificationRegistrar registrar_;
119   bool webui_visible_;
120   bool launcher_ready_;
121
122   // A timer to ensure the app splash is shown for a minimum amount of time.
123   base::OneShotTimer<AppLaunchController> splash_wait_timer_;
124
125   base::OneShotTimer<AppLaunchController> network_wait_timer_;
126   bool waiting_for_network_;
127   bool network_wait_timedout_;
128   bool showing_network_dialog_;
129   int64 launch_splash_start_time_;
130
131   static bool skip_splash_wait_;
132   static int network_wait_time_;
133   static base::Closure* network_timeout_callback_;
134   static ReturnBoolCallback* can_configure_network_callback_;
135   static ReturnBoolCallback* need_owner_auth_to_configure_network_callback_;
136
137   DISALLOW_COPY_AND_ASSIGN(AppLaunchController);
138 };
139
140 }  // namespace chromeos
141
142 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_APP_LAUNCH_CONTROLLER_H_