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 } else if (description) { |
62 LOG(ERROR) << "Invalid message: " << ValidationErrorToString(error) << " (" | 69 LOG(ERROR) << "Invalid message: " << ValidationErrorToString(error) << " (" |
63 << description << ")"; | 70 << description << ")"; |
64 } else { | 71 } else { |
65 LOG(ERROR) << "Invalid message: " << ValidationErrorToString(error); | 72 LOG(ERROR) << "Invalid message: " << ValidationErrorToString(error); |
66 } | 73 } |
74 | |
75 if (context->message()) { | |
yzshen1
2016/06/15 22:20:09
When g_validation_error_observer is set, we are in
Ken Rockot(use gerrit already)
2016/06/15 22:38:23
I guess not. Done.
| |
76 if (description) { | |
77 context->message()->NotifyBadMessage( | |
78 base::StringPrintf("Validation failed for %s [%s (%s)]", | |
79 context->description().data(), | |
80 ValidationErrorToString(error), description)); | |
81 } else { | |
82 context->message()->NotifyBadMessage( | |
83 base::StringPrintf("Validation failed for %s [%s]", | |
84 context->description().data(), | |
85 ValidationErrorToString(error))); | |
86 } | |
87 } | |
67 } | 88 } |
68 | 89 |
69 ValidationErrorObserverForTesting::ValidationErrorObserverForTesting( | 90 ValidationErrorObserverForTesting::ValidationErrorObserverForTesting( |
70 const Callback<void()>& callback) | 91 const Callback<void()>& callback) |
71 : last_error_(VALIDATION_ERROR_NONE), callback_(callback) { | 92 : last_error_(VALIDATION_ERROR_NONE), callback_(callback) { |
72 DCHECK(!g_validation_error_observer); | 93 DCHECK(!g_validation_error_observer); |
73 g_validation_error_observer = this; | 94 g_validation_error_observer = this; |
74 } | 95 } |
75 | 96 |
76 ValidationErrorObserverForTesting::~ValidationErrorObserverForTesting() { | 97 ValidationErrorObserverForTesting::~ValidationErrorObserverForTesting() { |
(...skipping 17 matching lines...) Expand all Loading... | |
94 } | 115 } |
95 | 116 |
96 SerializationWarningObserverForTesting:: | 117 SerializationWarningObserverForTesting:: |
97 ~SerializationWarningObserverForTesting() { | 118 ~SerializationWarningObserverForTesting() { |
98 DCHECK(g_serialization_warning_observer == this); | 119 DCHECK(g_serialization_warning_observer == this); |
99 g_serialization_warning_observer = nullptr; | 120 g_serialization_warning_observer = nullptr; |
100 } | 121 } |
101 | 122 |
102 } // namespace internal | 123 } // namespace internal |
103 } // namespace mojo | 124 } // namespace mojo |
OLD | NEW |