| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/app/chrome_breakpad_client.h" | 5 #include "chrome/app/chrome_breakpad_client.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" |
| 7 #include "base/environment.h" | 8 #include "base/environment.h" |
| 8 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/strings/utf_string_conversions.h" |
| 11 #include "chrome/common/chrome_paths.h" | 14 #include "chrome/common/chrome_paths.h" |
| 15 #include "chrome/common/chrome_switches.h" |
| 16 |
| 17 #if defined(OS_WIN) |
| 18 #include "base/file_version_info.h" |
| 19 #endif |
| 12 | 20 |
| 13 #if defined(OS_POSIX) | 21 #if defined(OS_POSIX) |
| 14 #include "chrome/common/dump_without_crashing.h" | 22 #include "chrome/common/dump_without_crashing.h" |
| 15 #endif | 23 #endif |
| 16 | 24 |
| 17 namespace chrome { | 25 namespace chrome { |
| 18 | 26 |
| 19 ChromeBreakpadClient::ChromeBreakpadClient() {} | 27 ChromeBreakpadClient::ChromeBreakpadClient() {} |
| 20 | 28 |
| 21 ChromeBreakpadClient::~ChromeBreakpadClient() {} | 29 ChromeBreakpadClient::~ChromeBreakpadClient() {} |
| 22 | 30 |
| 23 #if defined(OS_WIN) | 31 #if defined(OS_WIN) |
| 24 bool ChromeBreakpadClient::GetAlternativeCrashDumpLocation( | 32 bool ChromeBreakpadClient::GetAlternativeCrashDumpLocation( |
| 25 base::FilePath* crash_dir) { | 33 base::FilePath* crash_dir) { |
| 26 // By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate | 34 // By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate |
| 27 // location to write breakpad crash dumps can be set. | 35 // location to write breakpad crash dumps can be set. |
| 28 scoped_ptr<base::Environment> env(base::Environment::Create()); | 36 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 29 std::string alternate_crash_dump_location; | 37 std::string alternate_crash_dump_location; |
| 30 if (env->GetVar("BREAKPAD_DUMP_LOCATION", &alternate_crash_dump_location)) { | 38 if (env->GetVar("BREAKPAD_DUMP_LOCATION", &alternate_crash_dump_location)) { |
| 31 *crash_dir = base::FilePath::FromUTF8Unsafe(alternate_crash_dump_location); | 39 *crash_dir = base::FilePath::FromUTF8Unsafe(alternate_crash_dump_location); |
| 32 return true; | 40 return true; |
| 33 } | 41 } |
| 34 | 42 |
| 35 return false; | 43 return false; |
| 36 } | 44 } |
| 45 |
| 46 void ChromeBreakpadClient::GetProductNameAndVersion( |
| 47 const base::FilePath& exe_path, |
| 48 base::string16* product_name, |
| 49 base::string16* version, |
| 50 base::string16* special_build) { |
| 51 DCHECK(product_name); |
| 52 DCHECK(version); |
| 53 DCHECK(special_build); |
| 54 |
| 55 scoped_ptr<FileVersionInfo> version_info( |
| 56 FileVersionInfo::CreateFileVersionInfo(exe_path)); |
| 57 |
| 58 if (version_info.get()) { |
| 59 // Get the information from the file. |
| 60 *version = version_info->product_version(); |
| 61 if (!version_info->is_official_build()) |
| 62 version->append(base::ASCIIToUTF16("-devel")); |
| 63 |
| 64 const CommandLine& command = *CommandLine::ForCurrentProcess(); |
| 65 if (command.HasSwitch(switches::kChromeFrame)) { |
| 66 *product_name = base::ASCIIToUTF16("ChromeFrame"); |
| 67 } else { |
| 68 *product_name = version_info->product_short_name(); |
| 69 } |
| 70 |
| 71 *special_build = version_info->special_build(); |
| 72 } else { |
| 73 // No version info found. Make up the values. |
| 74 *product_name = base::ASCIIToUTF16("Chrome"); |
| 75 *version = base::ASCIIToUTF16("0.0.0.0-devel"); |
| 76 } |
| 77 } |
| 37 #endif | 78 #endif |
| 38 | 79 |
| 39 bool ChromeBreakpadClient::GetCrashDumpLocation(base::FilePath* crash_dir) { | 80 bool ChromeBreakpadClient::GetCrashDumpLocation(base::FilePath* crash_dir) { |
| 40 // By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate | 81 // By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate |
| 41 // location to write breakpad crash dumps can be set. | 82 // location to write breakpad crash dumps can be set. |
| 42 scoped_ptr<base::Environment> env(base::Environment::Create()); | 83 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 43 std::string alternate_crash_dump_location; | 84 std::string alternate_crash_dump_location; |
| 44 if (env->GetVar("BREAKPAD_DUMP_LOCATION", &alternate_crash_dump_location)) { | 85 if (env->GetVar("BREAKPAD_DUMP_LOCATION", &alternate_crash_dump_location)) { |
| 45 base::FilePath crash_dumps_dir_path = | 86 base::FilePath crash_dumps_dir_path = |
| 46 base::FilePath::FromUTF8Unsafe(alternate_crash_dump_location); | 87 base::FilePath::FromUTF8Unsafe(alternate_crash_dump_location); |
| 47 PathService::Override(chrome::DIR_CRASH_DUMPS, crash_dumps_dir_path); | 88 PathService::Override(chrome::DIR_CRASH_DUMPS, crash_dumps_dir_path); |
| 48 } | 89 } |
| 49 | 90 |
| 50 return PathService::Get(chrome::DIR_CRASH_DUMPS, crash_dir); | 91 return PathService::Get(chrome::DIR_CRASH_DUMPS, crash_dir); |
| 51 } | 92 } |
| 52 | 93 |
| 53 #if defined(OS_POSIX) | 94 #if defined(OS_POSIX) |
| 54 void ChromeBreakpadClient::SetDumpWithoutCrashingFunction(void (*function)()) { | 95 void ChromeBreakpadClient::SetDumpWithoutCrashingFunction(void (*function)()) { |
| 55 logging::SetDumpWithoutCrashingFunction(function); | 96 logging::SetDumpWithoutCrashingFunction(function); |
| 56 } | 97 } |
| 57 #endif | 98 #endif |
| 58 | 99 |
| 59 } // namespace chrome | 100 } // namespace chrome |
| OLD | NEW |