[M85 Dev][EFL] Fix crashes at webview launch
[platform/framework/web/chromium-efl.git] / base / check.cc
1 // Copyright 2020 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 "base/check.h"
6
7 // check.h is a widely included header and its size has significant impact on
8 // build time. Try not to raise this limit unless absolutely necessary. See
9 // https://chromium.googlesource.com/chromium/src/+/HEAD/docs/wmax_tokens.md
10 #ifndef NACL_TC_REV
11 #pragma clang max_tokens_here 17000
12 #endif
13
14 #include "base/check_op.h"
15 #include "base/logging.h"
16 #include "build/build_config.h"
17
18 namespace logging {
19
20 CheckError CheckError::Check(const char* file,
21                              int line,
22                              const char* condition) {
23   CheckError check_error(new LogMessage(file, line, LOG_FATAL));
24   check_error.stream() << "Check failed: " << condition << ". ";
25   return check_error;
26 }
27
28 CheckError CheckError::CheckOp(const char* file,
29                                int line,
30                                CheckOpResult* check_op_result) {
31   CheckError check_error(new LogMessage(file, line, LOG_FATAL));
32   check_error.stream() << "Check failed: " << check_op_result->message_;
33   free(check_op_result->message_);
34   check_op_result->message_ = nullptr;
35   return check_error;
36 }
37
38 CheckError CheckError::DCheck(const char* file,
39                               int line,
40                               const char* condition) {
41   CheckError check_error(new LogMessage(file, line, LOG_DCHECK));
42   check_error.stream() << "Check failed: " << condition << ". ";
43   return check_error;
44 }
45
46 CheckError CheckError::DCheckOp(const char* file,
47                                 int line,
48                                 CheckOpResult* check_op_result) {
49   CheckError check_error(new LogMessage(file, line, LOG_DCHECK));
50   check_error.stream() << "Check failed: " << check_op_result->message_;
51   free(check_op_result->message_);
52   check_op_result->message_ = nullptr;
53   return check_error;
54 }
55
56 CheckError CheckError::PCheck(const char* file,
57                               int line,
58                               const char* condition) {
59   SystemErrorCode err_code = logging::GetLastSystemErrorCode();
60 #if defined(OS_WIN)
61   CheckError check_error(
62       new Win32ErrorLogMessage(file, line, LOG_FATAL, err_code));
63 #elif defined(OS_POSIX) || defined(OS_FUCHSIA)
64   CheckError check_error(new ErrnoLogMessage(file, line, LOG_FATAL, err_code));
65 #endif
66   check_error.stream() << "Check failed: " << condition << ". ";
67   return check_error;
68 }
69
70 CheckError CheckError::PCheck(const char* file, int line) {
71   return PCheck(file, line, "");
72 }
73
74 CheckError CheckError::DPCheck(const char* file,
75                                int line,
76                                const char* condition) {
77   SystemErrorCode err_code = logging::GetLastSystemErrorCode();
78 #if defined(OS_WIN)
79   CheckError check_error(
80       new Win32ErrorLogMessage(file, line, LOG_DCHECK, err_code));
81 #elif defined(OS_POSIX) || defined(OS_FUCHSIA)
82   CheckError check_error(new ErrnoLogMessage(file, line, LOG_DCHECK, err_code));
83 #endif
84   check_error.stream() << "Check failed: " << condition << ". ";
85   return check_error;
86 }
87
88 CheckError CheckError::NotImplemented(const char* file,
89                                       int line,
90                                       const char* function) {
91   CheckError check_error(new LogMessage(file, line, LOG_ERROR));
92   check_error.stream() << "Not implemented reached in " << function;
93   return check_error;
94 }
95
96 std::ostream& CheckError::stream() {
97   return log_message_->stream();
98 }
99
100 CheckError::~CheckError() {
101   // Note: This function ends up in crash stack traces. If its full name
102   // changes, the crash server's magic signature logic needs to be updated.
103   // See cl/306632920.
104   delete log_message_;
105 }
106
107 CheckError::CheckError(LogMessage* log_message) : log_message_(log_message) {}
108
109 void RawCheck(const char* message) {
110   RawLog(LOG_FATAL, message);
111 }
112
113 }  // namespace logging