Ensure low-memory renderers retry failed loads correctly.
[chromium-blink-merge.git] / components / drive / file_errors.cc
blob2c49448a401ed46ca3e41fbad7c515f86fa092ca
1 // Copyright (c) 2012 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 "components/drive/file_errors.h"
7 #include "base/logging.h"
9 namespace drive {
11 std::string FileErrorToString(FileError error) {
12 switch (error) {
13 case FILE_ERROR_OK:
14 return "FILE_ERROR_OK";
16 case FILE_ERROR_FAILED:
17 return "FILE_ERROR_FAILED";
19 case FILE_ERROR_IN_USE:
20 return "FILE_ERROR_IN_USE";
22 case FILE_ERROR_EXISTS:
23 return "FILE_ERROR_EXISTS";
25 case FILE_ERROR_NOT_FOUND:
26 return "FILE_ERROR_NOT_FOUND";
28 case FILE_ERROR_ACCESS_DENIED:
29 return "FILE_ERROR_ACCESS_DENIED";
31 case FILE_ERROR_TOO_MANY_OPENED:
32 return "FILE_ERROR_TOO_MANY_OPENED";
34 case FILE_ERROR_NO_MEMORY:
35 return "FILE_ERROR_NO_MEMORY";
37 case FILE_ERROR_NO_SERVER_SPACE:
38 return "FILE_ERROR_NO_SERVER_SPACE";
40 case FILE_ERROR_NOT_A_DIRECTORY:
41 return "FILE_ERROR_NOT_A_DIRECTORY";
43 case FILE_ERROR_INVALID_OPERATION:
44 return "FILE_ERROR_INVALID_OPERATION";
46 case FILE_ERROR_SECURITY:
47 return "FILE_ERROR_SECURITY";
49 case FILE_ERROR_ABORT:
50 return "FILE_ERROR_ABORT";
52 case FILE_ERROR_NOT_A_FILE:
53 return "FILE_ERROR_NOT_A_FILE";
55 case FILE_ERROR_NOT_EMPTY:
56 return "FILE_ERROR_NOT_EMPTY";
58 case FILE_ERROR_INVALID_URL:
59 return "FILE_ERROR_INVALID_URL";
61 case FILE_ERROR_NO_CONNECTION:
62 return "FILE_ERROR_NO_CONNECTION";
64 case FILE_ERROR_NO_LOCAL_SPACE:
65 return "FILE_ERROR_NO_LOCAL_SPACE";
67 case FILE_ERROR_SERVICE_UNAVAILABLE:
68 return "FILE_ERROR_SERVICE_UNAVAILABLE";
71 NOTREACHED();
72 return "";
75 base::File::Error FileErrorToBaseFileError(FileError error) {
76 switch (error) {
77 case FILE_ERROR_OK:
78 return base::File::FILE_OK;
80 case FILE_ERROR_FAILED:
81 return base::File::FILE_ERROR_FAILED;
83 case FILE_ERROR_IN_USE:
84 return base::File::FILE_ERROR_IN_USE;
86 case FILE_ERROR_EXISTS:
87 return base::File::FILE_ERROR_EXISTS;
89 case FILE_ERROR_NOT_FOUND:
90 return base::File::FILE_ERROR_NOT_FOUND;
92 case FILE_ERROR_ACCESS_DENIED:
93 return base::File::FILE_ERROR_ACCESS_DENIED;
95 case FILE_ERROR_TOO_MANY_OPENED:
96 return base::File::FILE_ERROR_TOO_MANY_OPENED;
98 case FILE_ERROR_NO_MEMORY:
99 return base::File::FILE_ERROR_NO_MEMORY;
101 case FILE_ERROR_NO_SERVER_SPACE:
102 return base::File::FILE_ERROR_NO_SPACE;
104 case FILE_ERROR_NOT_A_DIRECTORY:
105 return base::File::FILE_ERROR_NOT_A_DIRECTORY;
107 case FILE_ERROR_INVALID_OPERATION:
108 return base::File::FILE_ERROR_INVALID_OPERATION;
110 case FILE_ERROR_SECURITY:
111 return base::File::FILE_ERROR_SECURITY;
113 case FILE_ERROR_ABORT:
114 return base::File::FILE_ERROR_ABORT;
116 case FILE_ERROR_NOT_A_FILE:
117 return base::File::FILE_ERROR_NOT_A_FILE;
119 case FILE_ERROR_NOT_EMPTY:
120 return base::File::FILE_ERROR_NOT_EMPTY;
122 case FILE_ERROR_INVALID_URL:
123 return base::File::FILE_ERROR_INVALID_URL;
125 case FILE_ERROR_NO_CONNECTION:
126 return base::File::FILE_ERROR_FAILED;
128 case FILE_ERROR_NO_LOCAL_SPACE:
129 return base::File::FILE_ERROR_FAILED;
131 case FILE_ERROR_SERVICE_UNAVAILABLE:
132 return base::File::FILE_ERROR_FAILED;
135 NOTREACHED();
136 return base::File::FILE_ERROR_FAILED;
139 FileError GDataToFileError(google_apis::DriveApiErrorCode status) {
140 switch (status) {
141 case google_apis::HTTP_SUCCESS:
142 case google_apis::HTTP_CREATED:
143 case google_apis::HTTP_NO_CONTENT:
144 return FILE_ERROR_OK;
145 case google_apis::HTTP_UNAUTHORIZED:
146 case google_apis::HTTP_FORBIDDEN:
147 return FILE_ERROR_ACCESS_DENIED;
148 case google_apis::HTTP_NOT_FOUND:
149 case google_apis::HTTP_GONE:
150 return FILE_ERROR_NOT_FOUND;
151 case google_apis::HTTP_INTERNAL_SERVER_ERROR:
152 case google_apis::HTTP_SERVICE_UNAVAILABLE:
153 return FILE_ERROR_SERVICE_UNAVAILABLE;
154 case google_apis::HTTP_NOT_IMPLEMENTED:
155 return FILE_ERROR_INVALID_OPERATION;
156 case google_apis::DRIVE_CANCELLED:
157 return FILE_ERROR_ABORT;
158 case google_apis::DRIVE_NO_CONNECTION:
159 return FILE_ERROR_NO_CONNECTION;
160 case google_apis::DRIVE_NO_SPACE:
161 return FILE_ERROR_NO_SERVER_SPACE;
162 default:
163 return FILE_ERROR_FAILED;
167 } // namespace drive