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 "mojo/public/cpp/environment/logging.h" | 7 #include "mojo/public/cpp/environment/logging.h" |
8 | 8 |
9 namespace mojo { | 9 namespace mojo { |
10 namespace internal { | 10 namespace internal { |
11 namespace { | 11 namespace { |
12 | 12 |
13 ValidationErrorObserverForTesting* g_validation_error_observer = NULL; | 13 ValidationErrorObserverForTesting* g_validation_error_observer = NULL; |
| 14 SerializationWarningObserverForTesting* g_serialization_warning_observer = NULL; |
14 | 15 |
15 } // namespace | 16 } // namespace |
16 | 17 |
17 const char* ValidationErrorToString(ValidationError error) { | 18 const char* ValidationErrorToString(ValidationError error) { |
18 switch (error) { | 19 switch (error) { |
19 case VALIDATION_ERROR_NONE: | 20 case VALIDATION_ERROR_NONE: |
20 return "VALIDATION_ERROR_NONE"; | 21 return "VALIDATION_ERROR_NONE"; |
21 case VALIDATION_ERROR_MISALIGNED_OBJECT: | 22 case VALIDATION_ERROR_MISALIGNED_OBJECT: |
22 return "VALIDATION_ERROR_MISALIGNED_OBJECT"; | 23 return "VALIDATION_ERROR_MISALIGNED_OBJECT"; |
23 case VALIDATION_ERROR_ILLEGAL_MEMORY_RANGE: | 24 case VALIDATION_ERROR_ILLEGAL_MEMORY_RANGE: |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 g_validation_error_observer = this; | 57 g_validation_error_observer = this; |
57 MOJO_LOG(WARNING) << "Non-nullable validation is turned on for testing but " | 58 MOJO_LOG(WARNING) << "Non-nullable validation is turned on for testing but " |
58 << "not for production code yet!"; | 59 << "not for production code yet!"; |
59 } | 60 } |
60 | 61 |
61 ValidationErrorObserverForTesting::~ValidationErrorObserverForTesting() { | 62 ValidationErrorObserverForTesting::~ValidationErrorObserverForTesting() { |
62 MOJO_DCHECK(g_validation_error_observer == this); | 63 MOJO_DCHECK(g_validation_error_observer == this); |
63 g_validation_error_observer = NULL; | 64 g_validation_error_observer = NULL; |
64 } | 65 } |
65 | 66 |
| 67 bool ReportSerializationWarning(ValidationError error) { |
| 68 if (g_serialization_warning_observer) { |
| 69 g_serialization_warning_observer->set_last_warning(error); |
| 70 return true; |
| 71 } |
| 72 |
| 73 return false; |
| 74 } |
| 75 |
| 76 SerializationWarningObserverForTesting::SerializationWarningObserverForTesting() |
| 77 : last_warning_(VALIDATION_ERROR_NONE) { |
| 78 MOJO_DCHECK(!g_serialization_warning_observer); |
| 79 g_serialization_warning_observer = this; |
| 80 } |
| 81 |
| 82 SerializationWarningObserverForTesting:: |
| 83 ~SerializationWarningObserverForTesting() { |
| 84 MOJO_DCHECK(g_serialization_warning_observer == this); |
| 85 g_serialization_warning_observer = NULL; |
| 86 } |
| 87 |
66 bool IsNonNullableValidationEnabled() { | 88 bool IsNonNullableValidationEnabled() { |
67 return !!g_validation_error_observer; | 89 return g_validation_error_observer || g_serialization_warning_observer; |
68 } | 90 } |
69 | 91 |
70 } // namespace internal | 92 } // namespace internal |
71 } // namespace mojo | 93 } // namespace mojo |
OLD | NEW |