Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / browser / chromeos / app_mode / kiosk_external_updater.h
blobf56b0f724a23cee24fad3e3989a01188c40fffb4
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_
8 #include <string>
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"
18 namespace chromeos {
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 {
26 public:
27 enum ExternalUpdateErrorCode {
28 ERROR_NONE,
29 ERROR_NO_MANIFEST,
30 ERROR_INVALID_MANIFEST,
33 KioskExternalUpdater(
34 const scoped_refptr<base::SequencedTaskRunner>& backend_task_runner,
35 const base::FilePath& crx_cache_dir,
36 const base::FilePath& crx_unpack_dir);
38 ~KioskExternalUpdater() override;
40 private:
41 enum ExternalUpdateStatus {
42 PENDING,
43 SUCCESS,
44 FAILED,
46 struct ExternalUpdate {
47 ExternalUpdate();
48 ~ExternalUpdate();
50 std::string app_name;
51 extensions::CRXFileInfo external_crx;
52 ExternalUpdateStatus update_status;
53 base::string16 error;
56 // disks::DiskMountManager::Observer overrides.
57 void OnDiskEvent(disks::DiskMountManager::DiskEvent event,
58 const disks::DiskMountManager::Disk* disk) override;
59 void OnDeviceEvent(disks::DiskMountManager::DeviceEvent event,
60 const std::string& device_path) override;
61 void OnMountEvent(
62 disks::DiskMountManager::MountEvent event,
63 MountError error_code,
64 const disks::DiskMountManager::MountPointInfo& mount_info) override;
65 void OnFormatEvent(disks::DiskMountManager::FormatEvent event,
66 FormatError error_code,
67 const std::string& device_path) override;
69 // KioskExternalUpdateValidatorDelegate overrides:
70 void OnExtenalUpdateUnpackSuccess(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 void OnExternalUpdateUnpackFailure(const std::string& app_id) override;
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);
82 // Returns true if |external_update_| is interrupted before the updating
83 // completes.
84 bool CheckExternalUpdateInterrupted();
86 // Validates the external updates.
87 void ValidateExternalUpdates();
89 // Returns true if there are any external updates pending.
90 bool IsExternalUpdatePending();
92 // Returns true if all external updates specified in the manifest are
93 // completed successfully.
94 bool IsAllExternalUpdatesSucceeded();
96 // Returns true if the app with |app_id| should be updated to
97 // |external_extension|.
98 bool ShouldDoExternalUpdate(const std::string& app_id,
99 const std::string& version,
100 const std::string& min_browser_version);
102 // Installs the validated extension into cache.
103 // |*crx_copied| indicates whether the |crx_file| is copied successfully.
104 void PutValidatedExtension(bool* crx_copied,
105 const std::string& app_id,
106 const base::FilePath& crx_file,
107 const std::string& version);
109 // Called upon completion of installing the validated external extension into
110 // the local cache. |success| is true if the operation succeeded.
111 void OnPutValidatedExtension(const std::string& app_id, bool success);
113 void NotifyKioskUpdateProgress(const base::string16& message);
115 void MaybeValidateNextExternalUpdate();
117 // Notifies the kiosk update status with UI and KioskAppUpdateService, if
118 // there is no kiosk external updates pending.
119 void MayBeNotifyKioskAppUpdate();
121 void NotifyKioskAppUpdateAvailable();
123 // Dismisses the UI notification for kiosk updates.
124 void DismissKioskUpdateNotification();
126 // Return a detailed message for kiosk updating status.
127 base::string16 GetUpdateReportMessage();
129 // Task runner for executing file I/O tasks.
130 const scoped_refptr<base::SequencedTaskRunner> backend_task_runner_;
132 // The directory where kiosk crx files are cached.
133 const base::FilePath crx_cache_dir_;
135 // The directory used by SandBoxedUnpacker for unpack extensions.
136 const base::FilePath crx_unpack_dir_;
138 // The path where external crx files resides(usb stick mount path).
139 base::FilePath external_update_path_;
141 // map of app_id: ExternalUpdate
142 typedef std::map<std::string, ExternalUpdate> ExternalUpdateMap;
143 ExternalUpdateMap external_updates_;
144 scoped_ptr<KioskExternalUpdateNotification> notification_;
146 base::WeakPtrFactory<KioskExternalUpdater> weak_factory_;
148 DISALLOW_COPY_AND_ASSIGN(KioskExternalUpdater);
151 } // namespace chromeos
153 #endif // CHROME_BROWSER_CHROMEOS_APP_MODE_KIOSK_EXTERNAL_UPDATER_H_