Chromium Code Reviews| Index: chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_data.cc |
| diff --git a/chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_data.cc b/chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_data.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b8ed53ca33b1bddf071ccc5d63d371d633ee5e08 |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_data.cc |
| @@ -0,0 +1,79 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_data.h" |
| + |
| +#include <utility> |
| + |
| +#include "base/path_service.h" |
| +#include "chrome/browser/browser_process.h" |
| +#include "chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_manager.h" |
| +#include "chrome/common/chrome_paths.h" |
| +#include "components/prefs/pref_service.h" |
| +#include "components/prefs/scoped_user_pref_update.h" |
| +#include "content/public/browser/browser_thread.h" |
| + |
| +namespace chromeos { |
| + |
| +namespace { |
| + |
| +constexpr char kIconCacheDir[] = "arc-kiosk/icon"; |
| + |
| +} // namespace |
| + |
| +ArcKioskAppData::ArcKioskAppData(const std::string& app_id, |
| + const AccountId& account_id, |
| + const std::string& name) |
| + : KioskAppDataBase(ArcKioskAppManager::kArcKioskDictionaryName, |
| + app_id, |
| + account_id) { |
| + name_ = name; |
| +} |
| + |
| +ArcKioskAppData::~ArcKioskAppData() = default; |
| + |
| +bool ArcKioskAppData::operator==(const std::string& other_app_id) const { |
| + return app_id() == other_app_id; |
| +} |
| + |
| +bool ArcKioskAppData::LoadFromCache() { |
| + PrefService* local_state = g_browser_process->local_state(); |
| + const base::DictionaryValue* dict = |
| + local_state->GetDictionary(dictionary_name()); |
| + |
| + return LoadFromDictionary(*dict); |
| +} |
| + |
| +void ArcKioskAppData::SetCache(const std::string& name, |
| + const gfx::ImageSkia& icon) { |
| + DCHECK(!name.empty()); |
| + DCHECK(!icon.isNull()); |
| + name_ = name; |
| + icon_ = icon; |
| + |
| + base::FilePath user_data_dir; |
| + CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)); |
|
Luis Héctor Chávez
2017/04/03 22:58:55
nit: there's still a few straggling CHECKs in this
Sergey Poromov
2017/04/06 10:29:58
Done.
|
| + base::FilePath cache_dir = user_data_dir.AppendASCII(kIconCacheDir); |
| + |
| + SaveIcon(*icon_.bitmap(), cache_dir); |
| + |
| + PrefService* local_state = g_browser_process->local_state(); |
| + DictionaryPrefUpdate dict_update(local_state, dictionary_name()); |
| + |
| + SaveToDictionary(dict_update); |
| +} |
| + |
| +void ArcKioskAppData::OnIconLoadSuccess(const gfx::ImageSkia& icon) { |
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| + kiosk_app_icon_loader_.release(); |
| + icon_ = icon; |
| +} |
| + |
| +void ArcKioskAppData::OnIconLoadFailure() { |
| + kiosk_app_icon_loader_.release(); |
| + LOG(ERROR) << "Icon Load Failure"; |
| + // Do nothing |
| +} |
| + |
| +} // namespace chromeos |