Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / chromeos / app_mode / app_launch_utils.cc
blobd5a4c491b592b8db173de89560fe76f9b3ac9c88
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"
11 namespace chromeos {
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)) {}
25 void Start() {
26 startup_app_launcher_->Initialize();
29 private:
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.
43 return true;
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();
53 Cleanup();
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