- add sources.
[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/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
24 class Profile;
25
26 namespace chromeos {
27
28 class LoginDisplayHost;
29 class OobeDisplay;
30 class 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.
35 class 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   typedef base::Callback<bool()> CanConfigureNetworkCallback;
44
45   AppLaunchController(const std::string& app_id,
46                       LoginDisplayHost* host,
47                       OobeDisplay* oobe_display);
48
49   virtual ~AppLaunchController();
50
51   void StartAppLaunch();
52
53   bool waiting_for_network() { return waiting_for_network_; }
54   bool network_wait_timedout() { return network_wait_timedout_; }
55   bool showing_network_dialog() { return showing_network_dialog_; }
56
57   // Customize controller for testing purposes.
58   static void SkipSplashWaitForTesting();
59   static void SetNetworkTimeoutCallbackForTesting(base::Closure* callback);
60   static void SetNetworkWaitForTesting(int wait_time_secs);
61   static void SetCanConfigureNetworkCallbackForTesting(
62       CanConfigureNetworkCallback* can_configure_network_callback);
63
64  private:
65   // A class to watch app window creation.
66   class AppWindowWatcher;
67
68   void CleanUp();
69   void OnNetworkWaitTimedout();
70
71   // Callback of AppWindowWatcher to notify an app window is created.
72   void OnAppWindowCreated();
73
74   // Whether the network could be configured during launching.
75   bool CanConfigureNetwork();
76
77   // KioskProfileLoader::Delegate overrides:
78   virtual void OnProfileLoaded(Profile* profile) OVERRIDE;
79   virtual void OnProfileLoadFailed(KioskAppLaunchError::Error error) OVERRIDE;
80
81   // AppLaunchSplashScreenActor::Delegate overrides:
82   virtual void OnConfigureNetwork() OVERRIDE;
83   virtual void OnCancelAppLaunch() OVERRIDE;
84
85   // StartupAppLauncher::Observer overrides:
86   virtual void OnLoadingOAuthFile() OVERRIDE;
87   virtual void OnInitializingTokenService() OVERRIDE;
88   virtual void OnInitializingNetwork() OVERRIDE;
89   virtual void OnInstallingApp() OVERRIDE;
90   virtual void OnReadyToLaunch() OVERRIDE;
91   virtual void OnLaunchSucceeded() OVERRIDE;
92   virtual void OnLaunchFailed(KioskAppLaunchError::Error error) OVERRIDE;
93
94   // AppLaunchSigninScreen::Delegate overrides:
95   virtual void OnOwnerSigninSuccess() OVERRIDE;
96
97   // content::NotificationObserver overrides:
98   virtual void Observe(int type,
99                        const content::NotificationSource& source,
100                        const content::NotificationDetails& details) OVERRIDE;
101
102   Profile* profile_;
103   const std::string app_id_;
104   LoginDisplayHost* host_;
105   OobeDisplay* oobe_display_;
106   AppLaunchSplashScreenActor* app_launch_splash_screen_actor_;
107   ErrorScreenActor* error_screen_actor_;
108   scoped_ptr<KioskProfileLoader> kiosk_profile_loader_;
109   scoped_ptr<StartupAppLauncher> startup_app_launcher_;
110   scoped_ptr<AppLaunchSigninScreen> signin_screen_;
111   scoped_ptr<AppWindowWatcher> app_window_watcher_;
112
113   content::NotificationRegistrar registrar_;
114   bool webui_visible_;
115   bool launcher_ready_;
116
117   base::OneShotTimer<AppLaunchController> network_wait_timer_;
118   bool waiting_for_network_;
119   bool network_wait_timedout_;
120   bool showing_network_dialog_;
121   int64 launch_splash_start_time_;
122
123   static bool skip_splash_wait_;
124   static int network_wait_time_;
125   static base::Closure* network_timeout_callback_;
126   static CanConfigureNetworkCallback* can_configure_network_callback_;
127
128   DISALLOW_COPY_AND_ASSIGN(AppLaunchController);
129 };
130
131 }  // namespace chromeos
132
133 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_APP_LAUNCH_CONTROLLER_H_