| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/crash/content/app/crashpad.h" | 5 #include "components/crash/content/app/crashpad.h" |
| 6 | 6 |
| 7 #include <CoreFoundation/CoreFoundation.h> |
| 7 #include <string.h> | 8 #include <string.h> |
| 8 #include <unistd.h> | 9 #include <unistd.h> |
| 9 | 10 |
| 10 #include <algorithm> | 11 #include <algorithm> |
| 11 #include <map> | 12 #include <map> |
| 12 #include <vector> | 13 #include <vector> |
| 13 | 14 |
| 14 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 15 #include "base/logging.h" | 16 #include "base/logging.h" |
| 16 #include "base/mac/bundle_locations.h" | 17 #include "base/mac/bundle_locations.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 39 if (initial_client) { | 40 if (initial_client) { |
| 40 @autoreleasepool { | 41 @autoreleasepool { |
| 41 base::FilePath framework_bundle_path = base::mac::FrameworkBundlePath(); | 42 base::FilePath framework_bundle_path = base::mac::FrameworkBundlePath(); |
| 42 base::FilePath handler_path = | 43 base::FilePath handler_path = |
| 43 framework_bundle_path.Append("Helpers").Append("crashpad_handler"); | 44 framework_bundle_path.Append("Helpers").Append("crashpad_handler"); |
| 44 | 45 |
| 45 // Is there a way to recover if this fails? | 46 // Is there a way to recover if this fails? |
| 46 CrashReporterClient* crash_reporter_client = GetCrashReporterClient(); | 47 CrashReporterClient* crash_reporter_client = GetCrashReporterClient(); |
| 47 crash_reporter_client->GetCrashDumpLocation(&database_path); | 48 crash_reporter_client->GetCrashDumpLocation(&database_path); |
| 48 | 49 |
| 49 // TODO(mark): Reading the Breakpad keys is temporary and transitional. At | 50 #if defined(GOOGLE_CHROME_BUILD) && defined(OFFICIAL_BUILD) |
| 50 // the very least, they should be renamed to Crashpad. For the time being, | 51 // Only allow the possibility of report upload in official builds. This |
| 51 // this isn't the worst thing: Crashpad is still uploading to a | 52 // crash server won't have symbols for any other build types. |
| 52 // Breakpad-type server, after all. | 53 std::string url = "https://clients2.google.com/cr/report"; |
| 53 NSBundle* framework_bundle = base::mac::FrameworkBundle(); | 54 #else |
| 54 NSString* product = base::mac::ObjCCast<NSString>( | 55 std::string url; |
| 55 [framework_bundle objectForInfoDictionaryKey:@"BreakpadProduct"]); | 56 #endif |
| 56 NSString* version = base::mac::ObjCCast<NSString>( | 57 |
| 57 [framework_bundle objectForInfoDictionaryKey:@"BreakpadVersion"]); | 58 std::map<std::string, std::string> process_annotations; |
| 58 NSString* url_ns = base::mac::ObjCCast<NSString>( | 59 |
| 59 [framework_bundle objectForInfoDictionaryKey:@"BreakpadURL"]); | 60 NSBundle* outer_bundle = base::mac::OuterBundle(); |
| 61 NSString* product = base::mac::ObjCCast<NSString>([outer_bundle |
| 62 objectForInfoDictionaryKey:base::mac::CFToNSCast(kCFBundleNameKey)]); |
| 63 process_annotations["prod"] = |
| 64 base::SysNSStringToUTF8(product).append("_Mac"); |
| 65 |
| 60 #if defined(GOOGLE_CHROME_BUILD) | 66 #if defined(GOOGLE_CHROME_BUILD) |
| 61 NSString* channel = base::mac::ObjCCast<NSString>( | 67 NSString* channel = base::mac::ObjCCast<NSString>( |
| 62 [base::mac::OuterBundle() objectForInfoDictionaryKey:@"KSChannelID"]); | 68 [outer_bundle objectForInfoDictionaryKey:@"KSChannelID"]); |
| 63 #else | |
| 64 NSString* channel = nil; | |
| 65 #endif | |
| 66 | |
| 67 std::string url = base::SysNSStringToUTF8(url_ns); | |
| 68 | |
| 69 std::map<std::string, std::string> process_annotations; | |
| 70 process_annotations["prod"] = base::SysNSStringToUTF8(product); | |
| 71 process_annotations["ver"] = base::SysNSStringToUTF8(version); | |
| 72 if (channel) { | 69 if (channel) { |
| 73 process_annotations["channel"] = base::SysNSStringToUTF8(channel); | 70 process_annotations["channel"] = base::SysNSStringToUTF8(channel); |
| 74 } | 71 } |
| 72 #endif |
| 73 |
| 74 NSString* version = |
| 75 base::mac::ObjCCast<NSString>([base::mac::FrameworkBundle() |
| 76 objectForInfoDictionaryKey:@"CFBundleShortVersionString"]); |
| 77 process_annotations["ver"] = base::SysNSStringToUTF8(version); |
| 78 |
| 75 process_annotations["plat"] = std::string("OS X"); | 79 process_annotations["plat"] = std::string("OS X"); |
| 76 | 80 |
| 77 crashpad::CrashpadClient crashpad_client; | |
| 78 | |
| 79 std::vector<std::string> arguments; | 81 std::vector<std::string> arguments; |
| 80 if (!browser_process) { | 82 if (!browser_process) { |
| 81 // If this is an initial client that's not the browser process, it's | 83 // If this is an initial client that's not the browser process, it's |
| 82 // important that the new Crashpad handler also not be connected to any | 84 // important that the new Crashpad handler also not be connected to any |
| 83 // existing handler. This argument tells the new Crashpad handler to | 85 // existing handler. This argument tells the new Crashpad handler to |
| 84 // sever this connection. | 86 // sever this connection. |
| 85 arguments.push_back( | 87 arguments.push_back( |
| 86 "--reset-own-crash-exception-port-to-system-default"); | 88 "--reset-own-crash-exception-port-to-system-default"); |
| 87 } | 89 } |
| 88 | 90 |
| 91 crashpad::CrashpadClient crashpad_client; |
| 89 bool result = crashpad_client.StartHandler(handler_path, | 92 bool result = crashpad_client.StartHandler(handler_path, |
| 90 database_path, | 93 database_path, |
| 91 url, | 94 url, |
| 92 process_annotations, | 95 process_annotations, |
| 93 arguments, | 96 arguments, |
| 94 true); | 97 true); |
| 95 if (result) { | 98 if (result) { |
| 96 result = crashpad_client.UseHandler(); | 99 result = crashpad_client.UseHandler(); |
| 97 } | 100 } |
| 98 | 101 |
| 99 // If this is an initial client that's not the browser process, it's | 102 // If this is an initial client that's not the browser process, it's |
| 100 // important to sever the connection to any existing handler. If | 103 // important to sever the connection to any existing handler. If |
| 101 // StartHandler() or UseHandler() failed, call UseSystemDefaultHandler() | 104 // StartHandler() or UseHandler() failed, call UseSystemDefaultHandler() |
| 102 // in that case to drop the link to the existing handler. | 105 // in that case to drop the link to the existing handler. |
| 103 if (!result && !browser_process) { | 106 if (!result && !browser_process) { |
| 104 crashpad::CrashpadClient::UseSystemDefaultHandler(); | 107 crashpad::CrashpadClient::UseSystemDefaultHandler(); |
| 105 } | 108 } |
| 106 } // @autoreleasepool | 109 } // @autoreleasepool |
| 107 } | 110 } |
| 108 | 111 |
| 109 return database_path; | 112 return database_path; |
| 110 } | 113 } |
| 111 | 114 |
| 112 } // namespace internal | 115 } // namespace internal |
| 113 } // namespace crash_reporter | 116 } // namespace crash_reporter |
| OLD | NEW |