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

Unified Diff: mojo/public/cpp/bindings/lib/error.cc

Issue 2064903002: Mojo: Report bindings validation errors via MojoNotifyBadMessage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: mojo/public/cpp/bindings/lib/error.cc
diff --git a/mojo/public/cpp/bindings/lib/error.cc b/mojo/public/cpp/bindings/lib/error.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6b309e0f74599e69d3de96c56bbc2a0ad8fe35c3
--- /dev/null
+++ b/mojo/public/cpp/bindings/lib/error.cc
@@ -0,0 +1,89 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/public/cpp/bindings/error.h"
+
+#include "base/strings/stringprintf.h"
+
+namespace mojo {
+
+Error::Error() : Error(Type::NONE) {}
+
+Error::Error(Error&& other) { *this = std::move(other); }
+
+Error::Error(Type type) : Error(type, "") {}
+
+Error::Error(Type type, const std::string& details)
+ : type_(type), details_(details) {
+}
+
+Error::~Error() {}
+
+Error& Error::operator=(Error&& other) {
+ type_ = other.type_;
+ details_ = std::move(other.details_);
+ other.message_.MoveTo(&message_);
+ return *this;
+}
+
+// static
+Error Error::ForBadMessage(const std::string& details, Message* message) {
+ Error error(Type::BAD_MESSAGE, details);
+ error.set_message(message);
+ return error;
+}
+
+// static
+Error Error::ForBadRequest(const std::string& interface_name,
+ const std::string& method_name,
+ Message* message) {
+ Error error(Type::BAD_MESSAGE,
+ base::StringPrintf("%s::%s", interface_name.c_str(),
+ method_name.c_str()));
+ error.set_message(message);
+ return error;
+}
+
+// static
+Error Error::ForBadResponse(const std::string& interface_name,
+ const std::string& method_name,
+ Message* message) {
+ Error error(Type::BAD_MESSAGE,
+ base::StringPrintf("%s::%s",
+ interface_name.c_str(), method_name.c_str()));
+ error.set_message(message);
+ return error;
+}
+
+// static
+Error Error::ForUnexpectedRequest(const std::string& interface_name,
+ Message* message) {
+ Error error(Type::BAD_MESSAGE,
+ base::StringPrintf("%s (Unexpected request %u)",
+ interface_name.c_str(), message->name()));
+ error.set_message(message);
+ return error;
+}
+
+// static
+Error Error::ForUnexpectedResponse(const std::string& interface_name,
+ Message* message) {
+ Error error(Type::BAD_MESSAGE,
+ base::StringPrintf("%s (Unexpected response %u)",
+ interface_name.c_str(), message->name()));
+ error.set_message(message);
+ return error;
+}
+
+//static
+Error Error::ForBadControlMessage(const std::string& interface_name,
+ Message* message) {
+ Error error(Type::BAD_MESSAGE,
+ base::StringPrintf("%s (control message ID %u)",
+ interface_name.c_str(), message->name()));
+ error.set_message(message);
+ return error;
+}
+
+} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698