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 ~AppLaunchManager() override
{}
32 void Cleanup() { delete this; }
34 // StartupAppLauncher::Delegate overrides:
35 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 bool IsNetworkReady() override
{
42 // See comments above. Network is assumed to be online here.
45 void OnLoadingOAuthFile() override
{}
46 void OnInitializingTokenService() override
{}
47 void OnInstallingApp() override
{}
48 void OnReadyToLaunch() override
{ startup_app_launcher_
->LaunchApp(); }
49 void OnLaunchSucceeded() override
{ Cleanup(); }
50 void OnLaunchFailed(KioskAppLaunchError::Error error
) override
{
51 KioskAppLaunchError::Save(error
);
52 chrome::AttemptUserExit();
55 bool IsShowingNetworkConfigScreen() override
{ return false; }
57 scoped_ptr
<StartupAppLauncher
> startup_app_launcher_
;
59 DISALLOW_COPY_AND_ASSIGN(AppLaunchManager
);
62 void LaunchAppOrDie(Profile
* profile
, const std::string
& app_id
) {
63 // AppLaunchManager manages its own lifetime.
64 (new AppLaunchManager(profile
, app_id
))->Start();
67 } // namespace chromeos