#include "chrome/browser/chromeos/login/app_launch_controller.h"
-#include "apps/shell_window_registry.h"
+#include "base/bind.h"
#include "base/callback.h"
#include "base/files/file_path.h"
#include "base/json/json_file_value_serializer.h"
+#include "base/logging.h"
+#include "base/memory/weak_ptr.h"
+#include "base/message_loop/message_loop.h"
#include "base/time/time.h"
#include "base/values.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/app_mode/app_session_lifetime.h"
#include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
#include "chrome/browser/chromeos/app_mode/startup_app_launcher.h"
-#include "chrome/browser/chromeos/login/login_display_host.h"
-#include "chrome/browser/chromeos/login/login_display_host_impl.h"
-#include "chrome/browser/chromeos/login/oobe_display.h"
#include "chrome/browser/chromeos/login/screens/error_screen_actor.h"
-#include "chrome/browser/chromeos/login/webui_login_view.h"
+#include "chrome/browser/chromeos/login/ui/login_display_host.h"
+#include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
+#include "chrome/browser/chromeos/login/ui/oobe_display.h"
+#include "chrome/browser/chromeos/login/ui/webui_login_view.h"
#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
#include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/browser/lifetime/application_lifetime.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/chromeos/login/app_launch_splash_screen_handler.h"
#include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
+#include "components/user_manager/user_manager.h"
#include "content/public/browser/notification_service.h"
+#include "extensions/browser/app_window/app_window.h"
+#include "extensions/browser/app_window/app_window_registry.h"
#include "net/base/network_change_notifier.h"
namespace chromeos {
// AppLaunchController::AppWindowWatcher
class AppLaunchController::AppWindowWatcher
- : public apps::ShellWindowRegistry::Observer {
+ : public extensions::AppWindowRegistry::Observer {
public:
- explicit AppWindowWatcher(AppLaunchController* controller)
- : controller_(controller),
- window_registry_(apps::ShellWindowRegistry::Get(controller->profile_)) {
- window_registry_->AddObserver(this);
+ explicit AppWindowWatcher(AppLaunchController* controller,
+ const std::string& app_id)
+ : controller_(controller),
+ app_id_(app_id),
+ window_registry_(
+ extensions::AppWindowRegistry::Get(controller->profile_)),
+ weak_factory_(this) {
+ if (!window_registry_->GetAppWindowsForApp(app_id).empty()) {
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&AppWindowWatcher::NotifyAppWindowCreated,
+ weak_factory_.GetWeakPtr()));
+ return;
+ } else {
+ window_registry_->AddObserver(this);
+ }
}
virtual ~AppWindowWatcher() {
window_registry_->RemoveObserver(this);
}
private:
- // apps::ShellWindowRegistry::Observer overrides:
- virtual void OnShellWindowAdded(apps::ShellWindow* shell_window) OVERRIDE {
- if (controller_) {
- controller_->OnAppWindowCreated();
- controller_= NULL;
+ // extensions::AppWindowRegistry::Observer overrides:
+ virtual void OnAppWindowAdded(extensions::AppWindow* app_window) OVERRIDE {
+ if (app_window->extension_id() == app_id_) {
+ window_registry_->RemoveObserver(this);
+ NotifyAppWindowCreated();
}
}
- virtual void OnShellWindowIconChanged(
- apps::ShellWindow* shell_window) OVERRIDE {}
- virtual void OnShellWindowRemoved(apps::ShellWindow* shell_window) OVERRIDE {}
+
+ void NotifyAppWindowCreated() {
+ controller_->OnAppWindowCreated();
+ }
AppLaunchController* controller_;
- apps::ShellWindowRegistry* window_registry_;
+ std::string app_id_;
+ extensions::AppWindowRegistry* window_registry_;
+ base::WeakPtrFactory<AppWindowWatcher> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(AppWindowWatcher);
};
// AppLaunchController
AppLaunchController::AppLaunchController(const std::string& app_id,
+ bool diagnostic_mode,
LoginDisplayHost* host,
OobeDisplay* oobe_display)
: profile_(NULL),
app_id_(app_id),
+ diagnostic_mode_(diagnostic_mode),
host_(host),
oobe_display_(oobe_display),
app_launch_splash_screen_actor_(
waiting_for_network_(false),
network_wait_timedout_(false),
showing_network_dialog_(false),
+ network_config_requested_(false),
launch_splash_start_time_(0) {
}
app_launch_splash_screen_actor_->SetDelegate(this);
app_launch_splash_screen_actor_->Show(app_id_);
+ KioskAppManager::App app;
+ CHECK(KioskAppManager::Get());
+ CHECK(KioskAppManager::Get()->GetApp(app_id_, &app));
kiosk_profile_loader_.reset(
- new KioskProfileLoader(KioskAppManager::Get(), app_id_, this));
+ new KioskProfileLoader(app.user_id, false, this));
kiosk_profile_loader_->Start();
}
OnLaunchFailed(KioskAppLaunchError::USER_CANCEL);
}
+void AppLaunchController::OnNetworkConfigRequested(bool requested) {
+ network_config_requested_ = requested;
+ if (requested)
+ MaybeShowNetworkConfigureUI();
+ else
+ startup_app_launcher_->RestartLauncher();
+}
+
void AppLaunchController::OnNetworkStateChanged(bool online) {
if (!waiting_for_network_)
return;
- if (online)
+ if (online && !network_config_requested_)
startup_app_launcher_->ContinueWithNetworkReady();
else if (network_wait_timedout_)
MaybeShowNetworkConfigureUI();
DVLOG(1) << "Profile loaded... Starting app launch.";
profile_ = profile;
+ // This is needed to trigger input method extensions being loaded.
+ profile_->InitChromeOSPreferences();
+
kiosk_profile_loader_.reset();
- startup_app_launcher_.reset(new StartupAppLauncher(profile_, app_id_, this));
+ startup_app_launcher_.reset(
+ new StartupAppLauncher(profile_, app_id_, diagnostic_mode_, this));
startup_app_launcher_->Initialize();
}
return true;
}
- return !UserManager::Get()->GetOwnerEmail().empty();
+ return !user_manager::UserManager::Get()->GetOwnerEmail().empty();
}
bool AppLaunchController::NeedOwnerAuthToConfigureNetwork() {
void AppLaunchController::MaybeShowNetworkConfigureUI() {
if (CanConfigureNetwork()) {
if (NeedOwnerAuthToConfigureNetwork()) {
- app_launch_splash_screen_actor_->ToggleNetworkConfig(true);
+ if (network_config_requested_)
+ OnConfigureNetwork();
+ else
+ app_launch_splash_screen_actor_->ToggleNetworkConfig(true);
} else {
showing_network_dialog_ = true;
app_launch_splash_screen_actor_->ShowNetworkConfigureUI();
}
void AppLaunchController::InitializeNetwork() {
- // Show the network configration dialog if network is not initialized
+ // Show the network configuration dialog if network is not initialized
// after a brief wait time.
waiting_for_network_ = true;
network_wait_timer_.Start(
AppLaunchSplashScreenActor::APP_LAUNCH_STATE_PREPARING_NETWORK);
}
+bool AppLaunchController::IsNetworkReady() {
+ return app_launch_splash_screen_actor_->IsNetworkReady();
+}
+
void AppLaunchController::OnLoadingOAuthFile() {
app_launch_splash_screen_actor_->UpdateAppLaunchState(
AppLaunchSplashScreenActor::APP_LAUNCH_STATE_LOADING_AUTH_FILE);
void AppLaunchController::OnReadyToLaunch() {
launcher_ready_ = true;
+
+ if (network_config_requested_)
+ return;
+
if (!webui_visible_)
return;
AppLaunchSplashScreenActor::APP_LAUNCH_STATE_WAITING_APP_WINDOW);
DCHECK(!app_window_watcher_);
- app_window_watcher_.reset(new AppWindowWatcher(this));
+ app_window_watcher_.reset(new AppWindowWatcher(this, app_id_));
}
void AppLaunchController::OnLaunchFailed(KioskAppLaunchError::Error error) {
CleanUp();
}
+bool AppLaunchController::IsShowingNetworkConfigScreen() {
+ return network_config_requested_;
+}
+
} // namespace chromeos