Revert "Fix broken channel icon in chrome://help on CrOS" and try again
[chromium-blink-merge.git] / third_party / libjingle / overrides / init_webrtc.cc
blob927f9bf7da48324df202f95ed30a83e5d2b003d9
1 // Copyright 2013 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.
5 #include "init_webrtc.h"
7 #include "base/command_line.h"
8 #include "base/files/file_path.h"
9 #include "base/files/file_util.h"
10 #include "base/logging.h"
11 #include "base/metrics/field_trial.h"
12 #include "base/metrics/histogram.h"
13 #include "base/native_library.h"
14 #include "base/path_service.h"
15 #include "base/trace_event/trace_event.h"
16 #include "third_party/webrtc/overrides/webrtc/base/basictypes.h"
17 #include "third_party/webrtc/overrides/webrtc/base/logging.h"
18 #include "third_party/webrtc/system_wrappers/interface/cpu_info.h"
19 #include "third_party/webrtc/system_wrappers/interface/event_tracer.h"
21 const unsigned char* GetCategoryGroupEnabled(const char* category_group) {
22 return TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(category_group);
25 void AddTraceEvent(char phase,
26 const unsigned char* category_group_enabled,
27 const char* name,
28 unsigned long long id,
29 int num_args,
30 const char** arg_names,
31 const unsigned char* arg_types,
32 const unsigned long long* arg_values,
33 unsigned char flags) {
34 TRACE_EVENT_API_ADD_TRACE_EVENT(phase, category_group_enabled, name, id,
35 num_args, arg_names, arg_types, arg_values,
36 NULL, flags);
39 namespace webrtc {
40 // Define webrtc::field_trial::FindFullName to provide webrtc with a field trial
41 // implementation.
42 namespace field_trial {
43 std::string FindFullName(const std::string& trial_name) {
44 return base::FieldTrialList::FindFullName(trial_name);
46 } // namespace field_trial
48 // Define webrtc::metrics functions to provide webrtc with implementations.
49 namespace metrics {
51 // This class doesn't actually exist, so don't go looking for it :)
52 // This type is just fwd declared here in order to use it as an opaque type
53 // between the Histogram functions in this file.
54 class Histogram;
56 Histogram* HistogramFactoryGetCounts(
57 const std::string& name, int min, int max, int bucket_count) {
58 return reinterpret_cast<Histogram*>(
59 base::Histogram::FactoryGet(name, min, max, bucket_count,
60 base::HistogramBase::kUmaTargetedHistogramFlag));
63 Histogram* HistogramFactoryGetEnumeration(
64 const std::string& name, int boundary) {
65 return reinterpret_cast<Histogram*>(
66 base::LinearHistogram::FactoryGet(name, 1, boundary, boundary + 1,
67 base::HistogramBase::kUmaTargetedHistogramFlag));
70 void HistogramAdd(
71 Histogram* histogram_pointer, const std::string& name, int sample) {
72 base::HistogramBase* ptr =
73 reinterpret_cast<base::HistogramBase*>(histogram_pointer);
74 // The name should not vary.
75 DCHECK(ptr->histogram_name() == name);
76 ptr->Add(sample);
78 } // namespace metrics
79 } // namespace webrtc
81 bool InitializeWebRtcModule() {
82 // Workaround for crbug.com/176522
83 // On Linux, we can't fetch the number of cores after the sandbox has been
84 // initialized, so we call DetectNumberOfCores() here, to cache the value.
85 webrtc::CpuInfo::DetectNumberOfCores();
86 webrtc::SetupEventTracer(&GetCategoryGroupEnabled, &AddTraceEvent);
87 return true;