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