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_ADD_RESOURCE_TO_DIRECTORY
:
42 return "TYPE_ADD_RESOURCE_TO_DIRECTORY";
43 case TYPE_REMOVE_RESOURCE_FROM_DIRECTORY
:
44 return "TYPE_REMOVE_RESOURCE_FROM_DIRECTORY";
45 case TYPE_ADD_NEW_DIRECTORY
:
46 return "TYPE_ADD_NEW_DIRECTORY";
47 case TYPE_DOWNLOAD_FILE
:
48 return "TYPE_DOWNLOAD_FILE";
49 case TYPE_UPLOAD_NEW_FILE
:
50 return "TYPE_UPLOAD_NEW_FILE";
51 case TYPE_UPLOAD_EXISTING_FILE
:
52 return "TYPE_UPLOAD_EXISTING_FILE";
53 case TYPE_ADD_PERMISSION
:
54 return "TYPE_ADD_PERMISSION";
57 return "(unknown job type)";
60 std::string
JobStateToString(JobState state
) {
65 return "STATE_RUNNING";
70 return "(unknown job state)";
73 JobInfo::JobInfo(JobType in_job_type
)
74 : job_type(in_job_type
),
77 num_completed_bytes(0),
81 std::string
JobInfo::ToString() const {
82 std::string output
= base::StringPrintf(
84 JobTypeToString(job_type
).c_str(),
85 JobStateToString(state
).c_str(),
87 if (job_type
== TYPE_DOWNLOAD_FILE
||
88 job_type
== TYPE_UPLOAD_NEW_FILE
||
89 job_type
== TYPE_UPLOAD_EXISTING_FILE
) {
90 base::StringAppendF(&output
,
92 base::Int64ToString(num_completed_bytes
).c_str(),
93 base::Int64ToString(num_total_bytes
).c_str());
98 bool IsActiveFileTransferJobInfo(const JobInfo
& job_info
) {
99 // Using switch statement so that compiler can warn when new states or types
101 switch (job_info
.job_type
) {
102 case TYPE_GET_ABOUT_RESOURCE
:
103 case TYPE_GET_APP_LIST
:
104 case TYPE_GET_ALL_RESOURCE_LIST
:
105 case TYPE_GET_RESOURCE_LIST_IN_DIRECTORY
:
107 case TYPE_GET_CHANGE_LIST
:
108 case TYPE_GET_REMAINING_CHANGE_LIST
:
109 case TYPE_GET_REMAINING_FILE_LIST
:
110 case TYPE_GET_RESOURCE_ENTRY
:
111 case TYPE_GET_SHARE_URL
:
112 case TYPE_TRASH_RESOURCE
:
113 case TYPE_COPY_RESOURCE
:
114 case TYPE_UPDATE_RESOURCE
:
115 case TYPE_ADD_RESOURCE_TO_DIRECTORY
:
116 case TYPE_REMOVE_RESOURCE_FROM_DIRECTORY
:
117 case TYPE_ADD_NEW_DIRECTORY
:
118 case TYPE_ADD_PERMISSION
:
120 case TYPE_DOWNLOAD_FILE
:
121 case TYPE_UPLOAD_NEW_FILE
:
122 case TYPE_UPLOAD_EXISTING_FILE
: