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.
5 #include "chrome/browser/chromeos/drive/job_list.h"
7 #include "base/logging.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/stringprintf.h"
13 std::string
JobTypeToString(JobType type
) {
15 case TYPE_GET_ABOUT_RESOURCE
:
16 return "TYPE_GET_ABOUT_RESOURCE";
17 case TYPE_GET_APP_LIST
:
18 return "TYPE_GET_APP_LIST";
19 case TYPE_GET_ALL_RESOURCE_LIST
:
20 return "TYPE_GET_ALL_RESOURCE_LIST";
21 case TYPE_GET_RESOURCE_LIST_IN_DIRECTORY
:
22 return "TYPE_GET_RESOURCE_LIST_IN_DIRECTORY";
25 case TYPE_GET_CHANGE_LIST
:
26 return "TYPE_GET_CHANGE_LIST";
27 case TYPE_GET_REMAINING_CHANGE_LIST
:
28 return "TYPE_GET_REMAINING_CHANGE_LIST";
29 case TYPE_GET_REMAINING_FILE_LIST
:
30 return "TYPE_GET_REMAINING_FILE_LIST";
31 case TYPE_GET_RESOURCE_ENTRY
:
32 return "TYPE_GET_RESOURCE_ENTRY";
33 case TYPE_GET_SHARE_URL
:
34 return "TYPE_GET_SHARE_URL";
35 case TYPE_TRASH_RESOURCE
:
36 return "TYPE_TRASH_RESOURCE";
37 case TYPE_COPY_RESOURCE
:
38 return "TYPE_COPY_RESOURCE";
39 case TYPE_UPDATE_RESOURCE
:
40 return "TYPE_UPDATE_RESOURCE";
41 case TYPE_RENAME_RESOURCE
:
42 return "TYPE_RENAME_RESOURCE";
43 case TYPE_ADD_RESOURCE_TO_DIRECTORY
:
44 return "TYPE_ADD_RESOURCE_TO_DIRECTORY";
45 case TYPE_REMOVE_RESOURCE_FROM_DIRECTORY
:
46 return "TYPE_REMOVE_RESOURCE_FROM_DIRECTORY";
47 case TYPE_ADD_NEW_DIRECTORY
:
48 return "TYPE_ADD_NEW_DIRECTORY";
49 case TYPE_DOWNLOAD_FILE
:
50 return "TYPE_DOWNLOAD_FILE";
51 case TYPE_UPLOAD_NEW_FILE
:
52 return "TYPE_UPLOAD_NEW_FILE";
53 case TYPE_UPLOAD_EXISTING_FILE
:
54 return "TYPE_UPLOAD_EXISTING_FILE";
55 case TYPE_CREATE_FILE
:
56 return "TYPE_CREATE_FILE";
57 case TYPE_GET_RESOURCE_LIST_IN_DIRECTORY_BY_WAPI
:
58 return "TYPE_GET_RESOURCE_LIST_IN_DIRECTORY_BY_WAPI";
59 case TYPE_GET_REMAINING_RESOURCE_LIST
:
60 return "TYPE_GET_REMAINING_RESOURCE_LIST";
63 return "(unknown job type)";
66 std::string
JobStateToString(JobState state
) {
71 return "STATE_RUNNING";
76 return "(unknown job state)";
79 JobInfo::JobInfo(JobType in_job_type
)
80 : job_type(in_job_type
),
83 num_completed_bytes(0),
87 std::string
JobInfo::ToString() const {
88 std::string output
= base::StringPrintf(
90 JobTypeToString(job_type
).c_str(),
91 JobStateToString(state
).c_str(),
93 if (job_type
== TYPE_DOWNLOAD_FILE
||
94 job_type
== TYPE_UPLOAD_NEW_FILE
||
95 job_type
== TYPE_UPLOAD_EXISTING_FILE
) {
96 base::StringAppendF(&output
,
98 base::Int64ToString(num_completed_bytes
).c_str(),
99 base::Int64ToString(num_total_bytes
).c_str());
104 bool IsActiveFileTransferJobInfo(const JobInfo
& job_info
) {
105 // Using switch statement so that compiler can warn when new states or types
107 switch (job_info
.state
) {
115 switch (job_info
.job_type
) {
116 case TYPE_GET_ABOUT_RESOURCE
:
117 case TYPE_GET_APP_LIST
:
118 case TYPE_GET_ALL_RESOURCE_LIST
:
119 case TYPE_GET_RESOURCE_LIST_IN_DIRECTORY
:
121 case TYPE_GET_CHANGE_LIST
:
122 case TYPE_GET_REMAINING_CHANGE_LIST
:
123 case TYPE_GET_REMAINING_FILE_LIST
:
124 case TYPE_GET_RESOURCE_ENTRY
:
125 case TYPE_GET_SHARE_URL
:
126 case TYPE_TRASH_RESOURCE
:
127 case TYPE_COPY_RESOURCE
:
128 case TYPE_UPDATE_RESOURCE
:
129 case TYPE_RENAME_RESOURCE
:
130 case TYPE_ADD_RESOURCE_TO_DIRECTORY
:
131 case TYPE_REMOVE_RESOURCE_FROM_DIRECTORY
:
132 case TYPE_ADD_NEW_DIRECTORY
:
133 case TYPE_CREATE_FILE
:
134 case TYPE_GET_RESOURCE_LIST_IN_DIRECTORY_BY_WAPI
:
135 case TYPE_GET_REMAINING_RESOURCE_LIST
:
137 case TYPE_DOWNLOAD_FILE
:
138 case TYPE_UPLOAD_NEW_FILE
:
139 case TYPE_UPLOAD_EXISTING_FILE
: