kiosk_app_launch_error.cc revision 1e9bf3e0803691d0a228da41fc608347b6db4340
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/kiosk_app_launch_error.h"
6
7#include "base/prefs/scoped_user_pref_update.h"
8#include "chrome/browser/browser_process.h"
9#include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
10#include "grit/generated_resources.h"
11#include "ui/base/l10n/l10n_util.h"
12
13namespace chromeos {
14
15namespace {
16
17// Key under "kiosk" dictionary to store last launch error.
18const char kKeyLaunchError[] = "launch_error";
19
20}  // namespace
21
22// static
23std::string KioskAppLaunchError::GetErrorMessage(Error error) {
24  switch (error) {
25    case NONE:
26      return std::string();
27
28    case HAS_PENDING_LAUNCH:
29    case NOT_KIOSK_ENABLED:
30    case UNABLE_TO_RETRIEVE_HASH:
31    case POLICY_LOAD_FAILED:
32      return l10n_util::GetStringUTF8(IDS_KIOSK_APP_FAILED_TO_LAUNCH);
33
34    case CRYPTOHOMED_NOT_RUNNING:
35    case ALREADY_MOUNTED:
36    case UNABLE_TO_MOUNT:
37    case UNABLE_TO_REMOVE:
38      return l10n_util::GetStringUTF8(IDS_KIOSK_APP_ERROR_UNABLE_TO_MOUNT);
39
40    case UNABLE_TO_INSTALL:
41      return l10n_util::GetStringUTF8(IDS_KIOSK_APP_ERROR_UNABLE_TO_INSTALL);
42
43    case USER_CANCEL:
44      return l10n_util::GetStringUTF8(IDS_KIOSK_APP_ERROR_USER_CANCEL);
45  }
46
47  NOTREACHED() << "Unknown kiosk app launch error, error=" << error;
48  return l10n_util::GetStringUTF8(IDS_KIOSK_APP_FAILED_TO_LAUNCH);
49}
50
51// static
52void KioskAppLaunchError::Save(KioskAppLaunchError::Error error) {
53  PrefService* local_state = g_browser_process->local_state();
54  DictionaryPrefUpdate dict_update(local_state,
55                                   KioskAppManager::kKioskDictionaryName);
56  dict_update->SetInteger(kKeyLaunchError, error);
57}
58
59// static
60KioskAppLaunchError::Error KioskAppLaunchError::Get() {
61  PrefService* local_state = g_browser_process->local_state();
62  const base::DictionaryValue* dict =
63      local_state->GetDictionary(KioskAppManager::kKioskDictionaryName);
64
65  int error;
66  if (dict->GetInteger(kKeyLaunchError, &error))
67    return static_cast<KioskAppLaunchError::Error>(error);
68
69  return KioskAppLaunchError::NONE;
70}
71
72// static
73void KioskAppLaunchError::Clear() {
74  PrefService* local_state = g_browser_process->local_state();
75  DictionaryPrefUpdate dict_update(local_state,
76                                   KioskAppManager::kKioskDictionaryName);
77  dict_update->Remove(kKeyLaunchError, NULL);
78}
79
80}  // namespace chromeos
81