1 // Copyright 2018 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 #ifndef MOJO_PUBLIC_CPP_BASE_FILE_ERROR_MOJOM_TRAITS_H_ 6 #define MOJO_PUBLIC_CPP_BASE_FILE_ERROR_MOJOM_TRAITS_H_ 7 8 #include "base/files/file.h" 9 #include "mojo/public/mojom/base/file_error.mojom.h" 10 11 namespace mojo { 12 13 template <> 14 struct EnumTraits<mojo_base::mojom::FileError, base::File::Error> { 15 static mojo_base::mojom::FileError ToMojom(base::File::Error error) { 16 switch (error) { 17 case base::File::FILE_OK: 18 return mojo_base::mojom::FileError::OK; 19 case base::File::FILE_ERROR_FAILED: 20 return mojo_base::mojom::FileError::FAILED; 21 case base::File::FILE_ERROR_IN_USE: 22 return mojo_base::mojom::FileError::IN_USE; 23 case base::File::FILE_ERROR_EXISTS: 24 return mojo_base::mojom::FileError::EXISTS; 25 case base::File::FILE_ERROR_NOT_FOUND: 26 return mojo_base::mojom::FileError::NOT_FOUND; 27 case base::File::FILE_ERROR_ACCESS_DENIED: 28 return mojo_base::mojom::FileError::ACCESS_DENIED; 29 case base::File::FILE_ERROR_TOO_MANY_OPENED: 30 return mojo_base::mojom::FileError::TOO_MANY_OPENED; 31 case base::File::FILE_ERROR_NO_MEMORY: 32 return mojo_base::mojom::FileError::NO_MEMORY; 33 case base::File::FILE_ERROR_NO_SPACE: 34 return mojo_base::mojom::FileError::NO_SPACE; 35 case base::File::FILE_ERROR_NOT_A_DIRECTORY: 36 return mojo_base::mojom::FileError::NOT_A_DIRECTORY; 37 case base::File::FILE_ERROR_INVALID_OPERATION: 38 return mojo_base::mojom::FileError::INVALID_OPERATION; 39 case base::File::FILE_ERROR_SECURITY: 40 return mojo_base::mojom::FileError::SECURITY; 41 case base::File::FILE_ERROR_ABORT: 42 return mojo_base::mojom::FileError::ABORT; 43 case base::File::FILE_ERROR_NOT_A_FILE: 44 return mojo_base::mojom::FileError::NOT_A_FILE; 45 case base::File::FILE_ERROR_NOT_EMPTY: 46 return mojo_base::mojom::FileError::NOT_EMPTY; 47 case base::File::FILE_ERROR_INVALID_URL: 48 return mojo_base::mojom::FileError::INVALID_URL; 49 case base::File::FILE_ERROR_IO: 50 return mojo_base::mojom::FileError::IO; 51 case base::File::FILE_ERROR_MAX: 52 return mojo_base::mojom::FileError::FAILED; 53 } 54 NOTREACHED(); 55 return mojo_base::mojom::FileError::FAILED; 56 } 57 58 static bool FromMojom(mojo_base::mojom::FileError in, 59 base::File::Error* out) { 60 switch (in) { 61 case mojo_base::mojom::FileError::OK: 62 *out = base::File::FILE_OK; 63 return true; 64 case mojo_base::mojom::FileError::FAILED: 65 *out = base::File::FILE_ERROR_FAILED; 66 return true; 67 case mojo_base::mojom::FileError::IN_USE: 68 *out = base::File::FILE_ERROR_IN_USE; 69 return true; 70 case mojo_base::mojom::FileError::EXISTS: 71 *out = base::File::FILE_ERROR_EXISTS; 72 return true; 73 case mojo_base::mojom::FileError::NOT_FOUND: 74 *out = base::File::FILE_ERROR_NOT_FOUND; 75 return true; 76 case mojo_base::mojom::FileError::ACCESS_DENIED: 77 *out = base::File::FILE_ERROR_ACCESS_DENIED; 78 return true; 79 case mojo_base::mojom::FileError::TOO_MANY_OPENED: 80 *out = base::File::FILE_ERROR_TOO_MANY_OPENED; 81 return true; 82 case mojo_base::mojom::FileError::NO_MEMORY: 83 *out = base::File::FILE_ERROR_NO_MEMORY; 84 return true; 85 case mojo_base::mojom::FileError::NO_SPACE: 86 *out = base::File::FILE_ERROR_NO_SPACE; 87 return true; 88 case mojo_base::mojom::FileError::NOT_A_DIRECTORY: 89 *out = base::File::FILE_ERROR_NOT_A_DIRECTORY; 90 return true; 91 case mojo_base::mojom::FileError::INVALID_OPERATION: 92 *out = base::File::FILE_ERROR_INVALID_OPERATION; 93 return true; 94 case mojo_base::mojom::FileError::SECURITY: 95 *out = base::File::FILE_ERROR_SECURITY; 96 return true; 97 case mojo_base::mojom::FileError::ABORT: 98 *out = base::File::FILE_ERROR_ABORT; 99 return true; 100 case mojo_base::mojom::FileError::NOT_A_FILE: 101 *out = base::File::FILE_ERROR_NOT_A_FILE; 102 return true; 103 case mojo_base::mojom::FileError::NOT_EMPTY: 104 *out = base::File::FILE_ERROR_NOT_EMPTY; 105 return true; 106 case mojo_base::mojom::FileError::INVALID_URL: 107 *out = base::File::FILE_ERROR_INVALID_URL; 108 return true; 109 case mojo_base::mojom::FileError::IO: 110 *out = base::File::FILE_ERROR_IO; 111 return true; 112 } 113 NOTREACHED(); 114 return false; 115 } 116 }; 117 118 } // namespace mojo 119 120 #endif // MOJO_PUBLIC_CPP_BASE_FILE_ERROR_MOJOM_TRAITS_H_ 121