12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file.
42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#ifndef CHROME_BROWSER_CHROMEOS_APP_MODE_KIOSK_APP_MANAGER_H_
62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define CHROME_BROWSER_CHROMEOS_APP_MODE_KIOSK_APP_MANAGER_H_
72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <string>
92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <vector>
102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/basictypes.h"
127d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/callback_forward.h"
132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/lazy_instance.h"
1468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#include "base/memory/scoped_ptr.h"
152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/memory/scoped_vector.h"
162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/observer_list.h"
172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/chromeos/app_mode/kiosk_app_data_delegate.h"
18010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "chrome/browser/chromeos/extensions/external_cache.h"
197d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "chrome/browser/chromeos/policy/enterprise_install_attributes.h"
2068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#include "chrome/browser/chromeos/settings/cros_settings.h"
212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/gfx/image/image_skia.h"
222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class PrefRegistrySimple;
245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class Profile;
252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace base {
272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class RefCountedString;
282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace extensions {
315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class Extension;
32116680a4aac90f2aa7413d9095a592090648e557Ben Murdochclass ExternalLoader;
335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace chromeos {
362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class KioskAppData;
38116680a4aac90f2aa7413d9095a592090648e557Ben Murdochclass KioskAppExternalLoader;
392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class KioskAppManagerObserver;
401320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass KioskExternalUpdater;
412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
42c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// KioskAppManager manages cached app data.
43010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)class KioskAppManager : public KioskAppDataDelegate,
44010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                        public ExternalCache::Delegate {
452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public:
465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  enum ConsumerKioskAutoLaunchStatus {
475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // Consumer kiosk mode auto-launch feature can be enabled on this machine.
485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    CONSUMER_KIOSK_AUTO_LAUNCH_CONFIGURABLE,
495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // Consumer kiosk auto-launch feature is enabled on this machine.
505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    CONSUMER_KIOSK_AUTO_LAUNCH_ENABLED,
515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // Consumer kiosk mode auto-launch feature is disabled and cannot any longer
525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // be enabled on this machine.
535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    CONSUMER_KIOSK_AUTO_LAUNCH_DISABLED,
547d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  };
557d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  typedef base::Callback<void(bool success)> EnableKioskAutoLaunchCallback;
575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  typedef base::Callback<void(ConsumerKioskAutoLaunchStatus status)>
585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      GetConsumerKioskAutoLaunchStatusCallback;
597d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Struct to hold app info returned from GetApps() call.
612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  struct App {
62010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    App(const KioskAppData& data, bool is_extension_pending);
632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    App();
642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    ~App();
652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    std::string app_id;
6790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    std::string user_id;
682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    std::string name;
692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    gfx::ImageSkia icon;
702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    bool is_loading;
712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  };
722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  typedef std::vector<App> Apps;
732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
74868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Name of a dictionary that holds kiosk app info in Local State.
752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Sample layout:
762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  //   "kiosk": {
77868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  //     "auto_login_enabled": true  //
782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  //   }
792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static const char kKioskDictionaryName[];
802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static const char kKeyApps[];
81868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  static const char kKeyAutoLoginState[];
822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Sub directory under DIR_USER_DATA to store cached icon files.
842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static const char kIconCacheDir[];
852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
86010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Sub directory under DIR_USER_DATA to store cached crx files.
87010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  static const char kCrxCacheDir[];
88010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
891320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Sub directory under DIR_USER_DATA to store unpacked crx file for validating
901320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // its signature.
911320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  static const char kCrxUnpackDir[];
921320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Gets the KioskAppManager instance, which is lazily created on first call..
942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static KioskAppManager* Get();
952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
96c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Prepares for shutdown and calls CleanUp() if needed.
97c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  static void Shutdown();
98c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Registers kiosk app entries in local state.
1002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static void RegisterPrefs(PrefRegistrySimple* registry);
1012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Initiates reading of consumer kiosk mode auto-launch status.
1035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void GetConsumerKioskAutoLaunchStatus(
1045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      const GetConsumerKioskAutoLaunchStatusCallback& callback);
1057d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
1065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Enables consumer kiosk mode app auto-launch feature. Upon completion,
1075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // |callback| will be invoked with outcome of this operation.
1085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void EnableConsumerKioskAutoLaunch(
1095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      const EnableKioskAutoLaunchCallback& callback);
1107d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
111a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Returns true if this device is consumer kiosk auto launch enabled.
112a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  bool IsConsumerKioskDeviceWithAutoLaunch();
113a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
1142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Returns auto launcher app id or an empty string if there is none.
1152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  std::string GetAutoLaunchApp() const;
1162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Sets |app_id| as the app to auto launch at start up.
1182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void SetAutoLaunchApp(const std::string& app_id);
1192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
120868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Returns true if there is a pending auto-launch request.
121868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  bool IsAutoLaunchRequested() const;
122868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
123868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Returns true if owner/policy enabled auto launch.
124868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  bool IsAutoLaunchEnabled() const;
125868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
126868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Enable auto launch setter.
127868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  void SetEnableAutoLaunch(bool value);
128868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
1292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Adds/removes a kiosk app by id. When removed, all locally cached data
1302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // will be removed as well.
1312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void AddApp(const std::string& app_id);
1322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void RemoveApp(const std::string& app_id);
1332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
134effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  // Gets info of all apps that have no meta data load error.
1352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void GetApps(Apps* apps) const;
1362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Gets app data for the given app id. Returns true if |app_id| is known and
1382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // |app| is populated. Otherwise, return false.
1392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool GetApp(const std::string& app_id, App* app) const;
1402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Gets the raw icon data for the given app id. Returns NULL if |app_id|
1422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // is unknown.
1432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const base::RefCountedString* GetAppRawIcon(const std::string& app_id) const;
1442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
145c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Gets whether the bailout shortcut is disabled.
146c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  bool GetDisableBailoutShortcut() const;
147c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Clears locally cached app data.
1495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void ClearAppData(const std::string& app_id);
1505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Updates app data from the |app| in |profile|. |app| is provided to cover
1525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // the case of app update case where |app| is the new version and is not
1535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // finished installing (e.g. because old version is still running). Otherwise,
1545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // |app| could be NULL and the current installed app in |profile| will be
1555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // used.
1565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void UpdateAppDataFromProfile(const std::string& app_id,
1575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                Profile* profile,
1585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                const extensions::Extension* app);
1595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
160116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  void RetryFailedAppDataFetch();
161116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
162116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // Returns true if the app is found in cache.
163116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  bool HasCachedCrx(const std::string& app_id) const;
164116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
1651320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Gets the path and version of the cached crx with |app_id|.
1661320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Returns true if the app is found in cache.
1671320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  bool GetCachedCrx(const std::string& app_id,
1681320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                    base::FilePath* file_path,
1691320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                    std::string* version) const;
1701320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
1712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void AddObserver(KioskAppManagerObserver* observer);
1722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void RemoveObserver(KioskAppManagerObserver* observer);
1732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
174116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // Creates extensions::ExternalLoader for installing kiosk apps during their
175116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // first time launch.
176116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  extensions::ExternalLoader* CreateExternalLoader();
177116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
178116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // Installs kiosk app with |id| from cache.
179116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  void InstallFromCache(const std::string& id);
180116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
181116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  void UpdateExternalCache();
182116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
1831320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Monitors kiosk external update from usb stick.
1841320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void MonitorKioskExternalUpdate();
1851320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
1861320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Invoked when kiosk app cache has been updated.
1871320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void OnKioskAppCacheUpdated(const std::string& app_id);
1881320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
1891320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Invoked when kiosk app updating from usb stick has been completed.
1901320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // |success| indicates if all the updates are completed successfully.
1911320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void OnKioskAppExternalUpdateComplete(bool success);
1921320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
1931320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Installs the validated external extension into cache.
1941320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void PutValidatedExternalExtension(
1951320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      const std::string& app_id,
1961320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      const base::FilePath& crx_path,
1971320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      const std::string& version,
1981320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      const ExternalCache::PutExternalExtensionCallback& callback);
1991320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
200116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  bool external_loader_created() const { return external_loader_created_; }
201116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
2022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private:
2032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  friend struct base::DefaultLazyInstanceTraits<KioskAppManager>;
2042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  friend struct base::DefaultDeleter<KioskAppManager>;
2052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  friend class KioskAppManagerTest;
206c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  friend class KioskTest;
207116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  friend class KioskUpdateTest;
2082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
209868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  enum AutoLoginState {
210868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    AUTOLOGIN_NONE      = 0,
211868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    AUTOLOGIN_REQUESTED = 1,
212868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    AUTOLOGIN_APPROVED  = 2,
213868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    AUTOLOGIN_REJECTED  = 3,
214868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  };
215868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
2162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  KioskAppManager();
2172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~KioskAppManager();
2182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
219c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Stop all data loading and remove its dependency on CrosSettings.
220c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  void CleanUp();
221c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
2222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Gets KioskAppData for the given app id.
2232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const KioskAppData* GetAppData(const std::string& app_id) const;
2245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  KioskAppData* GetAppDataMutable(const std::string& app_id);
2252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
226116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // Updates app data |apps_| based on CrosSettings.
2272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void UpdateAppData();
2282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // KioskAppDataDelegate overrides:
2302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void GetKioskAppIconCacheDir(base::FilePath* cache_dir) OVERRIDE;
2312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void OnKioskAppDataChanged(const std::string& app_id) OVERRIDE;
2322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void OnKioskAppDataLoadFailure(const std::string& app_id) OVERRIDE;
2332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
234010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // ExternalCache::Delegate:
235010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  virtual void OnExtensionListsUpdated(
236010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      const base::DictionaryValue* prefs) OVERRIDE;
237010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  virtual void OnExtensionLoadedInCache(const std::string& id) OVERRIDE;
238010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  virtual void OnExtensionDownloadFailed(
239010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      const std::string& id,
240010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      extensions::ExtensionDownloaderDelegate::Error error) OVERRIDE;
241010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
2427d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Callback for EnterpriseInstallAttributes::LockDevice() during
2437d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // EnableConsumerModeKiosk() call.
2447d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  void OnLockDevice(
2455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      const EnableKioskAutoLaunchCallback& callback,
2467d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      policy::EnterpriseInstallAttributes::LockResult result);
2477d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
2487d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Callback for EnterpriseInstallAttributes::ReadImmutableAttributes() during
2497d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // GetConsumerKioskModeStatus() call.
2507d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  void OnReadImmutableAttributes(
2515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      const GetConsumerKioskAutoLaunchStatusCallback& callback);
2527d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
2537d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Callback for reading handling checks of the owner public.
2547d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  void OnOwnerFileChecked(
2555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      const GetConsumerKioskAutoLaunchStatusCallback& callback,
2565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      bool* owner_present);
2577d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
258868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Reads/writes auto login state from/to local state.
259868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  AutoLoginState GetAutoLoginState() const;
260868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  void SetAutoLoginState(AutoLoginState state);
261868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
262cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  void GetCrxCacheDir(base::FilePath* cache_dir);
2631320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void GetCrxUnpackDir(base::FilePath* unpack_dir);
264010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
2657d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // True if machine ownership is already established.
2667d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  bool ownership_established_;
2672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ScopedVector<KioskAppData> apps_;
268c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  std::string auto_launch_app_id_;
2692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ObserverList<KioskAppManagerObserver, true> observers_;
2702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
27168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  scoped_ptr<CrosSettings::ObserverSubscription>
27268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)      local_accounts_subscription_;
27368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  scoped_ptr<CrosSettings::ObserverSubscription>
27468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)      local_account_auto_login_id_subscription_;
27568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
276010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  scoped_ptr<ExternalCache> external_cache_;
2771320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  scoped_ptr<KioskExternalUpdater> usb_stick_updater_;
278010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
279116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // The extension external loader for installing kiosk app.
280116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  bool external_loader_created_;
281116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  base::WeakPtr<KioskAppExternalLoader> external_loader_;
282116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
2832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(KioskAppManager);
2842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
2852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}  // namespace chromeos
2872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif  // CHROME_BROWSER_CHROMEOS_APP_MODE_KIOSK_APP_MANAGER_H_
289