OLD | NEW |
| (Empty) |
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 "webkit/fileapi/syncable/sync_status_code.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "third_party/leveldatabase/src/include/leveldb/db.h" | |
9 | |
10 namespace sync_file_system { | |
11 | |
12 std::string 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."; | |
20 | |
21 // PlatformFile related errors. | |
22 // TODO(nhiroki): add stringize function for PlatformFileError 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 | |
54 // Database related errors. | |
55 case SYNC_DATABASE_ERROR_NOT_FOUND: | |
56 return "Database not found."; | |
57 case SYNC_DATABASE_ERROR_CORRUPTION: | |
58 return "Database was corrupted."; | |
59 case SYNC_DATABASE_ERROR_IO_ERROR: | |
60 return "Database I/O error."; | |
61 case SYNC_DATABASE_ERROR_FAILED: | |
62 return "Database operation failed."; | |
63 | |
64 // Sync specific status code. | |
65 case SYNC_STATUS_FILE_BUSY: | |
66 return "Sync: file is busy."; | |
67 case SYNC_STATUS_HAS_CONFLICT: | |
68 return "Sync: file has conflict."; | |
69 case SYNC_STATUS_NO_CONFLICT: | |
70 return "Sync: file has no conflict."; | |
71 case SYNC_STATUS_ABORT: | |
72 return "Sync: operation aborted."; | |
73 case SYNC_STATUS_NO_CHANGE_TO_SYNC: | |
74 return "Sync: no change to synchronize."; | |
75 case SYNC_STATUS_RETRY: | |
76 return "Sync: retry to synchronize."; | |
77 case SYNC_STATUS_NETWORK_ERROR: | |
78 return "Sync: network error."; | |
79 case SYNC_STATUS_AUTHENTICATION_FAILED: | |
80 return "Sync: authentication failed."; | |
81 case SYNC_STATUS_UNKNOWN_ORIGIN: | |
82 return "Sync: unknown origin."; | |
83 case SYNC_STATUS_NOT_MODIFIED: | |
84 return "Sync: file not modified."; | |
85 case SYNC_STATUS_SYNC_DISABLED: | |
86 return "Sync: sync is disabled."; | |
87 } | |
88 NOTREACHED(); | |
89 return "Unknown error."; | |
90 } | |
91 | |
92 SyncStatusCode LevelDBStatusToSyncStatusCode(const leveldb::Status& status) { | |
93 if (status.ok()) | |
94 return SYNC_STATUS_OK; | |
95 else if (status.IsNotFound()) | |
96 return SYNC_DATABASE_ERROR_NOT_FOUND; | |
97 else if (status.IsCorruption()) | |
98 return SYNC_DATABASE_ERROR_CORRUPTION; | |
99 else if (status.IsIOError()) | |
100 return SYNC_DATABASE_ERROR_IO_ERROR; | |
101 else | |
102 return SYNC_DATABASE_ERROR_FAILED; | |
103 } | |
104 | |
105 SyncStatusCode PlatformFileErrorToSyncStatusCode( | |
106 base::PlatformFileError file_error) { | |
107 switch (file_error) { | |
108 case base::PLATFORM_FILE_OK: | |
109 return SYNC_STATUS_OK; | |
110 case base::PLATFORM_FILE_ERROR_FAILED: | |
111 return SYNC_FILE_ERROR_FAILED; | |
112 case base::PLATFORM_FILE_ERROR_IN_USE: | |
113 return SYNC_FILE_ERROR_IN_USE; | |
114 case base::PLATFORM_FILE_ERROR_EXISTS: | |
115 return SYNC_FILE_ERROR_EXISTS; | |
116 case base::PLATFORM_FILE_ERROR_NOT_FOUND: | |
117 return SYNC_FILE_ERROR_NOT_FOUND; | |
118 case base::PLATFORM_FILE_ERROR_ACCESS_DENIED: | |
119 return SYNC_FILE_ERROR_ACCESS_DENIED; | |
120 case base::PLATFORM_FILE_ERROR_TOO_MANY_OPENED: | |
121 return SYNC_FILE_ERROR_TOO_MANY_OPENED; | |
122 case base::PLATFORM_FILE_ERROR_NO_MEMORY: | |
123 return SYNC_FILE_ERROR_NO_MEMORY; | |
124 case base::PLATFORM_FILE_ERROR_NO_SPACE: | |
125 return SYNC_FILE_ERROR_NO_SPACE; | |
126 case base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY: | |
127 return SYNC_FILE_ERROR_NOT_A_DIRECTORY; | |
128 case base::PLATFORM_FILE_ERROR_INVALID_OPERATION: | |
129 return SYNC_FILE_ERROR_INVALID_OPERATION; | |
130 case base::PLATFORM_FILE_ERROR_SECURITY: | |
131 return SYNC_FILE_ERROR_SECURITY; | |
132 case base::PLATFORM_FILE_ERROR_ABORT: | |
133 return SYNC_FILE_ERROR_ABORT; | |
134 case base::PLATFORM_FILE_ERROR_NOT_A_FILE: | |
135 return SYNC_FILE_ERROR_NOT_A_FILE; | |
136 case base::PLATFORM_FILE_ERROR_NOT_EMPTY: | |
137 return SYNC_FILE_ERROR_NOT_EMPTY; | |
138 case base::PLATFORM_FILE_ERROR_INVALID_URL: | |
139 return SYNC_FILE_ERROR_INVALID_URL; | |
140 default: | |
141 return SYNC_FILE_ERROR_FAILED; | |
142 } | |
143 } | |
144 | |
145 } // namespace sync_file_system | |
OLD | NEW |