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. 4 5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_JOB_LIST_H_ 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_JOB_LIST_H_ 7 8 #include <string> 9 10 #include "base/basictypes.h" 11 #include "base/files/file_path.h" 12 #include "chrome/browser/chromeos/drive/file_errors.h" 13 14 namespace drive { 15 16 // Enum representing the type of job. 17 enum JobType { 18 TYPE_GET_ABOUT_RESOURCE, 19 TYPE_GET_APP_LIST, 20 TYPE_GET_ALL_RESOURCE_LIST, 21 TYPE_GET_RESOURCE_LIST_IN_DIRECTORY, 22 TYPE_SEARCH, 23 TYPE_GET_CHANGE_LIST, 24 TYPE_GET_REMAINING_CHANGE_LIST, 25 TYPE_GET_REMAINING_FILE_LIST, 26 TYPE_GET_RESOURCE_ENTRY, 27 TYPE_GET_SHARE_URL, 28 TYPE_TRASH_RESOURCE, 29 TYPE_COPY_RESOURCE, 30 TYPE_UPDATE_RESOURCE, 31 TYPE_RENAME_RESOURCE, 32 TYPE_ADD_RESOURCE_TO_DIRECTORY, 33 TYPE_REMOVE_RESOURCE_FROM_DIRECTORY, 34 TYPE_ADD_NEW_DIRECTORY, 35 TYPE_DOWNLOAD_FILE, 36 TYPE_UPLOAD_NEW_FILE, 37 TYPE_UPLOAD_EXISTING_FILE, 38 TYPE_CREATE_FILE, 39 TYPE_GET_RESOURCE_LIST_IN_DIRECTORY_BY_WAPI, 40 TYPE_GET_REMAINING_RESOURCE_LIST, 41 }; 42 43 // Returns the string representation of |type|. 44 std::string JobTypeToString(JobType type); 45 46 // Current state of the job. 47 enum JobState { 48 // The job is queued, but not yet executed. 49 STATE_NONE, 50 51 // The job is in the process of being handled. 52 STATE_RUNNING, 53 54 // The job failed, but has been re-added to the queue. 55 STATE_RETRY, 56 }; 57 58 // Returns the string representation of |state|. 59 std::string JobStateToString(JobState state); 60 61 // Unique ID assigned to each job. 62 typedef int32 JobID; 63 64 // Information about a specific job that is visible to other systems. 65 struct JobInfo { 66 explicit JobInfo(JobType job_type); 67 68 // Type of the job. 69 JobType job_type; 70 71 // Id of the job, which can be used to query or modify it. 72 JobID job_id; 73 74 // Current state of the operation. 75 JobState state; 76 77 // The fields below are available only for jobs with job_type: 78 // TYPE_DOWNLOAD_FILE, TYPE_UPLOAD_NEW_FILE, or TYPE_UPLOAD_EXISTING_FILE. 79 80 // Number of bytes completed. 81 int64 num_completed_bytes; 82 83 // Total bytes of this operation. 84 int64 num_total_bytes; 85 86 // Drive path of the file that this job acts on. 87 base::FilePath file_path; 88 89 // Time when the job is started (i.e. the request is sent to the server). 90 base::Time start_time; 91 92 // Returns the string representation of the job info. 93 std::string ToString() const; 94 }; 95 96 // Checks if |job_info| represents a job for currently active file transfer. 97 bool IsActiveFileTransferJobInfo(const JobInfo& job_info); 98 99 // The interface for observing JobListInterface. 100 // All events are notified in the UI thread. 101 class JobListObserver { 102 public: 103 // Called when a new job id added. 104 virtual void OnJobAdded(const JobInfo& job_info) {} 105 106 // Called when a job id finished. 107 // |error| is FILE_ERROR_OK when the job successfully finished, and a value 108 // telling the reason of failure when the jobs is failed. 109 virtual void OnJobDone(const JobInfo& job_info, 110 FileError error) {} 111 112 // Called when a job status is updated. 113 virtual void OnJobUpdated(const JobInfo& job_info) {} 114 115 protected: 116 virtual ~JobListObserver() {} 117 }; 118 119 // The interface to expose the list of issued Drive jobs. 120 class JobListInterface { 121 public: 122 virtual ~JobListInterface() {} 123 124 // Returns the list of jobs currently managed by the scheduler. 125 virtual std::vector<JobInfo> GetJobInfoList() = 0; 126 127 // Adds an observer. 128 virtual void AddObserver(JobListObserver* observer) = 0; 129 130 // Removes an observer. 131 virtual void RemoveObserver(JobListObserver* observer) = 0; 132 133 // Cancels the job. 134 virtual void CancelJob(JobID job_id) = 0; 135 136 // Cancels all the jobs. 137 virtual void CancelAllJobs() = 0; 138 }; 139 140 } // namespace drive 141 142 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_JOB_LIST_H_ 143