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.
5 #include "chrome/browser/chromeos/app_mode/app_launch_utils.h"
7 #include "chrome/browser/chromeos/app_mode/kiosk_app_launch_error.h"
8 #include "chrome/browser/chromeos/app_mode/startup_app_launcher.h"
9 #include "chrome/browser/lifetime/application_lifetime.h"
13 // A simple manager for the app launch that starts the launch
14 // and deletes itself when the launch finishes. On launch failure,
15 // it exits the browser process.
16 class AppLaunchManager : public StartupAppLauncher::Delegate {
18 AppLaunchManager(Profile* profile, const std::string& app_id)
19 : startup_app_launcher_(
20 new StartupAppLauncher(profile,
22 false /* diagnostic_mode */,
26 startup_app_launcher_->Initialize();
30 virtual ~AppLaunchManager() {}
32 void Cleanup() { delete this; }
34 // StartupAppLauncher::Delegate overrides:
35 virtual void InitializeNetwork() override {
36 // This is on crash-restart path and assumes network is online.
37 // TODO(xiyuan): Remove the crash-restart path for kiosk or add proper
38 // network configure handling.
39 startup_app_launcher_->ContinueWithNetworkReady();
41 virtual bool IsNetworkReady() override {
42 // See comments above. Network is assumed to be online here.
45 virtual void OnLoadingOAuthFile() override {}
46 virtual void OnInitializingTokenService() override {}
47 virtual void OnInstallingApp() override {}
48 virtual void OnReadyToLaunch() override {
49 startup_app_launcher_->LaunchApp();
51 virtual void OnLaunchSucceeded() override { Cleanup(); }
52 virtual void OnLaunchFailed(KioskAppLaunchError::Error error) override {
53 KioskAppLaunchError::Save(error);
54 chrome::AttemptUserExit();
57 virtual bool IsShowingNetworkConfigScreen() override { return false; }
59 scoped_ptr<StartupAppLauncher> startup_app_launcher_;
61 DISALLOW_COPY_AND_ASSIGN(AppLaunchManager);
64 void LaunchAppOrDie(Profile* profile, const std::string& app_id) {
65 // AppLaunchManager manages its own lifetime.
66 (new AppLaunchManager(profile, app_id))->Start();
69 } // namespace chromeos