| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "mojo/public/cpp/bindings/lib/validation_errors.h" | 5 #include "mojo/public/cpp/bindings/lib/validation_errors.h" |
| 6 | 6 |
| 7 #include "base/strings/stringprintf.h" |
| 8 #include "mojo/public/cpp/bindings/message.h" |
| 9 |
| 7 namespace mojo { | 10 namespace mojo { |
| 8 namespace internal { | 11 namespace internal { |
| 9 namespace { | 12 namespace { |
| 10 | 13 |
| 11 ValidationErrorObserverForTesting* g_validation_error_observer = nullptr; | 14 ValidationErrorObserverForTesting* g_validation_error_observer = nullptr; |
| 12 SerializationWarningObserverForTesting* g_serialization_warning_observer = | 15 SerializationWarningObserverForTesting* g_serialization_warning_observer = |
| 13 nullptr; | 16 nullptr; |
| 14 | 17 |
| 15 } // namespace | 18 } // namespace |
| 16 | 19 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 43 case VALIDATION_ERROR_MESSAGE_HEADER_MISSING_REQUEST_ID: | 46 case VALIDATION_ERROR_MESSAGE_HEADER_MISSING_REQUEST_ID: |
| 44 return "VALIDATION_ERROR_MESSAGE_HEADER_MISSING_REQUEST_ID"; | 47 return "VALIDATION_ERROR_MESSAGE_HEADER_MISSING_REQUEST_ID"; |
| 45 case VALIDATION_ERROR_MESSAGE_HEADER_UNKNOWN_METHOD: | 48 case VALIDATION_ERROR_MESSAGE_HEADER_UNKNOWN_METHOD: |
| 46 return "VALIDATION_ERROR_MESSAGE_HEADER_UNKNOWN_METHOD"; | 49 return "VALIDATION_ERROR_MESSAGE_HEADER_UNKNOWN_METHOD"; |
| 47 case VALIDATION_ERROR_DIFFERENT_SIZED_ARRAYS_IN_MAP: | 50 case VALIDATION_ERROR_DIFFERENT_SIZED_ARRAYS_IN_MAP: |
| 48 return "VALIDATION_ERROR_DIFFERENT_SIZED_ARRAYS_IN_MAP"; | 51 return "VALIDATION_ERROR_DIFFERENT_SIZED_ARRAYS_IN_MAP"; |
| 49 case VALIDATION_ERROR_UNKNOWN_UNION_TAG: | 52 case VALIDATION_ERROR_UNKNOWN_UNION_TAG: |
| 50 return "VALIDATION_ERROR_UNKNOWN_UNION_TAG"; | 53 return "VALIDATION_ERROR_UNKNOWN_UNION_TAG"; |
| 51 case VALIDATION_ERROR_UNKNOWN_ENUM_VALUE: | 54 case VALIDATION_ERROR_UNKNOWN_ENUM_VALUE: |
| 52 return "VALIDATION_ERROR_UNKNOWN_ENUM_VALUE"; | 55 return "VALIDATION_ERROR_UNKNOWN_ENUM_VALUE"; |
| 56 case VALIDATION_ERROR_DESERIALIZATION_FAILED: |
| 57 return "VALIDATION_ERROR_DESERIALIZATION_FAILED"; |
| 53 } | 58 } |
| 54 | 59 |
| 55 return "Unknown error"; | 60 return "Unknown error"; |
| 56 } | 61 } |
| 57 | 62 |
| 58 void ReportValidationError(ValidationError error, const char* description) { | 63 void ReportValidationError(ValidationContext* context, |
| 64 ValidationError error, |
| 65 const char* description) { |
| 59 if (g_validation_error_observer) { | 66 if (g_validation_error_observer) { |
| 60 g_validation_error_observer->set_last_error(error); | 67 g_validation_error_observer->set_last_error(error); |
| 61 } else if (description) { | 68 return; |
| 69 } |
| 70 |
| 71 if (description) { |
| 62 LOG(ERROR) << "Invalid message: " << ValidationErrorToString(error) << " (" | 72 LOG(ERROR) << "Invalid message: " << ValidationErrorToString(error) << " (" |
| 63 << description << ")"; | 73 << description << ")"; |
| 74 if (context->message()) { |
| 75 context->message()->NotifyBadMessage( |
| 76 base::StringPrintf("Validation failed for %s [%s (%s)]", |
| 77 context->description().data(), |
| 78 ValidationErrorToString(error), description)); |
| 79 } |
| 64 } else { | 80 } else { |
| 65 LOG(ERROR) << "Invalid message: " << ValidationErrorToString(error); | 81 LOG(ERROR) << "Invalid message: " << ValidationErrorToString(error); |
| 82 if (context->message()) { |
| 83 context->message()->NotifyBadMessage( |
| 84 base::StringPrintf("Validation failed for %s [%s]", |
| 85 context->description().data(), |
| 86 ValidationErrorToString(error))); |
| 87 } |
| 66 } | 88 } |
| 67 } | 89 } |
| 68 | 90 |
| 69 ValidationErrorObserverForTesting::ValidationErrorObserverForTesting( | 91 ValidationErrorObserverForTesting::ValidationErrorObserverForTesting( |
| 70 const Callback<void()>& callback) | 92 const Callback<void()>& callback) |
| 71 : last_error_(VALIDATION_ERROR_NONE), callback_(callback) { | 93 : last_error_(VALIDATION_ERROR_NONE), callback_(callback) { |
| 72 DCHECK(!g_validation_error_observer); | 94 DCHECK(!g_validation_error_observer); |
| 73 g_validation_error_observer = this; | 95 g_validation_error_observer = this; |
| 74 } | 96 } |
| 75 | 97 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 94 } | 116 } |
| 95 | 117 |
| 96 SerializationWarningObserverForTesting:: | 118 SerializationWarningObserverForTesting:: |
| 97 ~SerializationWarningObserverForTesting() { | 119 ~SerializationWarningObserverForTesting() { |
| 98 DCHECK(g_serialization_warning_observer == this); | 120 DCHECK(g_serialization_warning_observer == this); |
| 99 g_serialization_warning_observer = nullptr; | 121 g_serialization_warning_observer = nullptr; |
| 100 } | 122 } |
| 101 | 123 |
| 102 } // namespace internal | 124 } // namespace internal |
| 103 } // namespace mojo | 125 } // namespace mojo |
| OLD | NEW |