forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjob_list.h
139 lines (105 loc) · 3.62 KB
/
job_list.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// 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 COMPONENTS_DRIVE_JOB_LIST_H_
#define COMPONENTS_DRIVE_JOB_LIST_H_
#include <string>
#include "base/basictypes.h"
#include "base/files/file_path.h"
#include "components/drive/file_errors.h"
namespace drive {
// Enum representing the type of job.
enum JobType {
TYPE_GET_ABOUT_RESOURCE,
TYPE_GET_APP_LIST,
TYPE_GET_ALL_RESOURCE_LIST,
TYPE_GET_RESOURCE_LIST_IN_DIRECTORY,
TYPE_SEARCH,
TYPE_GET_CHANGE_LIST,
TYPE_GET_REMAINING_CHANGE_LIST,
TYPE_GET_REMAINING_FILE_LIST,
TYPE_GET_RESOURCE_ENTRY,
TYPE_GET_SHARE_URL,
TYPE_TRASH_RESOURCE,
TYPE_COPY_RESOURCE,
TYPE_UPDATE_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,
TYPE_ADD_PERMISSION,
};
// 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 job_type);
// 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;
// Time when the job is started (i.e. the request is sent to the server).
base::Time start_time;
// Returns the string representation of the job info.
std::string ToString() const;
};
// Checks if |job_info| represents a job for currently active file transfer.
bool IsActiveFileTransferJobInfo(const JobInfo& job_info);
// 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 // COMPONENTS_DRIVE_JOB_LIST_H_