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

Side by Side Diff: webrtc/api/rtcerror.cc

Issue 2692723002: Adding RTCErrorOr class to be used by ORTC APIs. (Closed)
Patch Set: Created 3 years, 10 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 /*
2 * Copyright 2017 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "webrtc/api/rtcerror.h"
12
13 #include "webrtc/base/arraysize.h"
14
15 namespace {
16
17 static const char* const kRTCErrorTypeNames[] = {
18 "NONE",
19 "UNSUPPORTED_OPERATION",
20 "UNSUPPORTED_PARAMETER",
21 "INVALID_PARAMETER",
22 "INVALID_RANGE",
23 "SYNTAX_ERROR",
24 "INVALID_STATE",
25 "INVALID_MODIFICATION",
26 "NETWORK_ERROR",
27 "RESOURCE_EXHAUSTED",
28 "INTERNAL_ERROR",
29 };
30 static_assert(static_cast<int>(webrtc::RTCErrorType::INTERNAL_ERROR) ==
31 (arraysize(kRTCErrorTypeNames) - 1),
32 "kRTCErrorTypeNames must have as many strings as RTCErrorType "
33 "has values.");
34
35 } // namespace
36
37 namespace webrtc {
38
39 // static
40 const RTCError& RTCError::OK() {
41 static RTCError ok;
tommi 2017/02/12 12:11:21 have you checked if this is thread safe? I don't t
Taylor Brandstetter 2017/02/12 16:19:23 It's thread-safe according to the standard, though
tommi 2017/02/12 18:19:32 Looks like the change in chromium was made a coupl
the sun 2017/02/13 07:35:03 I'd rather avoid singletons as much as possible. I
Taylor Brandstetter 2017/02/13 18:03:53 I'm curious what the downside here is. But would y
the sun 2017/02/13 19:28:52 Sorry, I misread the code in the morning haze. Loo
Taylor Brandstetter 2017/02/13 22:24:15 Done. By the way, when I did this, I got a compile
kwiberg-webrtc 2017/02/14 09:51:49 Interesting. What did the message say? This page
Taylor Brandstetter 2017/02/15 02:22:23 "default initialization of an object of const type
42 return ok;
43 }
44
45 std::ostream& operator<<(std::ostream& stream, RTCErrorType error) {
46 int index = static_cast<int>(error);
47 return stream << kRTCErrorTypeNames[index];
48 }
49
50 webrtc::RTCError CreateAndLogError(webrtc::RTCErrorType type,
51 const std::string& message,
52 rtc::LoggingSeverity severity) {
53 // "No error" shouldn't be logged as an error.
54 RTC_DCHECK(type != RTCErrorType::NONE);
55 rtc::LogMessage(__FILE__, __LINE__, severity).stream() << message << " ("
56 << type << ")";
57 return webrtc::RTCError(type, message);
58 }
59
60 webrtc::RTCError CreateAndLogError(webrtc::RTCErrorType type,
61 const std::string& message) {
62 return CreateAndLogError(type, message, rtc::LS_ERROR);
63 }
64
65 } // namespace webrtc
OLDNEW
« webrtc/api/rtcerror.h ('K') | « webrtc/api/rtcerror.h ('k') | webrtc/pc/peerconnection.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698