1 // Copyright 2013 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_DRIVE_JOB_LIST_H_
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_JOB_LIST_H_
10 #include "base/basictypes.h"
11 #include "base/files/file_path.h"
12 #include "chrome/browser/chromeos/drive/file_errors.h"
16 // Enum representing the type of job.
18 TYPE_GET_ABOUT_RESOURCE,
20 TYPE_GET_ALL_RESOURCE_LIST,
21 TYPE_GET_RESOURCE_LIST_IN_DIRECTORY,
24 TYPE_GET_REMAINING_CHANGE_LIST,
25 TYPE_GET_REMAINING_FILE_LIST,
26 TYPE_GET_RESOURCE_ENTRY,
32 TYPE_ADD_RESOURCE_TO_DIRECTORY,
33 TYPE_REMOVE_RESOURCE_FROM_DIRECTORY,
34 TYPE_ADD_NEW_DIRECTORY,
37 TYPE_UPLOAD_EXISTING_FILE,
42 // Returns the string representation of |type|.
43 std::string JobTypeToString(JobType type);
45 // Current state of the job.
47 // The job is queued, but not yet executed.
50 // The job is in the process of being handled.
53 // The job failed, but has been re-added to the queue.
57 // Returns the string representation of |state|.
58 std::string JobStateToString(JobState state);
60 // Unique ID assigned to each job.
63 // Information about a specific job that is visible to other systems.
65 explicit JobInfo(JobType job_type);
70 // Id of the job, which can be used to query or modify it.
73 // Current state of the operation.
76 // The fields below are available only for jobs with job_type:
77 // TYPE_DOWNLOAD_FILE, TYPE_UPLOAD_NEW_FILE, or TYPE_UPLOAD_EXISTING_FILE.
79 // Number of bytes completed.
80 int64 num_completed_bytes;
82 // Total bytes of this operation.
83 int64 num_total_bytes;
85 // Drive path of the file that this job acts on.
86 base::FilePath file_path;
88 // Time when the job is started (i.e. the request is sent to the server).
89 base::Time start_time;
91 // Returns the string representation of the job info.
92 std::string ToString() const;
95 // Checks if |job_info| represents a job for currently active file transfer.
96 bool IsActiveFileTransferJobInfo(const JobInfo& job_info);
98 // The interface for observing JobListInterface.
99 // All events are notified in the UI thread.
100 class JobListObserver {
102 // Called when a new job id added.
103 virtual void OnJobAdded(const JobInfo& job_info) {}
105 // Called when a job id finished.
106 // |error| is FILE_ERROR_OK when the job successfully finished, and a value
107 // telling the reason of failure when the jobs is failed.
108 virtual void OnJobDone(const JobInfo& job_info,
111 // Called when a job status is updated.
112 virtual void OnJobUpdated(const JobInfo& job_info) {}
115 virtual ~JobListObserver() {}
118 // The interface to expose the list of issued Drive jobs.
119 class JobListInterface {
121 virtual ~JobListInterface() {}
123 // Returns the list of jobs currently managed by the scheduler.
124 virtual std::vector<JobInfo> GetJobInfoList() = 0;
127 virtual void AddObserver(JobListObserver* observer) = 0;
129 // Removes an observer.
130 virtual void RemoveObserver(JobListObserver* observer) = 0;
133 virtual void CancelJob(JobID job_id) = 0;
135 // Cancels all the jobs.
136 virtual void CancelAllJobs() = 0;
141 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_JOB_LIST_H_