Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chromeos / app_mode / app_launch_utils.cc
blobaee250cbfe739e2cf4d0ebd36ff001509e17119c
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 "base/timer/timer.h"
8 #include "chrome/browser/chromeos/app_mode/kiosk_app_launch_error.h"
9 #include "chrome/browser/chromeos/app_mode/startup_app_launcher.h"
10 #include "chrome/browser/lifetime/application_lifetime.h"
12 namespace chromeos {
14 // A simple manager for the app launch that starts the launch
15 // and deletes itself when the launch finishes. On launch failure,
16 // it exits the browser process.
17 class AppLaunchManager : public StartupAppLauncher::Delegate {
18 public:
19 AppLaunchManager(Profile* profile, const std::string& app_id)
20 : startup_app_launcher_(new StartupAppLauncher(profile, app_id, this)) {
23 void Start() {
24 startup_app_launcher_->Initialize();
27 private:
28 virtual ~AppLaunchManager() {}
30 void Cleanup() { delete this; }
32 // StartupAppLauncher::Delegate overrides:
33 virtual void InitializeNetwork() OVERRIDE {
34 // This is on crash-restart path and assumes network is online.
35 // TODO(xiyuan): Remove the crash-restart path for kiosk or add proper
36 // network configure handling.
37 startup_app_launcher_->ContinueWithNetworkReady();
39 virtual void OnLoadingOAuthFile() OVERRIDE {}
40 virtual void OnInitializingTokenService() OVERRIDE {}
41 virtual void OnInstallingApp() OVERRIDE {}
42 virtual void OnReadyToLaunch() OVERRIDE {
43 startup_app_launcher_->LaunchApp();
45 virtual void OnLaunchSucceeded() OVERRIDE { Cleanup(); }
46 virtual void OnLaunchFailed(KioskAppLaunchError::Error error) OVERRIDE {
47 KioskAppLaunchError::Save(error);
48 chrome::AttemptUserExit();
49 Cleanup();
52 scoped_ptr<StartupAppLauncher> startup_app_launcher_;
54 DISALLOW_COPY_AND_ASSIGN(AppLaunchManager);
57 void LaunchAppOrDie(Profile* profile, const std::string& app_id) {
58 // AppLaunchManager manages its own lifetime.
59 (new AppLaunchManager(profile, app_id))->Start();
62 } // namespace chromeos