Update broken references to image assets
[chromium-blink-merge.git] / chrome / browser / sync_file_system / sync_status_code.cc
blob85a989ce5fa51258d33687274b3425a95f01b1f9
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/sync_file_system/sync_status_code.h"
7 #include "base/logging.h"
8 #include "third_party/leveldatabase/src/include/leveldb/db.h"
10 namespace sync_file_system {
12 const char* SyncStatusCodeToString(SyncStatusCode status) {
13 switch (status) {
14 case SYNC_STATUS_OK:
15 return "OK.";
16 case SYNC_STATUS_UNKNOWN:
17 return "Unknown sync status.";
18 case SYNC_STATUS_FAILED:
19 return "Failed.";
21 // PlatformFile related errors.
22 // TODO(nhiroki): add stringize function for File::Error into base/.
23 case SYNC_FILE_ERROR_FAILED:
24 return "File operation failed.";
25 case SYNC_FILE_ERROR_IN_USE:
26 return "File currently in use.";
27 case SYNC_FILE_ERROR_EXISTS:
28 return "File already exists.";
29 case SYNC_FILE_ERROR_NOT_FOUND:
30 return "File not found.";
31 case SYNC_FILE_ERROR_ACCESS_DENIED:
32 return "File access denied.";
33 case SYNC_FILE_ERROR_TOO_MANY_OPENED:
34 return "Too many files open.";
35 case SYNC_FILE_ERROR_NO_MEMORY:
36 return "Out of memory.";
37 case SYNC_FILE_ERROR_NO_SPACE:
38 return "No space left on disk.";
39 case SYNC_FILE_ERROR_NOT_A_DIRECTORY:
40 return "Not a directory.";
41 case SYNC_FILE_ERROR_INVALID_OPERATION:
42 return "Invalid file operation.";
43 case SYNC_FILE_ERROR_SECURITY:
44 return "Security error.";
45 case SYNC_FILE_ERROR_ABORT:
46 return "File operation aborted.";
47 case SYNC_FILE_ERROR_NOT_A_FILE:
48 return "Not a file.";
49 case SYNC_FILE_ERROR_NOT_EMPTY:
50 return "File not empty.";
51 case SYNC_FILE_ERROR_INVALID_URL:
52 return "Invalid URL.";
53 case SYNC_FILE_ERROR_IO:
54 return "OS or hardware error.";
56 // Database related errors.
57 case SYNC_DATABASE_ERROR_NOT_FOUND:
58 return "Database not found.";
59 case SYNC_DATABASE_ERROR_CORRUPTION:
60 return "Database was corrupted.";
61 case SYNC_DATABASE_ERROR_IO_ERROR:
62 return "Database I/O error.";
63 case SYNC_DATABASE_ERROR_FAILED:
64 return "Database operation failed.";
66 // Sync specific status code.
67 case SYNC_STATUS_FILE_BUSY:
68 return "Sync: file is busy.";
69 case SYNC_STATUS_HAS_CONFLICT:
70 return "Sync: file has conflict.";
71 case SYNC_STATUS_NO_CONFLICT:
72 return "Sync: file has no conflict.";
73 case SYNC_STATUS_ABORT:
74 return "Sync: operation aborted.";
75 case SYNC_STATUS_NO_CHANGE_TO_SYNC:
76 return "Sync: no change to synchronize.";
77 case SYNC_STATUS_SERVICE_TEMPORARILY_UNAVAILABLE:
78 return "Sync: service is temporarily unavailable.";
79 case SYNC_STATUS_NETWORK_ERROR:
80 return "Sync: network error.";
81 case SYNC_STATUS_AUTHENTICATION_FAILED:
82 return "Sync: authentication failed.";
83 case SYNC_STATUS_UNKNOWN_ORIGIN:
84 return "Sync: unknown origin.";
85 case SYNC_STATUS_NOT_MODIFIED:
86 return "Sync: file not modified.";
87 case SYNC_STATUS_SYNC_DISABLED:
88 return "Sync: sync is disabled.";
89 case SYNC_STATUS_ACCESS_FORBIDDEN:
90 return "Sync: service access forbidden.";
91 case SYNC_STATUS_RETRY:
92 return "Sync: retry the operation.";
94 NOTREACHED();
95 return "Unknown error.";
98 SyncStatusCode LevelDBStatusToSyncStatusCode(const leveldb::Status& status) {
99 if (status.ok())
100 return SYNC_STATUS_OK;
101 else if (status.IsNotFound())
102 return SYNC_DATABASE_ERROR_NOT_FOUND;
103 else if (status.IsCorruption())
104 return SYNC_DATABASE_ERROR_CORRUPTION;
105 else if (status.IsIOError())
106 return SYNC_DATABASE_ERROR_IO_ERROR;
107 else
108 return SYNC_DATABASE_ERROR_FAILED;
111 SyncStatusCode FileErrorToSyncStatusCode(
112 base::File::Error file_error) {
113 switch (file_error) {
114 case base::File::FILE_OK:
115 return SYNC_STATUS_OK;
116 case base::File::FILE_ERROR_FAILED:
117 return SYNC_FILE_ERROR_FAILED;
118 case base::File::FILE_ERROR_IN_USE:
119 return SYNC_FILE_ERROR_IN_USE;
120 case base::File::FILE_ERROR_EXISTS:
121 return SYNC_FILE_ERROR_EXISTS;
122 case base::File::FILE_ERROR_NOT_FOUND:
123 return SYNC_FILE_ERROR_NOT_FOUND;
124 case base::File::FILE_ERROR_ACCESS_DENIED:
125 return SYNC_FILE_ERROR_ACCESS_DENIED;
126 case base::File::FILE_ERROR_TOO_MANY_OPENED:
127 return SYNC_FILE_ERROR_TOO_MANY_OPENED;
128 case base::File::FILE_ERROR_NO_MEMORY:
129 return SYNC_FILE_ERROR_NO_MEMORY;
130 case base::File::FILE_ERROR_NO_SPACE:
131 return SYNC_FILE_ERROR_NO_SPACE;
132 case base::File::FILE_ERROR_NOT_A_DIRECTORY:
133 return SYNC_FILE_ERROR_NOT_A_DIRECTORY;
134 case base::File::FILE_ERROR_INVALID_OPERATION:
135 return SYNC_FILE_ERROR_INVALID_OPERATION;
136 case base::File::FILE_ERROR_SECURITY:
137 return SYNC_FILE_ERROR_SECURITY;
138 case base::File::FILE_ERROR_ABORT:
139 return SYNC_FILE_ERROR_ABORT;
140 case base::File::FILE_ERROR_NOT_A_FILE:
141 return SYNC_FILE_ERROR_NOT_A_FILE;
142 case base::File::FILE_ERROR_NOT_EMPTY:
143 return SYNC_FILE_ERROR_NOT_EMPTY;
144 case base::File::FILE_ERROR_INVALID_URL:
145 return SYNC_FILE_ERROR_INVALID_URL;
146 case base::File::FILE_ERROR_IO:
147 return SYNC_FILE_ERROR_IO;
148 case base::File::FILE_ERROR_MAX:
149 NOTREACHED();
150 return SYNC_FILE_ERROR_FAILED;
152 // Return the value as is, so the value converted by
153 // SyncStatusCodeToFileError could be restored.
154 return static_cast<SyncStatusCode>(file_error);
157 base::File::Error SyncStatusCodeToFileError(
158 SyncStatusCode status) {
159 switch (status) {
160 case SYNC_STATUS_OK:
161 return base::File::FILE_OK;
162 case SYNC_FILE_ERROR_FAILED:
163 return base::File::FILE_ERROR_FAILED;
164 case SYNC_FILE_ERROR_IN_USE:
165 return base::File::FILE_ERROR_IN_USE;
166 case SYNC_FILE_ERROR_EXISTS:
167 return base::File::FILE_ERROR_EXISTS;
168 case SYNC_FILE_ERROR_NOT_FOUND:
169 return base::File::FILE_ERROR_NOT_FOUND;
170 case SYNC_FILE_ERROR_ACCESS_DENIED:
171 return base::File::FILE_ERROR_ACCESS_DENIED;
172 case SYNC_FILE_ERROR_TOO_MANY_OPENED:
173 return base::File::FILE_ERROR_TOO_MANY_OPENED;
174 case SYNC_FILE_ERROR_NO_MEMORY:
175 return base::File::FILE_ERROR_NO_MEMORY;
176 case SYNC_FILE_ERROR_NO_SPACE:
177 return base::File::FILE_ERROR_NO_SPACE;
178 case SYNC_FILE_ERROR_NOT_A_DIRECTORY:
179 return base::File::FILE_ERROR_NOT_A_DIRECTORY;
180 case SYNC_FILE_ERROR_INVALID_OPERATION:
181 return base::File::FILE_ERROR_INVALID_OPERATION;
182 case SYNC_FILE_ERROR_SECURITY:
183 return base::File::FILE_ERROR_SECURITY;
184 case SYNC_FILE_ERROR_ABORT:
185 return base::File::FILE_ERROR_ABORT;
186 case SYNC_FILE_ERROR_NOT_A_FILE:
187 return base::File::FILE_ERROR_NOT_A_FILE;
188 case SYNC_FILE_ERROR_NOT_EMPTY:
189 return base::File::FILE_ERROR_NOT_EMPTY;
190 case SYNC_FILE_ERROR_INVALID_URL:
191 return base::File::FILE_ERROR_INVALID_URL;
192 case SYNC_FILE_ERROR_IO:
193 return base::File::FILE_ERROR_IO;
194 default:
195 // Return the value as is, so that caller may be able to
196 // restore the information.
197 return static_cast<base::File::Error>(status);
201 } // namespace sync_file_system