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

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: some nits 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(ArcKioskAppManager::kArcKioskDictionaryName,
29 app_id,
30 account_id) {
31 name_ = name;
32 }
33
34 ArcKioskAppData::~ArcKioskAppData() = default;
35
36 bool ArcKioskAppData::operator==(const std::string& other_app_id) const {
37 return app_id() == other_app_id;
38 }
39
40 bool ArcKioskAppData::LoadFromCache() {
41 PrefService* local_state = g_browser_process->local_state();
42 const base::DictionaryValue* dict =
43 local_state->GetDictionary(dictionary_name());
44
45 return LoadFromDictionary(*dict);
46 }
47
48 void ArcKioskAppData::SetCache(const std::string& name,
49 const gfx::ImageSkia& icon) {
50 DCHECK(!name.empty());
51 DCHECK(!icon.isNull());
52 name_ = name;
53 icon_ = icon;
54
55 base::FilePath user_data_dir;
56 if (!PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) {
57 LOG(ERROR) << "Failed to get user directory.";
58 return;
59 }
60 base::FilePath cache_dir = user_data_dir.AppendASCII(kIconCacheDir);
61
62 SaveIcon(*icon_.bitmap(), cache_dir);
63
64 PrefService* local_state = g_browser_process->local_state();
65 DictionaryPrefUpdate dict_update(local_state, dictionary_name());
66
67 SaveToDictionary(dict_update);
68 }
69
70 void ArcKioskAppData::OnIconLoadSuccess(const gfx::ImageSkia& icon) {
71 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
72 kiosk_app_icon_loader_.release();
73 icon_ = icon;
74 }
75
76 void ArcKioskAppData::OnIconLoadFailure() {
77 kiosk_app_icon_loader_.release();
78 LOG(ERROR) << "Icon Load Failure";
79 // Do nothing
80 }
81
82 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698