summaryrefslogtreecommitdiffstats
path: root/remoting/base/breakpad_mac.mm
blob: 1dbd11fe31e439d6797aa137de801fd5e0cdaf50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "remoting/base/breakpad.h"

#include <Foundation/Foundation.h>

#include "base/logging.h"
#import "base/mac/scoped_nsautorelease_pool.h"
#import "breakpad/src/client/mac/Framework/Breakpad.h"

namespace remoting {

void InitializeCrashReporting() {
  base::mac::ScopedNSAutoreleasePool autorelease_pool;

  NSBundle* main_bundle = [NSBundle mainBundle];

  // Tell Breakpad where crash_inspector and crash_report_sender are.
  NSString* resource_path = [main_bundle resourcePath];
  NSString* inspector_location =
      [resource_path stringByAppendingPathComponent:@"crash_inspector"];
  NSString* reporter_bundle_location =
      [resource_path stringByAppendingPathComponent:@"crash_report_sender.app"];
  NSString* reporter_location =
      [[NSBundle bundleWithPath:reporter_bundle_location] executablePath];

  NSDictionary* info_dictionary = [main_bundle infoDictionary];
  NSMutableDictionary* breakpad_config =
      [[info_dictionary mutableCopy] autorelease];
  [breakpad_config setObject:inspector_location
                      forKey:@BREAKPAD_INSPECTOR_LOCATION];
  [breakpad_config setObject:reporter_location
                      forKey:@BREAKPAD_REPORTER_EXE_LOCATION];

  // Configure Breakpad settings here, if they are not already customized in
  // the Info.plist. These settings should be added to the plist, but the
  // problem is that the Breakpad URL contains a double-slash, which is broken
  // by the INFOPLIST_PREPROCESS step.
  // TODO(lambroslambrou): Add these to the Info.plist, similarly to what is
  // done for Chrome Framework - see 'Tweak Info.plist' in
  // chrome/chrome_dll_bundle.gypi.
  if (![breakpad_config objectForKey:@BREAKPAD_SKIP_CONFIRM]) {
    // Skip the upload confirmation dialog, since this is a remote-access
    // service that shouldn't rely on a console user to dismiss any prompt.
    // Also, this may be running in the LoginWindow context, where prompting
    // might not be possible.
    [breakpad_config setObject:@"YES"
                        forKey:@BREAKPAD_SKIP_CONFIRM];
  }
  if (![breakpad_config objectForKey:@BREAKPAD_REPORT_INTERVAL]) {
    // Set a minimum 6-hour interval between crash-reports, to match the
    // throttling used on Windows.
    [breakpad_config setObject:@"21600"
                        forKey:@BREAKPAD_REPORT_INTERVAL];
  }
  if (![breakpad_config objectForKey:@BREAKPAD_URL]) {
    [breakpad_config setObject:@"https://clients2.google.com/cr/report"
                        forKey:@BREAKPAD_URL];
  }

  if (!BreakpadCreate(breakpad_config)) {
    LOG(ERROR) << "Breakpad initialization failed";
  }
}

}  // namespace remoting