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

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: xiyuan@ comments 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 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.
57 base::FilePath cache_dir = user_data_dir.AppendASCII(kIconCacheDir);
58
59 SaveIcon(*icon_.bitmap(), cache_dir);
60
61 PrefService* local_state = g_browser_process->local_state();
62 DictionaryPrefUpdate dict_update(local_state, dictionary_name());
63
64 SaveToDictionary(dict_update);
65 }
66
67 void ArcKioskAppData::OnIconLoadSuccess(const gfx::ImageSkia& icon) {
68 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
69 kiosk_app_icon_loader_.release();
70 icon_ = icon;
71 }
72
73 void ArcKioskAppData::OnIconLoadFailure() {
74 kiosk_app_icon_loader_.release();
75 LOG(ERROR) << "Icon Load Failure";
76 // Do nothing
77 }
78
79 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698