Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / chromeos / drive / job_list.cc
blob39eb5bb10ffb7722efb13a4cdbd6a9c13313d88f
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"
11 namespace drive {
13 std::string JobTypeToString(JobType type) {
14 switch (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";
23 case TYPE_SEARCH:
24 return "TYPE_SEARCH";
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";
56 NOTREACHED();
57 return "(unknown job type)";
60 std::string JobStateToString(JobState state) {
61 switch (state) {
62 case STATE_NONE:
63 return "STATE_NONE";
64 case STATE_RUNNING:
65 return "STATE_RUNNING";
66 case STATE_RETRY:
67 return "STATE_RETRY";
69 NOTREACHED();
70 return "(unknown job state)";
73 JobInfo::JobInfo(JobType in_job_type)
74 : job_type(in_job_type),
75 job_id(-1),
76 state(STATE_NONE),
77 num_completed_bytes(0),
78 num_total_bytes(0) {
81 std::string JobInfo::ToString() const {
82 std::string output = base::StringPrintf(
83 "%s %s [%d]",
84 JobTypeToString(job_type).c_str(),
85 JobStateToString(state).c_str(),
86 job_id);
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,
91 " bytes: %s/%s",
92 base::Int64ToString(num_completed_bytes).c_str(),
93 base::Int64ToString(num_total_bytes).c_str());
95 return output;
98 bool IsActiveFileTransferJobInfo(const JobInfo& job_info) {
99 // Using switch statement so that compiler can warn when new states or types
100 // are added.
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:
106 case TYPE_SEARCH:
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:
119 return false;
120 case TYPE_DOWNLOAD_FILE:
121 case TYPE_UPLOAD_NEW_FILE:
122 case TYPE_UPLOAD_EXISTING_FILE:
123 break;
126 return true;
129 } // namespace drive