• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 The Chromium Embedded Framework Authors. Portions copyright
2 // 2011 the Chromium Authors. All rights reserved. Use of this source code is
3 // governed by a BSD-style license that can be found in the LICENSE file.
4 
5 #include "include/base/cef_build.h"
6 
7 #include "include/internal/cef_logging_internal.h"
8 #include "include/internal/cef_thread_internal.h"
9 #include "include/internal/cef_trace_event_internal.h"
10 
11 #include "base/logging.h"
12 #include "base/threading/platform_thread.h"
13 #include "base/trace_event/trace_event.h"
14 
15 #if BUILDFLAG(IS_WIN)
16 #include "base/win/win_util.h"
17 #endif
18 
19 namespace {
20 
21 constexpr const char kCategory[] = "cef.client";
22 
23 }  // namespace
24 
25 // The contents of this file are a compilation unit that is not called by other
26 // functions in the the library. Consiquently MSVS will exclude it during the
27 // linker stage if we don't call a stub function.
28 #if defined(COMPILER_MSVC)
29 #pragma optimize("", off)
30 #endif
31 
base_impl_stub()32 void base_impl_stub() {}
33 
34 #if defined(COMPILER_MSVC)
35 #pragma optimize("", on)
36 #endif
37 
cef_trace_event_instant(const char *,const char * name,const char * arg1_name,uint64 arg1_val,const char * arg2_name,uint64 arg2_val,int copy)38 CEF_EXPORT void cef_trace_event_instant(const char* /* category */,
39                                         const char* name,
40                                         const char* arg1_name,
41                                         uint64 arg1_val,
42                                         const char* arg2_name,
43                                         uint64 arg2_val,
44                                         int copy) {
45   DCHECK(name);
46   if (!name)
47     return;
48 
49   if (copy) {
50     if (arg1_name == nullptr && arg2_name == nullptr) {
51       TRACE_EVENT_COPY_INSTANT0(kCategory, name, TRACE_EVENT_SCOPE_THREAD);
52     } else if (arg2_name == nullptr) {
53       TRACE_EVENT_COPY_INSTANT1(kCategory, name, TRACE_EVENT_SCOPE_THREAD,
54                                 arg1_name, arg1_val);
55     } else {
56       TRACE_EVENT_COPY_INSTANT2(kCategory, name, TRACE_EVENT_SCOPE_THREAD,
57                                 arg1_name, arg1_val, arg2_name, arg2_val);
58     }
59   } else {
60     if (arg1_name == nullptr && arg2_name == nullptr) {
61       TRACE_EVENT_INSTANT0(kCategory, name, TRACE_EVENT_SCOPE_THREAD);
62     } else if (arg2_name == nullptr) {
63       TRACE_EVENT_INSTANT1(kCategory, name, TRACE_EVENT_SCOPE_THREAD, arg1_name,
64                            arg1_val);
65     } else {
66       TRACE_EVENT_INSTANT2(kCategory, name, TRACE_EVENT_SCOPE_THREAD, arg1_name,
67                            arg1_val, arg2_name, arg2_val);
68     }
69   }
70 }
71 
cef_trace_event_begin(const char *,const char * name,const char * arg1_name,uint64 arg1_val,const char * arg2_name,uint64 arg2_val,int copy)72 CEF_EXPORT void cef_trace_event_begin(const char* /* category */,
73                                       const char* name,
74                                       const char* arg1_name,
75                                       uint64 arg1_val,
76                                       const char* arg2_name,
77                                       uint64 arg2_val,
78                                       int copy) {
79   DCHECK(name);
80   if (!name)
81     return;
82 
83   if (copy) {
84     if (arg1_name == nullptr && arg2_name == nullptr) {
85       TRACE_EVENT_BEGIN_WITH_FLAGS0(kCategory, name, TRACE_EVENT_FLAG_COPY);
86     } else if (arg2_name == nullptr) {
87       TRACE_EVENT_BEGIN_WITH_FLAGS1(kCategory, name, TRACE_EVENT_FLAG_COPY,
88                                     arg1_name, arg1_val);
89     } else {
90       TRACE_EVENT_COPY_BEGIN2(kCategory, name, arg1_name, arg1_val, arg2_name,
91                               arg2_val);
92     }
93   } else {
94     if (arg1_name == nullptr && arg2_name == nullptr) {
95       TRACE_EVENT_BEGIN0(kCategory, name);
96     } else if (arg2_name == nullptr) {
97       TRACE_EVENT_BEGIN1(kCategory, name, arg1_name, arg1_val);
98     } else {
99       TRACE_EVENT_BEGIN2(kCategory, name, arg1_name, arg1_val, arg2_name,
100                          arg2_val);
101     }
102   }
103 }
104 
cef_trace_event_end(const char *,const char * name,const char * arg1_name,uint64 arg1_val,const char * arg2_name,uint64 arg2_val,int copy)105 CEF_EXPORT void cef_trace_event_end(const char* /* category */,
106                                     const char* name,
107                                     const char* arg1_name,
108                                     uint64 arg1_val,
109                                     const char* arg2_name,
110                                     uint64 arg2_val,
111                                     int copy) {
112   DCHECK(name);
113   if (!name)
114     return;
115 
116   if (copy) {
117     if (arg1_name == nullptr && arg2_name == nullptr) {
118       TRACE_EVENT_END_WITH_FLAGS0(kCategory, name, TRACE_EVENT_FLAG_COPY);
119     } else if (arg2_name == nullptr) {
120       TRACE_EVENT_END_WITH_FLAGS1(kCategory, name, TRACE_EVENT_FLAG_COPY,
121                                   arg1_name, arg1_val);
122     } else {
123       TRACE_EVENT_COPY_END2(kCategory, name, arg1_name, arg1_val, arg2_name,
124                             arg2_val);
125     }
126   } else {
127     if (arg1_name == nullptr && arg2_name == nullptr) {
128       TRACE_EVENT_END0(kCategory, name);
129     } else if (arg2_name == nullptr) {
130       TRACE_EVENT_END1(kCategory, name, arg1_name, arg1_val);
131     } else {
132       TRACE_EVENT_END2(kCategory, name, arg1_name, arg1_val, arg2_name,
133                        arg2_val);
134     }
135   }
136 }
137 
cef_trace_counter(const char *,const char * name,const char * value1_name,uint64 value1_val,const char * value2_name,uint64 value2_val,int copy)138 CEF_EXPORT void cef_trace_counter(const char* /* category */,
139                                   const char* name,
140                                   const char* value1_name,
141                                   uint64 value1_val,
142                                   const char* value2_name,
143                                   uint64 value2_val,
144                                   int copy) {
145   DCHECK(name);
146   if (!name)
147     return;
148 
149   if (copy) {
150     if (value1_name == nullptr && value2_name == nullptr) {
151       TRACE_COPY_COUNTER1(kCategory, name, value1_val);
152     } else {
153       TRACE_COPY_COUNTER2(kCategory, name, value1_name, value1_val, value2_name,
154                           value2_val);
155     }
156   } else {
157     if (value1_name == nullptr && value2_name == nullptr) {
158       TRACE_COUNTER1(kCategory, name, value1_val);
159     } else {
160       TRACE_COUNTER2(kCategory, name, value1_name, value1_val, value2_name,
161                      value2_val);
162     }
163   }
164 }
165 
cef_trace_counter_id(const char *,const char * name,uint64 id,const char * value1_name,uint64 value1_val,const char * value2_name,uint64 value2_val,int copy)166 CEF_EXPORT void cef_trace_counter_id(const char* /* category */,
167                                      const char* name,
168                                      uint64 id,
169                                      const char* value1_name,
170                                      uint64 value1_val,
171                                      const char* value2_name,
172                                      uint64 value2_val,
173                                      int copy) {
174   DCHECK(name);
175   if (!name)
176     return;
177 
178   if (copy) {
179     if (value1_name == nullptr && value2_name == nullptr) {
180       TRACE_COPY_COUNTER_ID1(kCategory, name, id, value1_val);
181     } else {
182       TRACE_COPY_COUNTER_ID2(kCategory, name, id, value1_name, value1_val,
183                              value2_name, value2_val);
184     }
185   } else {
186     if (value1_name == nullptr && value2_name == nullptr) {
187       TRACE_COUNTER_ID1(kCategory, name, id, value1_val);
188     } else {
189       TRACE_COUNTER_ID2(kCategory, name, id, value1_name, value1_val,
190                         value2_name, value2_val);
191     }
192   }
193 }
194 
cef_trace_event_async_begin(const char *,const char * name,uint64 id,const char * arg1_name,uint64 arg1_val,const char * arg2_name,uint64 arg2_val,int copy)195 CEF_EXPORT void cef_trace_event_async_begin(const char* /* category */,
196                                             const char* name,
197                                             uint64 id,
198                                             const char* arg1_name,
199                                             uint64 arg1_val,
200                                             const char* arg2_name,
201                                             uint64 arg2_val,
202                                             int copy) {
203   DCHECK(name);
204   if (!name)
205     return;
206 
207   if (copy) {
208     if (arg1_name == nullptr && arg2_name == nullptr) {
209       TRACE_EVENT_COPY_ASYNC_BEGIN0(kCategory, name, id);
210     } else if (arg2_name == nullptr) {
211       TRACE_EVENT_COPY_ASYNC_BEGIN1(kCategory, name, id, arg1_name, arg1_val);
212     } else {
213       TRACE_EVENT_COPY_ASYNC_BEGIN2(kCategory, name, id, arg1_name, arg1_val,
214                                     arg2_name, arg2_val);
215     }
216   } else {
217     if (arg1_name == nullptr && arg2_name == nullptr) {
218       TRACE_EVENT_ASYNC_BEGIN0(kCategory, name, id);
219     } else if (arg2_name == nullptr) {
220       TRACE_EVENT_ASYNC_BEGIN1(kCategory, name, id, arg1_name, arg1_val);
221     } else {
222       TRACE_EVENT_ASYNC_BEGIN2(kCategory, name, id, arg1_name, arg1_val,
223                                arg2_name, arg2_val);
224     }
225   }
226 }
227 
cef_trace_event_async_step_into(const char *,const char * name,uint64 id,uint64 step,const char * arg1_name,uint64 arg1_val,int copy)228 CEF_EXPORT void cef_trace_event_async_step_into(const char* /* category */,
229                                                 const char* name,
230                                                 uint64 id,
231                                                 uint64 step,
232                                                 const char* arg1_name,
233                                                 uint64 arg1_val,
234                                                 int copy) {
235   DCHECK(name);
236   if (!name)
237     return;
238 
239   if (copy) {
240     if (arg1_name == nullptr) {
241       INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_STEP_INTO,
242                                        kCategory, name, id,
243                                        TRACE_EVENT_FLAG_COPY, "step", step);
244     } else {
245       INTERNAL_TRACE_EVENT_ADD_WITH_ID(
246           TRACE_EVENT_PHASE_ASYNC_STEP_INTO, kCategory, name, id,
247           TRACE_EVENT_FLAG_COPY, "step", step, arg1_name, arg1_val);
248     }
249   } else {
250     if (arg1_name == nullptr) {
251       TRACE_EVENT_ASYNC_STEP_INTO0(kCategory, name, id, step);
252     } else {
253       TRACE_EVENT_ASYNC_STEP_INTO1(kCategory, name, id, step, arg1_name,
254                                    arg1_val);
255     }
256   }
257 }
258 
cef_trace_event_async_step_past(const char *,const char * name,uint64 id,uint64 step,const char * arg1_name,uint64 arg1_val,int copy)259 CEF_EXPORT void cef_trace_event_async_step_past(const char* /* category */,
260                                                 const char* name,
261                                                 uint64 id,
262                                                 uint64 step,
263                                                 const char* arg1_name,
264                                                 uint64 arg1_val,
265                                                 int copy) {
266   DCHECK(name);
267   if (!name)
268     return;
269 
270   if (copy) {
271     if (arg1_name == nullptr) {
272       INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_STEP_PAST,
273                                        kCategory, name, id,
274                                        TRACE_EVENT_FLAG_COPY, "step", step);
275     } else {
276       INTERNAL_TRACE_EVENT_ADD_WITH_ID(
277           TRACE_EVENT_PHASE_ASYNC_STEP_PAST, kCategory, name, id,
278           TRACE_EVENT_FLAG_COPY, "step", step, arg1_name, arg1_val);
279     }
280   } else {
281     if (arg1_name == nullptr) {
282       TRACE_EVENT_ASYNC_STEP_PAST0(kCategory, name, id, step);
283     } else {
284       TRACE_EVENT_ASYNC_STEP_PAST1(kCategory, name, id, step, arg1_name,
285                                    arg1_val);
286     }
287   }
288 }
289 
cef_trace_event_async_end(const char *,const char * name,uint64 id,const char * arg1_name,uint64 arg1_val,const char * arg2_name,uint64 arg2_val,int copy)290 CEF_EXPORT void cef_trace_event_async_end(const char* /* category */,
291                                           const char* name,
292                                           uint64 id,
293                                           const char* arg1_name,
294                                           uint64 arg1_val,
295                                           const char* arg2_name,
296                                           uint64 arg2_val,
297                                           int copy) {
298   DCHECK(name);
299   if (!name)
300     return;
301 
302   if (copy) {
303     if (arg1_name == nullptr && arg2_name == nullptr) {
304       TRACE_EVENT_COPY_ASYNC_END0(kCategory, name, id);
305     } else if (arg2_name == nullptr) {
306       TRACE_EVENT_COPY_ASYNC_END1(kCategory, name, id, arg1_name, arg1_val);
307     } else {
308       TRACE_EVENT_COPY_ASYNC_END2(kCategory, name, id, arg1_name, arg1_val,
309                                   arg2_name, arg2_val);
310     }
311   } else {
312     if (arg1_name == nullptr && arg2_name == nullptr) {
313       TRACE_EVENT_ASYNC_END0(kCategory, name, id);
314     } else if (arg2_name == nullptr) {
315       TRACE_EVENT_ASYNC_END1(kCategory, name, id, arg1_name, arg1_val);
316     } else {
317       TRACE_EVENT_ASYNC_END2(kCategory, name, id, arg1_name, arg1_val,
318                              arg2_name, arg2_val);
319     }
320   }
321 }
322 
cef_get_min_log_level()323 CEF_EXPORT int cef_get_min_log_level() {
324   return logging::GetMinLogLevel();
325 }
326 
cef_get_vlog_level(const char * file_start,size_t N)327 CEF_EXPORT int cef_get_vlog_level(const char* file_start, size_t N) {
328   return logging::GetVlogLevelHelper(file_start, N);
329 }
330 
cef_log(const char * file,int line,int severity,const char * message)331 CEF_EXPORT void cef_log(const char* file,
332                         int line,
333                         int severity,
334                         const char* message) {
335   logging::LogMessage(file, line, severity).stream() << message;
336 }
337 
cef_get_current_platform_thread_id()338 CEF_EXPORT cef_platform_thread_id_t cef_get_current_platform_thread_id() {
339   return base::PlatformThread::CurrentId();
340 }
341 
342 CEF_EXPORT cef_platform_thread_handle_t
cef_get_current_platform_thread_handle()343 cef_get_current_platform_thread_handle() {
344 #if BUILDFLAG(IS_WIN)
345   return base::PlatformThread::CurrentId();
346 #else
347   return base::PlatformThread::CurrentHandle().platform_handle();
348 #endif
349 }
350 
CefEnableHighDPISupport()351 void CefEnableHighDPISupport() {
352 #if BUILDFLAG(IS_WIN)
353   base::win::EnableHighDPISupport();
354 #endif
355 }
356