Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 #ifndef MOJO_PUBLIC_CPP_BINDINGS_ERROR_H_ | |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_ERROR_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "mojo/public/cpp/bindings/message.h" | |
| 11 | |
| 12 namespace mojo { | |
| 13 | |
| 14 // An error type used to signal various specific error conditions between | |
| 15 // internal bindings components. | |
| 16 class Error { | |
| 17 public: | |
| 18 enum class Type { | |
| 19 // Not really an error. | |
| 20 NONE, | |
| 21 | |
| 22 // A request was dropped because it didn't have a bound receiver after being | |
| 23 // read from a pipe. This may be raised on the receiving end of a request. | |
|
yzshen1
2016/06/14 16:45:32
Do you want to also return this code when the requ
Ken Rockot(use gerrit already)
2016/06/14 21:20:40
Done
| |
| 24 REQUEST_DROPPED, | |
| 25 | |
| 26 // A request expecting a response has become impossible to fulfill (i.e. | |
| 27 // a response callback was destroyed without being Run.) This may be raised | |
| 28 // on the receiving side of a request, i.e. the responder. | |
|
yzshen1
2016/06/14 16:45:32
Does this error code also include the case that th
Ken Rockot(use gerrit already)
2016/06/14 21:20:40
That case is actually treated as a BAD_MESSAGE (se
| |
| 29 RESPONSE_DROPPED, | |
| 30 | |
| 31 // A sent request which expects a response can no longer receive a response, | |
| 32 // e.g. because of pipe closure. This may be raised on the sending side of | |
| 33 // a request. | |
| 34 REQUEST_CANCELED, | |
|
yzshen1
2016/06/14 16:45:32
Reading the code, it seems this error code is used
Ken Rockot(use gerrit already)
2016/06/14 21:20:40
Oops, this is gone now. The only uses that existed
| |
| 35 | |
| 36 // A message could not be sent for some reason, e.g., peer closure detected | |
| 37 // on a pipe. | |
| 38 SEND_FAILED, | |
| 39 | |
| 40 // An unexpected or malformed message was received. | |
| 41 BAD_MESSAGE, | |
| 42 }; | |
| 43 | |
| 44 Error(); | |
| 45 Error(Error&& other); | |
| 46 explicit Error(Type type); | |
| 47 Error(Type type, const std::string& details); | |
| 48 | |
| 49 ~Error(); | |
| 50 | |
| 51 Error& operator=(Error&& other); | |
| 52 | |
| 53 // Set the Message object associated with this error, if any. Takes ownership | |
| 54 // of the contents of |*message|. | |
| 55 void set_message(Message* message) { | |
| 56 DCHECK(message); | |
| 57 message->MoveTo(&message_); | |
| 58 } | |
| 59 | |
| 60 Type type() const { return type_; } | |
| 61 const std::string& details() const { return details_; } | |
| 62 Message& message() { return message_; } | |
| 63 | |
| 64 static Error ForBadMessage(const std::string& details, | |
| 65 Message* message); | |
| 66 | |
| 67 static Error ForBadRequest(const std::string& interface_name, | |
| 68 const std::string& method_name, | |
| 69 Message* message); | |
| 70 | |
| 71 static Error ForBadResponse(const std::string& interface_name, | |
| 72 const std::string& method_name, | |
| 73 Message* message); | |
| 74 | |
| 75 static Error ForUnexpectedRequest(const std::string& interface_name, | |
| 76 Message* message); | |
| 77 | |
| 78 static Error ForUnexpectedResponse(const std::string& interface_name, | |
| 79 Message* message); | |
| 80 | |
| 81 static Error ForBadControlMessage(const std::string& interface_name, | |
| 82 Message* message); | |
| 83 | |
| 84 private: | |
| 85 Type type_; | |
| 86 std::string details_; | |
| 87 Message message_; | |
| 88 | |
| 89 DISALLOW_COPY_AND_ASSIGN(Error); | |
| 90 }; | |
| 91 | |
| 92 } // namespace mojo | |
| 93 | |
| 94 #endif // MOJO_PUBLIC_CPP_BINDINGS_ERROR_H_ | |
| OLD | NEW |