Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chromeos / app_mode / kiosk_app_launch_error.cc
blob3e8d320c81a361fd6e7f4f1aa4b6e78ff2b0a4ea
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/kiosk_app_launch_error.h"
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"
13 namespace chromeos {
15 namespace {
17 // Key under "kiosk" dictionary to store last launch error.
18 const char kKeyLaunchError[] = "launch_error";
20 } // namespace
22 // static
23 std::string KioskAppLaunchError::GetErrorMessage(Error error) {
24 switch (error) {
25 case NONE:
26 return std::string();
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);
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);
40 case UNABLE_TO_INSTALL:
41 return l10n_util::GetStringUTF8(IDS_KIOSK_APP_ERROR_UNABLE_TO_INSTALL);
43 case USER_CANCEL:
44 return l10n_util::GetStringUTF8(IDS_KIOSK_APP_ERROR_USER_CANCEL);
47 NOTREACHED() << "Unknown kiosk app launch error, error=" << error;
48 return l10n_util::GetStringUTF8(IDS_KIOSK_APP_FAILED_TO_LAUNCH);
51 // static
52 void 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);
59 // static
60 KioskAppLaunchError::Error KioskAppLaunchError::Get() {
61 PrefService* local_state = g_browser_process->local_state();
62 const base::DictionaryValue* dict =
63 local_state->GetDictionary(KioskAppManager::kKioskDictionaryName);
65 int error;
66 if (dict->GetInteger(kKeyLaunchError, &error))
67 return static_cast<KioskAppLaunchError::Error>(error);
69 return KioskAppLaunchError::NONE;
72 // static
73 void 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);
80 } // namespace chromeos