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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "mojo/public/cpp/bindings/error.h"
6
7 #include "base/strings/stringprintf.h"
8
9 namespace mojo {
10
11 Error::Error() : Error(Type::NONE) {}
12
13 Error::Error(Error&& other) { *this = std::move(other); }
14
15 Error::Error(Type type) : Error(type, "") {}
16
17 Error::Error(Type type, const std::string& details)
18 : type_(type), details_(details) {
19 }
20
21 Error::~Error() {}
22
23 Error& Error::operator=(Error&& other) {
24 type_ = other.type_;
25 details_ = std::move(other.details_);
26 other.message_.MoveTo(&message_);
27 return *this;
28 }
29
30 // static
31 Error Error::ForBadMessage(const std::string& details, Message* message) {
32 Error error(Type::BAD_MESSAGE, details);
33 error.set_message(message);
34 return error;
35 }
36
37 // static
38 Error Error::ForBadRequest(const std::string& interface_name,
39 const std::string& method_name,
40 Message* message) {
41 Error error(Type::BAD_MESSAGE,
42 base::StringPrintf("%s::%s", interface_name.c_str(),
43 method_name.c_str()));
44 error.set_message(message);
45 return error;
46 }
47
48 // static
49 Error Error::ForBadResponse(const std::string& interface_name,
50 const std::string& method_name,
51 Message* message) {
52 Error error(Type::BAD_MESSAGE,
53 base::StringPrintf("%s::%s",
54 interface_name.c_str(), method_name.c_str()));
55 error.set_message(message);
56 return error;
57 }
58
59 // static
60 Error Error::ForUnexpectedRequest(const std::string& interface_name,
61 Message* message) {
62 Error error(Type::BAD_MESSAGE,
63 base::StringPrintf("%s (Unexpected request %u)",
64 interface_name.c_str(), message->name()));
65 error.set_message(message);
66 return error;
67 }
68
69 // static
70 Error Error::ForUnexpectedResponse(const std::string& interface_name,
71 Message* message) {
72 Error error(Type::BAD_MESSAGE,
73 base::StringPrintf("%s (Unexpected response %u)",
74 interface_name.c_str(), message->name()));
75 error.set_message(message);
76 return error;
77 }
78
79 //static
80 Error Error::ForBadControlMessage(const std::string& interface_name,
81 Message* message) {
82 Error error(Type::BAD_MESSAGE,
83 base::StringPrintf("%s (control message ID %u)",
84 interface_name.c_str(), message->name()));
85 error.set_message(message);
86 return error;
87 }
88
89 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698