1 // Copyright 2013 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.
5 #ifndef CHROME_BROWSER_CHROMEOS_APP_MODE_KIOSK_APP_MANAGER_H_
6 #define CHROME_BROWSER_CHROMEOS_APP_MODE_KIOSK_APP_MANAGER_H_
11 #include "base/basictypes.h"
12 #include "base/callback_forward.h"
13 #include "base/lazy_instance.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/scoped_vector.h"
16 #include "base/observer_list.h"
17 #include "chrome/browser/chromeos/app_mode/kiosk_app_data_delegate.h"
18 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h"
19 #include "chrome/browser/chromeos/settings/cros_settings.h"
20 #include "ui/gfx/image/image_skia.h"
22 class PrefRegistrySimple
;
26 class RefCountedString
;
29 namespace extensions
{
36 class KioskAppManagerObserver
;
38 // KioskAppManager manages cached app data.
39 class KioskAppManager
: public KioskAppDataDelegate
{
41 enum ConsumerKioskModeStatus
{
42 // Consumer kiosk mode can be enabled on this machine.
43 CONSUMER_KIOSK_MODE_CONFIGURABLE
,
44 // Consumer kiosk is enabled on this machine.
45 CONSUMER_KIOSK_MODE_ENABLED
,
46 // Consumer kiosk mode is disabled ans cannot any longer be enabled on
48 CONSUMER_KIOSK_MODE_DISABLED
,
51 typedef base::Callback
<void(bool success
)> EnableKioskModeCallback
;
52 typedef base::Callback
<void(ConsumerKioskModeStatus status
)>
53 GetConsumerKioskModeStatusCallback
;
55 // Struct to hold app info returned from GetApps() call.
57 explicit App(const KioskAppData
& data
);
67 typedef std::vector
<App
> Apps
;
69 // Name of a dictionary that holds kiosk app info in Local State.
72 // "auto_login_enabled": true //
74 static const char kKioskDictionaryName
[];
75 static const char kKeyApps
[];
76 static const char kKeyAutoLoginState
[];
78 // Sub directory under DIR_USER_DATA to store cached icon files.
79 static const char kIconCacheDir
[];
81 // Gets the KioskAppManager instance, which is lazily created on first call..
82 static KioskAppManager
* Get();
84 // Prepares for shutdown and calls CleanUp() if needed.
85 static void Shutdown();
87 // Registers kiosk app entries in local state.
88 static void RegisterPrefs(PrefRegistrySimple
* registry
);
90 // Initiates reading of consumer kiosk mode status.
91 void GetConsumerKioskModeStatus(
92 const GetConsumerKioskModeStatusCallback
& callback
);
94 // Enables consumer kiosk mode feature. Upon completion, |callback| will be
95 // invoked with outcome of this operation.
96 void EnableConsumerModeKiosk(const EnableKioskModeCallback
& callback
);
98 // Returns auto launcher app id or an empty string if there is none.
99 std::string
GetAutoLaunchApp() const;
101 // Sets |app_id| as the app to auto launch at start up.
102 void SetAutoLaunchApp(const std::string
& app_id
);
104 // Returns true if there is a pending auto-launch request.
105 bool IsAutoLaunchRequested() const;
107 // Returns true if owner/policy enabled auto launch.
108 bool IsAutoLaunchEnabled() const;
110 // Enable auto launch setter.
111 void SetEnableAutoLaunch(bool value
);
113 // Adds/removes a kiosk app by id. When removed, all locally cached data
114 // will be removed as well.
115 void AddApp(const std::string
& app_id
);
116 void RemoveApp(const std::string
& app_id
);
118 // Gets info of all apps.
119 void GetApps(Apps
* apps
) const;
121 // Gets app data for the given app id. Returns true if |app_id| is known and
122 // |app| is populated. Otherwise, return false.
123 bool GetApp(const std::string
& app_id
, App
* app
) const;
125 // Gets the raw icon data for the given app id. Returns NULL if |app_id|
127 const base::RefCountedString
* GetAppRawIcon(const std::string
& app_id
) const;
129 // Gets whether the bailout shortcut is disabled.
130 bool GetDisableBailoutShortcut() const;
132 // Clears locally cached app data.
133 void ClearAppData(const std::string
& app_id
);
135 // Updates app data from the |app| in |profile|. |app| is provided to cover
136 // the case of app update case where |app| is the new version and is not
137 // finished installing (e.g. because old version is still running). Otherwise,
138 // |app| could be NULL and the current installed app in |profile| will be
140 void UpdateAppDataFromProfile(const std::string
& app_id
,
142 const extensions::Extension
* app
);
144 void AddObserver(KioskAppManagerObserver
* observer
);
145 void RemoveObserver(KioskAppManagerObserver
* observer
);
148 friend struct base::DefaultLazyInstanceTraits
<KioskAppManager
>;
149 friend struct base::DefaultDeleter
<KioskAppManager
>;
150 friend class KioskAppManagerTest
;
151 friend class KioskTest
;
153 enum AutoLoginState
{
155 AUTOLOGIN_REQUESTED
= 1,
156 AUTOLOGIN_APPROVED
= 2,
157 AUTOLOGIN_REJECTED
= 3,
161 virtual ~KioskAppManager();
163 // Stop all data loading and remove its dependency on CrosSettings.
166 // Gets KioskAppData for the given app id.
167 const KioskAppData
* GetAppData(const std::string
& app_id
) const;
168 KioskAppData
* GetAppDataMutable(const std::string
& app_id
);
170 // Update app data |apps_| based on CrosSettings.
171 void UpdateAppData();
173 // KioskAppDataDelegate overrides:
174 virtual void GetKioskAppIconCacheDir(base::FilePath
* cache_dir
) OVERRIDE
;
175 virtual void OnKioskAppDataChanged(const std::string
& app_id
) OVERRIDE
;
176 virtual void OnKioskAppDataLoadFailure(const std::string
& app_id
) OVERRIDE
;
178 // Callback for EnterpriseInstallAttributes::LockDevice() during
179 // EnableConsumerModeKiosk() call.
181 const EnableKioskModeCallback
& callback
,
182 policy::EnterpriseInstallAttributes::LockResult result
);
184 // Callback for EnterpriseInstallAttributes::ReadImmutableAttributes() during
185 // GetConsumerKioskModeStatus() call.
186 void OnReadImmutableAttributes(
187 const GetConsumerKioskModeStatusCallback
& callback
);
189 // Callback for reading handling checks of the owner public.
190 void OnOwnerFileChecked(
191 const GetConsumerKioskModeStatusCallback
& callback
,
192 bool* owner_present
);
194 // Reads/writes auto login state from/to local state.
195 AutoLoginState
GetAutoLoginState() const;
196 void SetAutoLoginState(AutoLoginState state
);
198 // True if machine ownership is already established.
199 bool ownership_established_
;
200 ScopedVector
<KioskAppData
> apps_
;
201 std::string auto_launch_app_id_
;
202 ObserverList
<KioskAppManagerObserver
, true> observers_
;
204 scoped_ptr
<CrosSettings::ObserverSubscription
>
205 local_accounts_subscription_
;
206 scoped_ptr
<CrosSettings::ObserverSubscription
>
207 local_account_auto_login_id_subscription_
;
209 DISALLOW_COPY_AND_ASSIGN(KioskAppManager
);
212 } // namespace chromeos
214 #endif // CHROME_BROWSER_CHROMEOS_APP_MODE_KIOSK_APP_MANAGER_H_