diff options
Diffstat (limited to 'chrome/browser/chromeos/drive/job_list.h')
-rw-r--r-- | chrome/browser/chromeos/drive/job_list.h | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/chrome/browser/chromeos/drive/job_list.h b/chrome/browser/chromeos/drive/job_list.h new file mode 100644 index 0000000..9805e5d --- /dev/null +++ b/chrome/browser/chromeos/drive/job_list.h @@ -0,0 +1,134 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_CHROMEOS_DRIVE_JOB_LIST_H_ +#define CHROME_BROWSER_CHROMEOS_DRIVE_JOB_LIST_H_ + +#include <string> + +#include "base/basictypes.h" +#include "base/files/file_path.h" +#include "chrome/browser/chromeos/drive/file_errors.h" + +namespace drive { + +// Enum representing the type of job. +enum JobType { + TYPE_GET_ABOUT_RESOURCE, + TYPE_GET_ACCOUNT_METADATA, + TYPE_GET_APP_LIST, + TYPE_GET_ALL_RESOURCE_LIST, + TYPE_GET_RESOURCE_LIST_IN_DIRECTORY, + TYPE_SEARCH, + TYPE_GET_CHANGE_LIST, + TYPE_CONTINUE_GET_RESOURCE_LIST, + TYPE_GET_RESOURCE_ENTRY, + TYPE_DELETE_RESOURCE, + TYPE_COPY_HOSTED_DOCUMENT, + TYPE_RENAME_RESOURCE, + TYPE_ADD_RESOURCE_TO_DIRECTORY, + TYPE_REMOVE_RESOURCE_FROM_DIRECTORY, + TYPE_ADD_NEW_DIRECTORY, + TYPE_DOWNLOAD_FILE, + TYPE_UPLOAD_NEW_FILE, + TYPE_UPLOAD_EXISTING_FILE, +}; + +// Returns the string representation of |type|. +std::string JobTypeToString(JobType type); + +// Current state of the job. +enum JobState { + // The job is queued, but not yet executed. + STATE_NONE, + + // The job is in the process of being handled. + STATE_RUNNING, + + // The job failed, but has been re-added to the queue. + STATE_RETRY, +}; + +// Returns the string representation of |state|. +std::string JobStateToString(JobState state); + +// Unique ID assigned to each job. +typedef int32 JobID; + +// Information about a specific job that is visible to other systems. +struct JobInfo { + explicit JobInfo(JobType in_job_type) + : job_type(in_job_type), + job_id(-1), + state(STATE_NONE), + num_completed_bytes(0), + num_total_bytes(0) { + } + + // Type of the job. + JobType job_type; + + // Id of the job, which can be used to query or modify it. + JobID job_id; + + // Current state of the operation. + JobState state; + + // The fields below are available only for jobs with job_type: + // TYPE_DOWNLOAD_FILE, TYPE_UPLOAD_NEW_FILE, or TYPE_UPLOAD_EXISTING_FILE. + + // Number of bytes completed. + int64 num_completed_bytes; + + // Total bytes of this operation. + int64 num_total_bytes; + + // Drive path of the file that this job acts on. + base::FilePath file_path; +}; + +// The interface for observing JobListInterface. +// All events are notified in the UI thread. +class JobListObserver { + public: + // Called when a new job id added. + virtual void OnJobAdded(const JobInfo& job_info) {} + + // Called when a job id finished. + // |error| is FILE_ERROR_OK when the job successfully finished, and a value + // telling the reason of failure when the jobs is failed. + virtual void OnJobDone(const JobInfo& job_info, + FileError error) {} + + // Called when a job status is updated. + virtual void OnJobUpdated(const JobInfo& job_info) {} + + protected: + virtual ~JobListObserver() {} +}; + +// The interface to expose the list of issued Drive jobs. +class JobListInterface { + public: + virtual ~JobListInterface() {} + + // Returns the list of jobs currently managed by the scheduler. + virtual std::vector<JobInfo> GetJobInfoList() = 0; + + // Adds an observer. + virtual void AddObserver(JobListObserver* observer) = 0; + + // Removes an observer. + virtual void RemoveObserver(JobListObserver* observer) = 0; + + // Cancels the job. + virtual void CancelJob(JobID job_id) = 0; + + // Cancels all the jobs. + virtual void CancelAllJobs() = 0; +}; + +} // namespace drive + +#endif // CHROME_BROWSER_CHROMEOS_DRIVE_JOB_LIST_H_ |