Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(704)

Side by Side Diff: chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_data.cc

Issue 2778053002: Fetch ARC Kiosk app name and icon from Android side. (Closed)
Patch Set: extract common code into KioskAppDataBase Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
19 namespace {
20
21 constexpr char kIconCacheDir[] = "arc-kiosk/icon";
22
23 } // namespace
24
25 ArcKioskAppData::ArcKioskAppData(const std::string& app_id,
26 const AccountId& account_id,
27 const std::string& name)
28 : KioskAppDataBase(app_id, account_id) {
29 name_ = name;
30 }
31
32 ArcKioskAppData::~ArcKioskAppData() = default;
33
34 bool ArcKioskAppData::operator==(const std::string& app_id) const {
35 return this->app_id_ == app_id;
36 }
37
38 bool ArcKioskAppData::LoadFromCache() {
39 PrefService* local_state = g_browser_process->local_state();
40 const base::DictionaryValue* dict =
41 local_state->GetDictionary(kiosk_dictionary_name());
42
43 return LoadFromDictionary(dict);
44 }
45
46 void ArcKioskAppData::SetCache(const std::string& name,
47 const gfx::ImageSkia& icon) {
48 DCHECK(!name.empty());
49 DCHECK(!icon.isNull());
50 name_ = name;
51 icon_ = icon;
52
53 base::FilePath user_data_dir;
54 CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir));
55 base::FilePath cache_dir = user_data_dir.AppendASCII(kIconCacheDir);
56
57 SaveIcon(*icon_.bitmap(), cache_dir);
58
59 PrefService* local_state = g_browser_process->local_state();
60 DictionaryPrefUpdate dict_update(local_state, kiosk_dictionary_name());
61
62 SaveToDictionary(dict_update);
63 }
64
65 const char* ArcKioskAppData::kiosk_dictionary_name() const {
66 return ArcKioskAppManager::kArcKioskDictionaryName;
67 }
68
69 void ArcKioskAppData::OnIconLoadSuccess(const gfx::ImageSkia& icon) {
70 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
71 icon_ = icon;
72 }
73
74 void ArcKioskAppData::OnIconLoadFailure() {
75 LOG(ERROR) << "Icon Load Failure";
76 // Do nothing
77 }
78
79 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698