OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_CHROMEOS_APP_MODE_ARC_ARC_KIOSK_APP_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_APP_MODE_ARC_ARC_KIOSK_APP_MANAGER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_APP_MODE_ARC_ARC_KIOSK_APP_MANAGER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_APP_MODE_ARC_ARC_KIOSK_APP_MANAGER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
14 #include "chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_data.h" | |
15 #include "chrome/browser/chromeos/policy/device_local_account.h" | 14 #include "chrome/browser/chromeos/policy/device_local_account.h" |
16 #include "chrome/browser/chromeos/settings/cros_settings.h" | 15 #include "chrome/browser/chromeos/settings/cros_settings.h" |
17 #include "components/signin/core/account_id/account_id.h" | 16 #include "components/signin/core/account_id/account_id.h" |
18 | 17 |
19 class PrefRegistrySimple; | 18 class PrefRegistrySimple; |
20 | 19 |
21 namespace chromeos { | 20 namespace chromeos { |
22 | 21 |
23 // Keeps track of Android apps that are to be launched in kiosk mode. | 22 // Keeps track of Android apps that are to be launched in kiosk mode. |
24 // For removed apps deletes appropriate cryptohome. The information about | 23 // For removed apps deletes appropriate cryptohome. The information about |
25 // kiosk apps are received from CrosSettings. For each app, the system | 24 // kiosk apps are received from CrosSettings. For each app, the system |
26 // creates a user in whose context the app then runs. | 25 // creates a user in whose context the app then runs. |
27 class ArcKioskAppManager { | 26 class ArcKioskAppManager { |
28 public: | 27 public: |
29 using Apps = std::vector<ArcKioskAppData*>; | 28 // Struct to hold full info about ARC Kiosk app. In future |
| 29 // this structure may contain many extra fields, e.g. icon. |
| 30 class ArcKioskApp { |
| 31 public: |
| 32 ArcKioskApp(const policy::ArcKioskAppBasicInfo& app_info, |
| 33 const AccountId& account_id, |
| 34 const std::string& name); |
| 35 ArcKioskApp(const ArcKioskApp& other); |
| 36 ~ArcKioskApp(); |
| 37 |
| 38 bool operator==(const std::string& app_id) const; |
| 39 bool operator==(const policy::ArcKioskAppBasicInfo& app_info) const; |
| 40 |
| 41 const policy::ArcKioskAppBasicInfo& app_info() const { return app_info_; } |
| 42 const AccountId& account_id() const { return account_id_; } |
| 43 const std::string& name() const { return name_; } |
| 44 |
| 45 private: |
| 46 policy::ArcKioskAppBasicInfo app_info_; |
| 47 AccountId account_id_; |
| 48 std::string name_; |
| 49 }; |
| 50 |
| 51 using ArcKioskApps = std::vector<ArcKioskApp>; |
30 | 52 |
31 class ArcKioskAppManagerObserver { | 53 class ArcKioskAppManagerObserver { |
32 public: | 54 public: |
33 virtual void OnArcKioskAppsChanged() {} | 55 virtual void OnArcKioskAppsChanged() {} |
34 | 56 |
35 protected: | 57 protected: |
36 virtual ~ArcKioskAppManagerObserver() = default; | 58 virtual ~ArcKioskAppManagerObserver() = default; |
37 }; | 59 }; |
38 | 60 |
39 static const char kArcKioskDictionaryName[]; | |
40 | |
41 static ArcKioskAppManager* Get(); | 61 static ArcKioskAppManager* Get(); |
42 | 62 |
43 ArcKioskAppManager(); | 63 ArcKioskAppManager(); |
44 ~ArcKioskAppManager(); | 64 ~ArcKioskAppManager(); |
45 | 65 |
46 // Registers kiosk app entries in local state. | 66 // Registers kiosk app entries in local state. |
47 static void RegisterPrefs(PrefRegistrySimple* registry); | 67 static void RegisterPrefs(PrefRegistrySimple* registry); |
48 | 68 |
49 // Removes cryptohomes which could not be removed during the previous session. | 69 // Removes cryptohomes which could not be removed during the previous session. |
50 static void RemoveObsoleteCryptohomes(); | 70 static void RemoveObsoleteCryptohomes(); |
51 | 71 |
52 // Returns auto launched account id. If there is none, account is invalid, | 72 // Returns auto launched account id. If there is none, account is invalid, |
53 // thus is_valid() returns empty AccountId. | 73 // thus is_valid() returns empty AccountId. |
54 const AccountId& GetAutoLaunchAccountId() const; | 74 const AccountId& GetAutoLaunchAccountId() const; |
55 | 75 |
56 // Returns app that should be started for given account id. | 76 // Returns app that should be started for given account id. |
57 const ArcKioskAppData* GetAppByAccountId(const AccountId& account_id); | 77 const ArcKioskApp* GetAppByAccountId(const AccountId& account_id); |
58 | 78 |
59 void GetAllApps(Apps* apps) const; | 79 const ArcKioskApps& GetAllApps() const { return apps_; } |
60 | |
61 void UpdateNameAndIcon(const std::string& app_id, | |
62 const std::string& name, | |
63 const gfx::ImageSkia& icon); | |
64 | 80 |
65 void AddObserver(ArcKioskAppManagerObserver* observer); | 81 void AddObserver(ArcKioskAppManagerObserver* observer); |
66 void RemoveObserver(ArcKioskAppManagerObserver* observer); | 82 void RemoveObserver(ArcKioskAppManagerObserver* observer); |
67 | 83 |
68 bool current_app_was_auto_launched_with_zero_delay() const { | 84 bool current_app_was_auto_launched_with_zero_delay() const { |
69 return auto_launched_with_zero_delay_; | 85 return auto_launched_with_zero_delay_; |
70 } | 86 } |
71 | 87 |
72 private: | 88 private: |
73 // Updates apps_ based on CrosSettings. | 89 // Updates apps_ based on CrosSettings. |
74 void UpdateApps(); | 90 void UpdateApps(); |
75 | 91 |
76 // Removes cryptohomes of the removed apps. Terminates the session if | 92 // Removes cryptohomes of the removed apps. Terminates the session if |
77 // a removed app is running. | 93 // a removed app is running. |
78 void ClearRemovedApps( | 94 void ClearRemovedApps(const ArcKioskApps& old_apps); |
79 const std::map<std::string, std::unique_ptr<ArcKioskAppData>>& old_apps); | |
80 | 95 |
81 std::vector<std::unique_ptr<ArcKioskAppData>> apps_; | 96 ArcKioskApps apps_; |
82 AccountId auto_launch_account_id_; | 97 AccountId auto_launch_account_id_; |
83 bool auto_launched_with_zero_delay_ = false; | 98 bool auto_launched_with_zero_delay_ = false; |
84 base::ObserverList<ArcKioskAppManagerObserver, true> observers_; | 99 base::ObserverList<ArcKioskAppManagerObserver, true> observers_; |
85 | 100 |
86 std::unique_ptr<CrosSettings::ObserverSubscription> | 101 std::unique_ptr<CrosSettings::ObserverSubscription> |
87 local_accounts_subscription_; | 102 local_accounts_subscription_; |
88 std::unique_ptr<CrosSettings::ObserverSubscription> | 103 std::unique_ptr<CrosSettings::ObserverSubscription> |
89 local_account_auto_login_id_subscription_; | 104 local_account_auto_login_id_subscription_; |
90 | 105 |
91 DISALLOW_COPY_AND_ASSIGN(ArcKioskAppManager); | 106 DISALLOW_COPY_AND_ASSIGN(ArcKioskAppManager); |
92 }; | 107 }; |
93 | 108 |
94 } // namespace chromeos | 109 } // namespace chromeos |
95 | 110 |
96 #endif // CHROME_BROWSER_CHROMEOS_APP_MODE_ARC_ARC_KIOSK_APP_MANAGER_H_ | 111 #endif // CHROME_BROWSER_CHROMEOS_APP_MODE_ARC_ARC_KIOSK_APP_MANAGER_H_ |
OLD | NEW |