#ifndef CHROME_BROWSER_ASH_FILE_MANAGER_IO_TASK_CONTROLLER_H_
#define CHROME_BROWSER_ASH_FILE_MANAGER_IO_TASK_CONTROLLER_H_
#include <map>
#include <memory>
#include "base/containers/flat_map.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "base/sequence_checker.h"
#include "base/task/sequenced_task_runner.h"
#include "base/time/time.h"
#include "chrome/browser/ash/file_manager/io_task.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/device/public/mojom/wake_lock.mojom.h"
#include "storage/browser/file_system/file_system_file_util.h"
namespace file_manager {
namespace io_task {
class IOTaskController {
public:
IOTaskController();
IOTaskController(const IOTaskController& other) = delete;
IOTaskController operator=(const IOTaskController& other) = delete;
~IOTaskController();
class Observer : public base::CheckedObserver {
public:
virtual void OnIOTaskStatus(const ProgressStatus& status) = 0;
};
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
IOTaskId Add(std::unique_ptr<IOTask> task);
void Pause(IOTaskId task_id, PauseParams params);
void Resume(IOTaskId task_id, ResumeParams params);
void Cancel(IOTaskId task_id);
void ProgressPausedTasks();
void CompleteWithError(IOTaskId task_id, PolicyError policy_error);
std::vector<std::reference_wrapper<const ProgressStatus>> TaskStatuses();
int wake_lock_counter_for_tests() const {
return wake_lock_counter_for_tests_;
}
private:
void MaybeNotifyIOTaskObservers(const ProgressStatus& status);
void NotifyIOTaskObservers(const ProgressStatus& status);
void OnIOTaskProgress(const ProgressStatus& status);
void OnIOTaskComplete(IOTaskId task_id, ProgressStatus status);
device::mojom::WakeLock* GetWakeLock();
IOTask* PutIOTask(const IOTaskId task_id, std::unique_ptr<IOTask> task);
void RemoveIOTask(const IOTaskId task_id);
SEQUENCE_CHECKER(sequence_checker_);
base::ObserverList<Observer> observers_;
IOTaskId last_id_ = 0;
std::map<IOTaskId, std::unique_ptr<IOTask>> tasks_;
mojo::Remote<device::mojom::WakeLock> wake_lock_;
int wake_lock_counter_for_tests_ = 0;
base::flat_map<IOTaskId, base::Time> tasks_last_update_;
base::WeakPtrFactory<IOTaskController> weak_ptr_factory_{this};
};
}
}
#endif