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