| 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 = nullptr; | 13 ValidationErrorObserverForTesting* g_validation_error_observer = nullptr; |
| 14 SerializationWarningObserverForTesting* g_serialization_warning_observer = | |
| 15 nullptr; | |
| 16 | 14 |
| 17 } // namespace | 15 } // namespace |
| 18 | 16 |
| 19 const char* ValidationErrorToString(ValidationError error) { | 17 const char* ValidationErrorToString(ValidationError error) { |
| 20 switch (error) { | 18 switch (error) { |
| 21 case VALIDATION_ERROR_NONE: | 19 case VALIDATION_ERROR_NONE: |
| 22 return "VALIDATION_ERROR_NONE"; | 20 return "VALIDATION_ERROR_NONE"; |
| 23 case VALIDATION_ERROR_MISALIGNED_OBJECT: | 21 case VALIDATION_ERROR_MISALIGNED_OBJECT: |
| 24 return "VALIDATION_ERROR_MISALIGNED_OBJECT"; | 22 return "VALIDATION_ERROR_MISALIGNED_OBJECT"; |
| 25 case VALIDATION_ERROR_ILLEGAL_MEMORY_RANGE: | 23 case VALIDATION_ERROR_ILLEGAL_MEMORY_RANGE: |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 : last_error_(VALIDATION_ERROR_NONE) { | 64 : last_error_(VALIDATION_ERROR_NONE) { |
| 67 MOJO_DCHECK(!g_validation_error_observer); | 65 MOJO_DCHECK(!g_validation_error_observer); |
| 68 g_validation_error_observer = this; | 66 g_validation_error_observer = this; |
| 69 } | 67 } |
| 70 | 68 |
| 71 ValidationErrorObserverForTesting::~ValidationErrorObserverForTesting() { | 69 ValidationErrorObserverForTesting::~ValidationErrorObserverForTesting() { |
| 72 MOJO_DCHECK(g_validation_error_observer == this); | 70 MOJO_DCHECK(g_validation_error_observer == this); |
| 73 g_validation_error_observer = nullptr; | 71 g_validation_error_observer = nullptr; |
| 74 } | 72 } |
| 75 | 73 |
| 76 bool ReportSerializationWarning(ValidationError error) { | |
| 77 if (g_serialization_warning_observer) { | |
| 78 g_serialization_warning_observer->set_last_warning(error); | |
| 79 return true; | |
| 80 } | |
| 81 | |
| 82 return false; | |
| 83 } | |
| 84 | |
| 85 SerializationWarningObserverForTesting::SerializationWarningObserverForTesting() | |
| 86 : last_warning_(VALIDATION_ERROR_NONE) { | |
| 87 MOJO_DCHECK(!g_serialization_warning_observer); | |
| 88 g_serialization_warning_observer = this; | |
| 89 } | |
| 90 | |
| 91 SerializationWarningObserverForTesting:: | |
| 92 ~SerializationWarningObserverForTesting() { | |
| 93 MOJO_DCHECK(g_serialization_warning_observer == this); | |
| 94 g_serialization_warning_observer = nullptr; | |
| 95 } | |
| 96 | |
| 97 } // namespace internal | 74 } // namespace internal |
| 98 } // namespace mojo | 75 } // namespace mojo |
| OLD | NEW |