Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / app_mode / app_launch_utils.cc
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 #include "chrome/browser/chromeos/app_mode/app_launch_utils.h"
6
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"
10
11 namespace chromeos {
12
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 {
17  public:
18   AppLaunchManager(Profile* profile, const std::string& app_id)
19       : startup_app_launcher_(
20             new StartupAppLauncher(profile,
21                                    app_id,
22                                    false /* diagnostic_mode */,
23                                    this)) {}
24
25   void Start() {
26     startup_app_launcher_->Initialize();
27   }
28
29  private:
30   virtual ~AppLaunchManager() {}
31
32   void Cleanup() { delete this; }
33
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();
40   }
41   virtual bool IsNetworkReady() override {
42     // See comments above. Network is assumed to be online here.
43     return true;
44   }
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();
50   }
51   virtual void OnLaunchSucceeded() override { Cleanup(); }
52   virtual void OnLaunchFailed(KioskAppLaunchError::Error error) override {
53     KioskAppLaunchError::Save(error);
54     chrome::AttemptUserExit();
55     Cleanup();
56   }
57   virtual bool IsShowingNetworkConfigScreen() override { return false; }
58
59   scoped_ptr<StartupAppLauncher> startup_app_launcher_;
60
61   DISALLOW_COPY_AND_ASSIGN(AppLaunchManager);
62 };
63
64 void LaunchAppOrDie(Profile* profile, const std::string& app_id) {
65   // AppLaunchManager manages its own lifetime.
66   (new AppLaunchManager(profile, app_id))->Start();
67 }
68
69 }  // namespace chromeos