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