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 |