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 #include "chrome/browser/chromeos/drive/job_list.h" 6 7 #include "base/logging.h" 8 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/stringprintf.h" 10 11 namespace drive { 12 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_CREATE_FILE: 54 return "TYPE_CREATE_FILE"; 55 case TYPE_ADD_PERMISSION: 56 return "TYPE_ADD_PERMISSION"; 57 } 58 NOTREACHED(); 59 return "(unknown job type)"; 60 } 61 62 std::string JobStateToString(JobState state) { 63 switch (state) { 64 case STATE_NONE: 65 return "STATE_NONE"; 66 case STATE_RUNNING: 67 return "STATE_RUNNING"; 68 case STATE_RETRY: 69 return "STATE_RETRY"; 70 } 71 NOTREACHED(); 72 return "(unknown job state)"; 73 } 74 75 JobInfo::JobInfo(JobType in_job_type) 76 : job_type(in_job_type), 77 job_id(-1), 78 state(STATE_NONE), 79 num_completed_bytes(0), 80 num_total_bytes(0) { 81 } 82 83 std::string JobInfo::ToString() const { 84 std::string output = base::StringPrintf( 85 "%s %s [%d]", 86 JobTypeToString(job_type).c_str(), 87 JobStateToString(state).c_str(), 88 job_id); 89 if (job_type == TYPE_DOWNLOAD_FILE || 90 job_type == TYPE_UPLOAD_NEW_FILE || 91 job_type == TYPE_UPLOAD_EXISTING_FILE) { 92 base::StringAppendF(&output, 93 " bytes: %s/%s", 94 base::Int64ToString(num_completed_bytes).c_str(), 95 base::Int64ToString(num_total_bytes).c_str()); 96 } 97 return output; 98 } 99 100 bool IsActiveFileTransferJobInfo(const JobInfo& job_info) { 101 // Using switch statement so that compiler can warn when new states or types 102 // are added. 103 switch (job_info.job_type) { 104 case TYPE_GET_ABOUT_RESOURCE: 105 case TYPE_GET_APP_LIST: 106 case TYPE_GET_ALL_RESOURCE_LIST: 107 case TYPE_GET_RESOURCE_LIST_IN_DIRECTORY: 108 case TYPE_SEARCH: 109 case TYPE_GET_CHANGE_LIST: 110 case TYPE_GET_REMAINING_CHANGE_LIST: 111 case TYPE_GET_REMAINING_FILE_LIST: 112 case TYPE_GET_RESOURCE_ENTRY: 113 case TYPE_GET_SHARE_URL: 114 case TYPE_TRASH_RESOURCE: 115 case TYPE_COPY_RESOURCE: 116 case TYPE_UPDATE_RESOURCE: 117 case TYPE_ADD_RESOURCE_TO_DIRECTORY: 118 case TYPE_REMOVE_RESOURCE_FROM_DIRECTORY: 119 case TYPE_ADD_NEW_DIRECTORY: 120 case TYPE_CREATE_FILE: 121 case TYPE_ADD_PERMISSION: 122 return false; 123 case TYPE_DOWNLOAD_FILE: 124 case TYPE_UPLOAD_NEW_FILE: 125 case TYPE_UPLOAD_EXISTING_FILE: 126 break; 127 } 128 129 return true; 130 } 131 132 } // namespace drive 133