| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/app_mode/kiosk_app_launch_error.h" | 5 #include "chrome/browser/chromeos/app_mode/kiosk_app_launch_error.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram_macros.h" |
| 7 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 8 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" | 9 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" |
| 9 #include "chrome/grit/generated_resources.h" | 10 #include "chrome/grit/generated_resources.h" |
| 11 #include "chromeos/login/auth/auth_status_consumer.h" |
| 10 #include "components/prefs/scoped_user_pref_update.h" | 12 #include "components/prefs/scoped_user_pref_update.h" |
| 11 #include "ui/base/l10n/l10n_util.h" | 13 #include "ui/base/l10n/l10n_util.h" |
| 12 | 14 |
| 13 namespace chromeos { | 15 namespace chromeos { |
| 14 | 16 |
| 15 namespace { | 17 namespace { |
| 16 | 18 |
| 17 // Key under "kiosk" dictionary to store last launch error. | 19 // Key under "kiosk" dictionary to store the last launch error. |
| 18 const char kKeyLaunchError[] = "launch_error"; | 20 constexpr char kKeyLaunchError[] = "launch_error"; |
| 21 |
| 22 // Key under "kiosk" dictionary to store the last cryptohome error. |
| 23 constexpr char kKeyCryptohomeFailure[] = "cryptohome_failure"; |
| 19 | 24 |
| 20 } // namespace | 25 } // namespace |
| 21 | 26 |
| 22 // static | 27 // static |
| 23 std::string KioskAppLaunchError::GetErrorMessage(Error error) { | 28 std::string KioskAppLaunchError::GetErrorMessage(Error error) { |
| 24 switch (error) { | 29 switch (error) { |
| 25 case NONE: | 30 case NONE: |
| 26 return std::string(); | 31 return std::string(); |
| 27 | 32 |
| 28 case HAS_PENDING_LAUNCH: | 33 case HAS_PENDING_LAUNCH: |
| (...skipping 13 matching lines...) Expand all Loading... |
| 42 return l10n_util::GetStringUTF8(IDS_KIOSK_APP_ERROR_UNABLE_TO_INSTALL); | 47 return l10n_util::GetStringUTF8(IDS_KIOSK_APP_ERROR_UNABLE_TO_INSTALL); |
| 43 | 48 |
| 44 case USER_CANCEL: | 49 case USER_CANCEL: |
| 45 return l10n_util::GetStringUTF8(IDS_KIOSK_APP_ERROR_USER_CANCEL); | 50 return l10n_util::GetStringUTF8(IDS_KIOSK_APP_ERROR_USER_CANCEL); |
| 46 | 51 |
| 47 case UNABLE_TO_DOWNLOAD: | 52 case UNABLE_TO_DOWNLOAD: |
| 48 return l10n_util::GetStringUTF8(IDS_KIOSK_APP_ERROR_UNABLE_TO_DOWNLOAD); | 53 return l10n_util::GetStringUTF8(IDS_KIOSK_APP_ERROR_UNABLE_TO_DOWNLOAD); |
| 49 | 54 |
| 50 case UNABLE_TO_LAUNCH: | 55 case UNABLE_TO_LAUNCH: |
| 51 return l10n_util::GetStringUTF8(IDS_KIOSK_APP_ERROR_UNABLE_TO_LAUNCH); | 56 return l10n_util::GetStringUTF8(IDS_KIOSK_APP_ERROR_UNABLE_TO_LAUNCH); |
| 57 |
| 58 case ERROR_COUNT: |
| 59 // Break onto the NOTREACHED() code path below. |
| 60 break; |
| 52 } | 61 } |
| 53 | 62 |
| 54 NOTREACHED() << "Unknown kiosk app launch error, error=" << error; | 63 NOTREACHED() << "Unknown kiosk app launch error, error=" << error; |
| 55 return l10n_util::GetStringUTF8(IDS_KIOSK_APP_FAILED_TO_LAUNCH); | 64 return l10n_util::GetStringUTF8(IDS_KIOSK_APP_FAILED_TO_LAUNCH); |
| 56 } | 65 } |
| 57 | 66 |
| 58 // static | 67 // static |
| 59 void KioskAppLaunchError::Save(KioskAppLaunchError::Error error) { | 68 void KioskAppLaunchError::Save(KioskAppLaunchError::Error error) { |
| 60 PrefService* local_state = g_browser_process->local_state(); | 69 PrefService* local_state = g_browser_process->local_state(); |
| 61 DictionaryPrefUpdate dict_update(local_state, | 70 DictionaryPrefUpdate dict_update(local_state, |
| 62 KioskAppManager::kKioskDictionaryName); | 71 KioskAppManager::kKioskDictionaryName); |
| 63 dict_update->SetInteger(kKeyLaunchError, error); | 72 dict_update->SetInteger(kKeyLaunchError, error); |
| 64 } | 73 } |
| 65 | 74 |
| 66 // static | 75 // static |
| 76 void KioskAppLaunchError::SaveCryptohomeFailure( |
| 77 const AuthFailure& auth_failure) { |
| 78 PrefService* local_state = g_browser_process->local_state(); |
| 79 DictionaryPrefUpdate dict_update(local_state, |
| 80 KioskAppManager::kKioskDictionaryName); |
| 81 dict_update->SetInteger(kKeyCryptohomeFailure, auth_failure.reason()); |
| 82 } |
| 83 |
| 84 // static |
| 67 KioskAppLaunchError::Error KioskAppLaunchError::Get() { | 85 KioskAppLaunchError::Error KioskAppLaunchError::Get() { |
| 68 PrefService* local_state = g_browser_process->local_state(); | 86 PrefService* local_state = g_browser_process->local_state(); |
| 69 const base::DictionaryValue* dict = | 87 const base::DictionaryValue* dict = |
| 70 local_state->GetDictionary(KioskAppManager::kKioskDictionaryName); | 88 local_state->GetDictionary(KioskAppManager::kKioskDictionaryName); |
| 71 | 89 |
| 72 int error; | 90 int error; |
| 73 if (dict->GetInteger(kKeyLaunchError, &error)) | 91 if (dict->GetInteger(kKeyLaunchError, &error)) |
| 74 return static_cast<KioskAppLaunchError::Error>(error); | 92 return static_cast<KioskAppLaunchError::Error>(error); |
| 75 | 93 |
| 76 return KioskAppLaunchError::NONE; | 94 return KioskAppLaunchError::NONE; |
| 77 } | 95 } |
| 78 | 96 |
| 79 // static | 97 // static |
| 80 void KioskAppLaunchError::Clear() { | 98 void KioskAppLaunchError::RecordMetricAndClear() { |
| 81 PrefService* local_state = g_browser_process->local_state(); | 99 PrefService* local_state = g_browser_process->local_state(); |
| 82 DictionaryPrefUpdate dict_update(local_state, | 100 DictionaryPrefUpdate dict_update(local_state, |
| 83 KioskAppManager::kKioskDictionaryName); | 101 KioskAppManager::kKioskDictionaryName); |
| 102 |
| 103 int error; |
| 104 if (dict_update->GetInteger(kKeyLaunchError, &error)) |
| 105 UMA_HISTOGRAM_ENUMERATION("Kiosk.Launch.Error", error, ERROR_COUNT); |
| 84 dict_update->Remove(kKeyLaunchError, NULL); | 106 dict_update->Remove(kKeyLaunchError, NULL); |
| 107 |
| 108 int cryptohome_failure; |
| 109 if (dict_update->GetInteger(kKeyCryptohomeFailure, &cryptohome_failure)) { |
| 110 UMA_HISTOGRAM_ENUMERATION("Kiosk.Launch.CryptohomeFailure", |
| 111 cryptohome_failure, |
| 112 AuthFailure::NUM_FAILURE_REASONS); |
| 113 } |
| 114 dict_update->Remove(kKeyCryptohomeFailure, NULL); |
| 85 } | 115 } |
| 86 | 116 |
| 87 } // namespace chromeos | 117 } // namespace chromeos |
| OLD | NEW |