• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "chrome/browser/chromeos/drive/file_errors.h"
6 
7 #include "base/logging.h"
8 
9 namespace drive {
10 
FileErrorToString(FileError error)11 std::string FileErrorToString(FileError error) {
12   switch (error) {
13     case FILE_ERROR_OK:
14       return "FILE_ERROR_OK";
15 
16     case FILE_ERROR_FAILED:
17       return "FILE_ERROR_FAILED";
18 
19     case FILE_ERROR_IN_USE:
20       return "FILE_ERROR_IN_USE";
21 
22     case FILE_ERROR_EXISTS:
23       return "FILE_ERROR_EXISTS";
24 
25     case FILE_ERROR_NOT_FOUND:
26       return "FILE_ERROR_NOT_FOUND";
27 
28     case FILE_ERROR_ACCESS_DENIED:
29       return "FILE_ERROR_ACCESS_DENIED";
30 
31     case FILE_ERROR_TOO_MANY_OPENED:
32       return "FILE_ERROR_TOO_MANY_OPENED";
33 
34     case FILE_ERROR_NO_MEMORY:
35       return "FILE_ERROR_NO_MEMORY";
36 
37     case FILE_ERROR_NO_SERVER_SPACE:
38       return "FILE_ERROR_NO_SERVER_SPACE";
39 
40     case FILE_ERROR_NOT_A_DIRECTORY:
41       return "FILE_ERROR_NOT_A_DIRECTORY";
42 
43     case FILE_ERROR_INVALID_OPERATION:
44       return "FILE_ERROR_INVALID_OPERATION";
45 
46     case FILE_ERROR_SECURITY:
47       return "FILE_ERROR_SECURITY";
48 
49     case FILE_ERROR_ABORT:
50       return "FILE_ERROR_ABORT";
51 
52     case FILE_ERROR_NOT_A_FILE:
53       return "FILE_ERROR_NOT_A_FILE";
54 
55     case FILE_ERROR_NOT_EMPTY:
56       return "FILE_ERROR_NOT_EMPTY";
57 
58     case FILE_ERROR_INVALID_URL:
59       return "FILE_ERROR_INVALID_URL";
60 
61     case FILE_ERROR_NO_CONNECTION:
62       return "FILE_ERROR_NO_CONNECTION";
63 
64     case FILE_ERROR_NO_LOCAL_SPACE:
65       return "FILE_ERROR_NO_LOCAL_SPACE";
66 
67     case FILE_ERROR_SERVICE_UNAVAILABLE:
68       return "FILE_ERROR_SERVICE_UNAVAILABLE";
69   }
70 
71   NOTREACHED();
72   return "";
73 }
74 
FileErrorToBaseFileError(FileError error)75 base::File::Error FileErrorToBaseFileError(FileError error) {
76   switch (error) {
77     case FILE_ERROR_OK:
78       return base::File::FILE_OK;
79 
80     case FILE_ERROR_FAILED:
81       return base::File::FILE_ERROR_FAILED;
82 
83     case FILE_ERROR_IN_USE:
84       return base::File::FILE_ERROR_IN_USE;
85 
86     case FILE_ERROR_EXISTS:
87       return base::File::FILE_ERROR_EXISTS;
88 
89     case FILE_ERROR_NOT_FOUND:
90       return base::File::FILE_ERROR_NOT_FOUND;
91 
92     case FILE_ERROR_ACCESS_DENIED:
93       return base::File::FILE_ERROR_ACCESS_DENIED;
94 
95     case FILE_ERROR_TOO_MANY_OPENED:
96       return base::File::FILE_ERROR_TOO_MANY_OPENED;
97 
98     case FILE_ERROR_NO_MEMORY:
99       return base::File::FILE_ERROR_NO_MEMORY;
100 
101     case FILE_ERROR_NO_SERVER_SPACE:
102       return base::File::FILE_ERROR_NO_SPACE;
103 
104     case FILE_ERROR_NOT_A_DIRECTORY:
105       return base::File::FILE_ERROR_NOT_A_DIRECTORY;
106 
107     case FILE_ERROR_INVALID_OPERATION:
108       return base::File::FILE_ERROR_INVALID_OPERATION;
109 
110     case FILE_ERROR_SECURITY:
111       return base::File::FILE_ERROR_SECURITY;
112 
113     case FILE_ERROR_ABORT:
114       return base::File::FILE_ERROR_ABORT;
115 
116     case FILE_ERROR_NOT_A_FILE:
117       return base::File::FILE_ERROR_NOT_A_FILE;
118 
119     case FILE_ERROR_NOT_EMPTY:
120       return base::File::FILE_ERROR_NOT_EMPTY;
121 
122     case FILE_ERROR_INVALID_URL:
123       return base::File::FILE_ERROR_INVALID_URL;
124 
125     case FILE_ERROR_NO_CONNECTION:
126       return base::File::FILE_ERROR_FAILED;
127 
128     case FILE_ERROR_NO_LOCAL_SPACE:
129       return base::File::FILE_ERROR_FAILED;
130 
131     case FILE_ERROR_SERVICE_UNAVAILABLE:
132       return base::File::FILE_ERROR_FAILED;
133   }
134 
135   NOTREACHED();
136   return base::File::FILE_ERROR_FAILED;
137 }
138 
GDataToFileError(google_apis::GDataErrorCode status)139 FileError GDataToFileError(google_apis::GDataErrorCode 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::GDATA_CANCELLED:
157       return FILE_ERROR_ABORT;
158     case google_apis::GDATA_NO_CONNECTION:
159       return FILE_ERROR_NO_CONNECTION;
160     case google_apis::GDATA_NO_SPACE:
161       return FILE_ERROR_NO_SERVER_SPACE;
162     default:
163       return FILE_ERROR_FAILED;
164   }
165 }
166 
167 }  // namespace drive
168