• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "content/public/browser/notification_observer.h"
21 #include "content/public/browser/notification_registrar.h"
22 
23 class Profile;
24 
25 namespace chromeos {
26 
27 class LoginDisplayHost;
28 class OobeDisplay;
29 class UserManager;
30 
31 // Controller for the kiosk app launch process, responsible for
32 // coordinating loading the kiosk profile, launching the app, and
33 // updating the splash screen UI.
34 class AppLaunchController
35     : public base::SupportsWeakPtr<AppLaunchController>,
36       public AppLaunchSplashScreenActor::Delegate,
37       public KioskProfileLoader::Delegate,
38       public StartupAppLauncher::Delegate,
39       public AppLaunchSigninScreen::Delegate,
40       public content::NotificationObserver {
41  public:
42   typedef base::Callback<bool()> ReturnBoolCallback;
43 
44   AppLaunchController(const std::string& app_id,
45                       LoginDisplayHost* host,
46                       OobeDisplay* oobe_display);
47 
48   virtual ~AppLaunchController();
49 
50   void StartAppLaunch();
51 
waiting_for_network()52   bool waiting_for_network() { return waiting_for_network_; }
network_wait_timedout()53   bool network_wait_timedout() { return network_wait_timedout_; }
showing_network_dialog()54   bool showing_network_dialog() { return showing_network_dialog_; }
55 
56   // Customize controller for testing purposes.
57   static void SkipSplashWaitForTesting();
58   static void SetNetworkTimeoutCallbackForTesting(base::Closure* callback);
59   static void SetNetworkWaitForTesting(int wait_time_secs);
60   static void SetCanConfigureNetworkCallbackForTesting(
61       ReturnBoolCallback* can_configure_network_callback);
62   static void SetNeedOwnerAuthToConfigureNetworkCallbackForTesting(
63       ReturnBoolCallback* need_owner_auth_callback);
64 
65  private:
66   // A class to watch app window creation.
67   class AppWindowWatcher;
68 
69   void CleanUp();
70   void OnNetworkWaitTimedout();
71 
72   // Callback of AppWindowWatcher to notify an app window is created.
73   void OnAppWindowCreated();
74 
75   // Whether the network could be configured during launching.
76   bool CanConfigureNetwork();
77 
78   // Whether the owner password is needed to configure network.
79   bool NeedOwnerAuthToConfigureNetwork();
80 
81   // Show network configuration UI if it is allowed. For consumer mode,
82   // owner password might be checked before showing the network configure UI.
83   void MaybeShowNetworkConfigureUI();
84 
85   // KioskProfileLoader::Delegate overrides:
86   virtual void OnProfileLoaded(Profile* profile) OVERRIDE;
87   virtual void OnProfileLoadFailed(KioskAppLaunchError::Error error) OVERRIDE;
88 
89   // AppLaunchSplashScreenActor::Delegate overrides:
90   virtual void OnConfigureNetwork() OVERRIDE;
91   virtual void OnCancelAppLaunch() OVERRIDE;
92   virtual void OnNetworkStateChanged(bool online) OVERRIDE;
93 
94   // StartupAppLauncher::Delegate overrides:
95   virtual void InitializeNetwork() OVERRIDE;
96   virtual void OnLoadingOAuthFile() OVERRIDE;
97   virtual void OnInitializingTokenService() OVERRIDE;
98   virtual void OnInstallingApp() OVERRIDE;
99   virtual void OnReadyToLaunch() OVERRIDE;
100   virtual void OnLaunchSucceeded() OVERRIDE;
101   virtual void OnLaunchFailed(KioskAppLaunchError::Error error) OVERRIDE;
102 
103   // AppLaunchSigninScreen::Delegate overrides:
104   virtual void OnOwnerSigninSuccess() OVERRIDE;
105 
106   // content::NotificationObserver overrides:
107   virtual void Observe(int type,
108                        const content::NotificationSource& source,
109                        const content::NotificationDetails& details) OVERRIDE;
110 
111   Profile* profile_;
112   const std::string app_id_;
113   LoginDisplayHost* host_;
114   OobeDisplay* oobe_display_;
115   AppLaunchSplashScreenActor* app_launch_splash_screen_actor_;
116   scoped_ptr<KioskProfileLoader> kiosk_profile_loader_;
117   scoped_ptr<StartupAppLauncher> startup_app_launcher_;
118   scoped_ptr<AppLaunchSigninScreen> signin_screen_;
119   scoped_ptr<AppWindowWatcher> app_window_watcher_;
120 
121   content::NotificationRegistrar registrar_;
122   bool webui_visible_;
123   bool launcher_ready_;
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_
143