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.
5 #ifndef CHROME_BROWSER_CHROMEOS_APP_MODE_KIOSK_EXTERNAL_UPDATER_H_
6 #define CHROME_BROWSER_CHROMEOS_APP_MODE_KIOSK_EXTERNAL_UPDATER_H_
10 #include "base/files/file_path.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/observer_list.h"
14 #include "base/sequenced_task_runner.h"
15 #include "chrome/browser/chromeos/app_mode/kiosk_external_update_validator.h"
16 #include "chromeos/disks/disk_mount_manager.h"
20 class KioskExternalUpdateNotification;
22 // Observes the disk mount/unmount events, scans the usb stick for external
23 // kiosk app updates, validates the external crx, and updates the cache.
24 class KioskExternalUpdater : public disks::DiskMountManager::Observer,
25 public KioskExternalUpdateValidatorDelegate {
27 enum ExternalUpdateErrorCode {
30 ERROR_INVALID_MANIFEST,
34 const scoped_refptr<base::SequencedTaskRunner>& backend_task_runner,
35 const base::FilePath& crx_cache_dir,
36 const base::FilePath& crx_unpack_dir);
38 virtual ~KioskExternalUpdater();
41 enum ExternalUpdateStatus {
46 struct ExternalUpdate {
50 base::FilePath external_crx;
51 ExternalUpdateStatus update_status;
55 // disks::DiskMountManager::Observer overrides.
56 virtual void OnDiskEvent(disks::DiskMountManager::DiskEvent event,
57 const disks::DiskMountManager::Disk* disk) OVERRIDE;
58 virtual void OnDeviceEvent(disks::DiskMountManager::DeviceEvent event,
59 const std::string& device_path) OVERRIDE;
60 virtual void OnMountEvent(
61 disks::DiskMountManager::MountEvent event,
62 MountError error_code,
63 const disks::DiskMountManager::MountPointInfo& mount_info) OVERRIDE;
64 virtual void OnFormatEvent(disks::DiskMountManager::FormatEvent event,
65 FormatError error_code,
66 const std::string& device_path) OVERRIDE;
68 // KioskExternalUpdateValidatorDelegate overrides:
69 virtual void OnExtenalUpdateUnpackSuccess(
70 const std::string& app_id,
71 const std::string& version,
72 const std::string& min_browser_version,
73 const base::FilePath& temp_dir) OVERRIDE;
74 virtual void OnExternalUpdateUnpackFailure(
75 const std::string& app_id) OVERRIDE;
77 // Processes the parsed external update manifest, check |parsing_error| for
78 // any manifest parsing error.
79 void ProcessParsedManifest(ExternalUpdateErrorCode* parsing_error,
80 const base::FilePath& external_update_dir,
81 base::DictionaryValue* parsed_manifest);
83 // Returns true if |external_update_| is interrupted before the updating
85 bool CheckExternalUpdateInterrupted();
87 // Validates the external updates.
88 void ValidateExternalUpdates();
90 // Returns true if there are any external updates pending.
91 bool IsExternalUpdatePending();
93 // Returns true if all external updates specified in the manifest are
94 // completed successfully.
95 bool IsAllExternalUpdatesSucceeded();
97 // Returns true if the app with |app_id| should be updated to
98 // |external_extension|.
99 bool ShouldDoExternalUpdate(const std::string& app_id,
100 const std::string& version,
101 const std::string& min_browser_version);
103 // Installs the validated extension into cache.
104 // |*crx_copied| indicates whether the |crx_file| is copied successfully.
105 void PutValidatedExtension(bool* crx_copied,
106 const std::string& app_id,
107 const base::FilePath& crx_file,
108 const std::string& version);
110 // Called upon completion of installing the validated external extension into
111 // the local cache. |success| is true if the operation succeeded.
112 void OnPutValidatedExtension(const std::string& app_id, bool success);
114 void NotifyKioskUpdateProgress(const base::string16& message);
116 void MaybeValidateNextExternalUpdate();
118 // Notifies the kiosk update status with UI and KioskAppUpdateService, if
119 // there is no kiosk external updates pending.
120 void MayBeNotifyKioskAppUpdate();
122 void NotifyKioskAppUpdateAvailable();
124 // Dismisses the UI notification for kiosk updates.
125 void DismissKioskUpdateNotification();
127 // Return a detailed message for kiosk updating status.
128 base::string16 GetUpdateReportMessage();
130 // Task runner for executing file I/O tasks.
131 const scoped_refptr<base::SequencedTaskRunner> backend_task_runner_;
133 // The directory where kiosk crx files are cached.
134 const base::FilePath crx_cache_dir_;
136 // The directory used by SandBoxedUnpacker for unpack extensions.
137 const base::FilePath crx_unpack_dir_;
139 // The path where external crx files resides(usb stick mount path).
140 base::FilePath external_update_path_;
142 // map of app_id: ExternalUpdate
143 typedef std::map<std::string, ExternalUpdate> ExternalUpdateMap;
144 ExternalUpdateMap external_updates_;
145 scoped_ptr<KioskExternalUpdateNotification> notification_;
147 base::WeakPtrFactory<KioskExternalUpdater> weak_factory_;
149 DISALLOW_COPY_AND_ASSIGN(KioskExternalUpdater);
152 } // namespace chromeos
154 #endif // CHROME_BROWSER_CHROMEOS_APP_MODE_KIOSK_EXTERNAL_UPDATER_H_