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#ifndef CHROME_BROWSER_CHROMEOS_APP_MODE_KIOSK_APP_LAUNCHER_H_
6#define CHROME_BROWSER_CHROMEOS_APP_MODE_KIOSK_APP_LAUNCHER_H_
7
8#include <string>
9
10#include "base/basictypes.h"
11#include "base/callback.h"
12#include "base/memory/scoped_ptr.h"
13#include "chrome/browser/chromeos/app_mode/kiosk_app_launch_error.h"
14#include "third_party/cros_system_api/dbus/service_constants.h"
15
16class Profile;
17
18namespace chromeos {
19
20class KioskAppManager;
21
22// KioskAppLauncher launches a given app from login screen. It first attempts
23// to mount a cryptohome for the app. If the mount is successful, it prepares
24// app profile then calls StartupAppLauncher to finish the launch. If mount
25// fails, it sets relevant launch error and restart chrome to gets back to
26// the login screen. Note that there should only be one launch attempt in
27// progress.
28class KioskAppLauncher {
29 public:
30  KioskAppLauncher(KioskAppManager* kiosk_app_manager,
31                   const std::string& app_id);
32
33  // Starts a launch attempt. Fails immediately if there is already a launch
34  // attempt running.
35  void Start();
36
37 private:
38  class CryptohomedChecker;
39  class ProfileLoader;
40
41  // Private dtor because this class manages its own lifetime.
42  ~KioskAppLauncher();
43
44  void ReportLaunchResult(KioskAppLaunchError::Error error);
45
46  void StartMount();
47  void MountCallback(bool mount_success, cryptohome::MountError mount_error);
48
49  void AttemptRemove();
50  void RemoveCallback(bool success,
51                      cryptohome::MountError return_code);
52
53  void OnProfilePrepared(Profile* profile);
54
55  // The instance of the current running launch.
56  static KioskAppLauncher* running_instance_;
57
58  KioskAppManager* kiosk_app_manager_;
59  const std::string app_id_;
60  std::string user_id_;
61
62  scoped_ptr<CryptohomedChecker> crytohomed_checker;
63  scoped_ptr<ProfileLoader> profile_loader_;
64
65  // Whether remove existing cryptohome has attempted.
66  bool remove_attempted_;
67
68  DISALLOW_COPY_AND_ASSIGN(KioskAppLauncher);
69};
70
71}  // namespace chromeos
72
73#endif  // CHROME_BROWSER_CHROMEOS_APP_MODE_KIOSK_APP_LAUNCHER_H_
74