OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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 #ifndef CHROME_BROWSER_CHROMEOS_APP_MODE_KIOSK_EXTERNAL_UPDATER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_APP_MODE_KIOSK_EXTERNAL_UPDATER_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/files/file_path.h" |
| 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/sequenced_task_runner.h" |
| 14 #include "chrome/browser/chromeos/app_mode/kiosk_external_update_validator.h" |
| 15 #include "chromeos/disks/disk_mount_manager.h" |
| 16 |
| 17 namespace chromeos { |
| 18 |
| 19 class KioskExternalUpdateNotification; |
| 20 |
| 21 // Observes the disk mount/unmount events, scans the usb stick for external |
| 22 // kiosk app updates, validates the external crx, and updates the cache. |
| 23 class KioskExternalUpdater : public disks::DiskMountManager::Observer, |
| 24 public KioskExternalUpdateValidatorDelegate { |
| 25 public: |
| 26 enum ExternalUpdateErrorCode { |
| 27 ERROR_NONE, |
| 28 ERROR_NO_MANIFEST, |
| 29 ERROR_INVALID_MANIFEST, |
| 30 }; |
| 31 |
| 32 KioskExternalUpdater( |
| 33 const scoped_refptr<base::SequencedTaskRunner>& backend_task_runner, |
| 34 const base::FilePath& crx_cache_dir, |
| 35 const base::FilePath& crx_unpack_dir); |
| 36 |
| 37 virtual ~KioskExternalUpdater(); |
| 38 |
| 39 private: |
| 40 enum ExternalUpdateStatus { |
| 41 PENDING, |
| 42 SUCCESS, |
| 43 FAILED, |
| 44 }; |
| 45 struct ExternalUpdate { |
| 46 ExternalUpdate(); |
| 47 |
| 48 std::string app_name; |
| 49 base::FilePath external_crx; |
| 50 ExternalUpdateStatus update_status; |
| 51 base::string16 error; |
| 52 }; |
| 53 |
| 54 // disks::DiskMountManager::Observer overrides. |
| 55 virtual void OnDiskEvent(disks::DiskMountManager::DiskEvent event, |
| 56 const disks::DiskMountManager::Disk* disk) OVERRIDE; |
| 57 virtual void OnDeviceEvent(disks::DiskMountManager::DeviceEvent event, |
| 58 const std::string& device_path) OVERRIDE; |
| 59 virtual void OnMountEvent( |
| 60 disks::DiskMountManager::MountEvent event, |
| 61 MountError error_code, |
| 62 const disks::DiskMountManager::MountPointInfo& mount_info) OVERRIDE; |
| 63 virtual void OnFormatEvent(disks::DiskMountManager::FormatEvent event, |
| 64 FormatError error_code, |
| 65 const std::string& device_path) OVERRIDE; |
| 66 |
| 67 // KioskExternalUpdateValidatorDelegate overrides: |
| 68 virtual void OnExtenalUpdateUnpackSuccess( |
| 69 const std::string& app_id, |
| 70 const std::string& version, |
| 71 const std::string& min_browser_version, |
| 72 const base::FilePath& temp_dir) OVERRIDE; |
| 73 virtual void OnExternalUpdateUnpackFailure( |
| 74 const std::string& app_id) OVERRIDE; |
| 75 |
| 76 // Processes the parsed external update manifest, check |parsing_error| for |
| 77 // any manifest parsing error. |
| 78 void ProcessParsedManifest(ExternalUpdateErrorCode* parsing_error, |
| 79 const base::FilePath& external_update_dir, |
| 80 base::DictionaryValue* parsed_manifest); |
| 81 |
| 82 // Returns true if |external_update_| is interrupted before the updating |
| 83 // completes. |
| 84 bool CheckExternalUpdateInterrupted(); |
| 85 |
| 86 // Validates the external updates. |
| 87 void ValidateExternalUpdates(); |
| 88 |
| 89 // Called upon completion of caching external crx file. |
| 90 // |cache_success| pass in the result of caching crx file. |
| 91 void OnCacheExternalCrx(const std::string& app_id, |
| 92 const base::FilePath& target_file, |
| 93 bool* cache_success); |
| 94 |
| 95 // Returns true if there are any external updates pending. |
| 96 bool IsExternalUpdatePending(); |
| 97 |
| 98 // Returns true if the app with |app_id| should be updated to |
| 99 // |external_extension|. |
| 100 bool ShouldDoExternalUpdate(const std::string& app_id, |
| 101 const std::string& version, |
| 102 const std::string& min_browser_version); |
| 103 |
| 104 void NotifyKioskUpdateProgress(const base::string16& message); |
| 105 |
| 106 void MaybeValidateNextExternalUpdate(); |
| 107 |
| 108 // Notifies the kiosk update status with UI and KioskAppUpdateService, if |
| 109 // there is no kiosk external updates pending. |
| 110 void MayBeNotifyKioskAppUpdate(); |
| 111 |
| 112 void NotifyKioskAppUpdateAvailable(); |
| 113 |
| 114 void ShowKioskUpdateProgress(const base::string16& message); |
| 115 |
| 116 // Dismisses the UI notification for kiosk updates. |
| 117 void DismissKioskUpdateNotificationOnUIThread(); |
| 118 void DismissKioskUpdateNotification(); |
| 119 |
| 120 // Return a detailed message for kiosk updating status. |
| 121 base::string16 GetUpdateReportMessage(); |
| 122 |
| 123 // Task runner for executing file I/O tasks. |
| 124 const scoped_refptr<base::SequencedTaskRunner> backend_task_runner_; |
| 125 |
| 126 // The directory where kiosk crx files are cached. |
| 127 const base::FilePath crx_cache_dir_; |
| 128 |
| 129 // The directory used by SandBoxedUnpacker for unpack extensions. |
| 130 const base::FilePath crx_unpack_dir_; |
| 131 |
| 132 // The path where external crx files resides(usb stick mount path). |
| 133 base::FilePath external_update_path_; |
| 134 |
| 135 // map of app_id: ExternalUpdate |
| 136 typedef std::map<std::string, ExternalUpdate> ExternalUpdateMap; |
| 137 ExternalUpdateMap external_updates_; |
| 138 scoped_ptr<KioskExternalUpdateNotification> notification_; |
| 139 |
| 140 base::WeakPtrFactory<KioskExternalUpdater> weak_factory_; |
| 141 |
| 142 DISALLOW_COPY_AND_ASSIGN(KioskExternalUpdater); |
| 143 }; |
| 144 |
| 145 } // namespace chromeos |
| 146 |
| 147 #endif // CHROME_BROWSER_CHROMEOS_APP_MODE_KIOSK_EXTERNAL_UPDATER_H_ |
OLD | NEW |