- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / app / chrome_breakpad_client_mac.mm
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.
4
5 #include "chrome/app/chrome_breakpad_client.h"
6
7 #include <CoreFoundation/CoreFoundation.h>
8
9 #include "base/command_line.h"
10 #include "base/mac/scoped_cftyperef.h"
11 #include "base/strings/sys_string_conversions.h"
12 #include "chrome/common/chrome_switches.h"
13 #include "policy/policy_constants.h"
14
15 #if !defined(DISABLE_NACL)
16 #import "breakpad/src/client/mac/Framework/Breakpad.h"
17 #include "components/nacl/common/nacl_switches.h"
18 #include "native_client/src/trusted/service_runtime/osx/crash_filter.h"
19 #endif
20
21 namespace chrome {
22
23 namespace {
24
25 #if !defined(DISABLE_NACL)
26 bool NaClBreakpadCrashFilter(int exception_type,
27                              int exception_code,
28                              mach_port_t crashing_thread,
29                              void* context) {
30   return !NaClMachThreadIsInUntrusted(crashing_thread);
31 }
32 #endif
33
34 }  // namespace
35
36 void ChromeBreakpadClient::InstallAdditionalFilters(BreakpadRef breakpad) {
37 #if !defined(DISABLE_NACL)
38   if (CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
39           switches::kProcessType) == switches::kNaClLoaderProcess) {
40     BreakpadSetFilterCallback(breakpad, NaClBreakpadCrashFilter, NULL);
41   }
42 #endif
43 }
44
45 bool ChromeBreakpadClient::ReportingIsEnforcedByPolicy(bool* breakpad_enabled) {
46   base::ScopedCFTypeRef<CFStringRef> key(
47       base::SysUTF8ToCFStringRef(policy::key::kMetricsReportingEnabled));
48   Boolean key_valid;
49   Boolean metrics_reporting_enabled = CFPreferencesGetAppBooleanValue(key,
50       kCFPreferencesCurrentApplication, &key_valid);
51   if (key_valid &&
52       CFPreferencesAppValueIsForced(key, kCFPreferencesCurrentApplication)) {
53     *breakpad_enabled = metrics_reporting_enabled;
54     return true;
55   }
56   return false;
57 }
58
59 }  // namespace chrome