Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(501)

Side by Side Diff: mojo/public/cpp/bindings/lib/validation_errors.cc

Issue 1387993002: mojo::Serialize*_() calls now propogate/return validation errors. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Fixed MOJO_DCHECK issues, removed SerializationWarningObserver & addressing trung's CL comments Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/validation_errors.h ('k') | mojo/public/cpp/bindings/tests/array_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698