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..dd683e85b73d49be950a2f8bf35185448a21b2a0 |
--- /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(app_id, account_id) { |
+ name_ = name; |
+} |
+ |
+ArcKioskAppData::~ArcKioskAppData() = default; |
+ |
+bool ArcKioskAppData::operator==(const std::string& app_id) const { |
+ return this->app_id_ == app_id; |
+} |
+ |
+bool ArcKioskAppData::LoadFromCache() { |
+ PrefService* local_state = g_browser_process->local_state(); |
+ const base::DictionaryValue* dict = |
+ local_state->GetDictionary(kiosk_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)); |
+ 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, kiosk_dictionary_name()); |
+ |
+ SaveToDictionary(dict_update); |
+} |
+ |
+const char* ArcKioskAppData::kiosk_dictionary_name() const { |
+ return ArcKioskAppManager::kArcKioskDictionaryName; |
+} |
+ |
+void ArcKioskAppData::OnIconLoadSuccess(const gfx::ImageSkia& icon) { |
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
+ icon_ = icon; |
+} |
+ |
+void ArcKioskAppData::OnIconLoadFailure() { |
+ LOG(ERROR) << "Icon Load Failure"; |
+ // Do nothing |
+} |
+ |
+} // namespace chromeos |