1 // Copyright 2017 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/arc/arc_kiosk_app_data.h"
6
7 #include <utility>
8
9 #include "base/path_service.h"
10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_manager.h"
12 #include "chrome/common/chrome_paths.h"
13 #include "components/prefs/pref_service.h"
14 #include "components/prefs/scoped_user_pref_update.h"
15 #include "content/public/browser/browser_thread.h"
16
17 namespace chromeos {
18
ArcKioskAppData(const std::string & app_id,const std::string & package_name,const std::string & activity,const std::string & intent,const AccountId & account_id,const std::string & name)19 ArcKioskAppData::ArcKioskAppData(const std::string& app_id,
20 const std::string& package_name,
21 const std::string& activity,
22 const std::string& intent,
23 const AccountId& account_id,
24 const std::string& name)
25 : KioskAppDataBase(ArcKioskAppManager::kArcKioskDictionaryName,
26 app_id,
27 account_id),
28 package_name_(package_name),
29 activity_(activity),
30 intent_(intent) {
31 DCHECK(!package_name_.empty());
32 DCHECK(activity.empty() || intent.empty());
33 name_ = name;
34 }
35
36 ArcKioskAppData::~ArcKioskAppData() = default;
37
operator ==(const std::string & other_app_id) const38 bool ArcKioskAppData::operator==(const std::string& other_app_id) const {
39 return app_id() == other_app_id;
40 }
41
LoadFromCache()42 bool ArcKioskAppData::LoadFromCache() {
43 PrefService* local_state = g_browser_process->local_state();
44 const base::DictionaryValue* dict =
45 local_state->GetDictionary(dictionary_name());
46
47 return LoadFromDictionary(*dict);
48 }
49
SetCache(const std::string & name,const gfx::ImageSkia & icon)50 void ArcKioskAppData::SetCache(const std::string& name,
51 const gfx::ImageSkia& icon) {
52 DCHECK(!name.empty());
53 DCHECK(!icon.isNull());
54 name_ = name;
55 icon_ = icon;
56
57 base::FilePath cache_dir;
58 ArcKioskAppManager::Get()->GetKioskAppIconCacheDir(&cache_dir);
59
60 SaveIcon(*icon_.bitmap(), cache_dir);
61
62 PrefService* local_state = g_browser_process->local_state();
63 DictionaryPrefUpdate dict_update(local_state, dictionary_name());
64
65 SaveToDictionary(dict_update);
66 }
67
OnIconLoadSuccess(const gfx::ImageSkia & icon)68 void ArcKioskAppData::OnIconLoadSuccess(const gfx::ImageSkia& icon) {
69 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
70 kiosk_app_icon_loader_.reset();
71 icon_ = icon;
72 }
73
OnIconLoadFailure()74 void ArcKioskAppData::OnIconLoadFailure() {
75 kiosk_app_icon_loader_.reset();
76 LOG(ERROR) << "Icon Load Failure";
77 // Do nothing
78 }
79
80 } // namespace chromeos
81