Chromium Code Reviews| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #if BUILDFLAG(ENABLE_KASKO) | 10 #if BUILDFLAG(ENABLE_KASKO) |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 257 #elif defined(OS_WIN) | 257 #elif defined(OS_WIN) |
| 258 // On Windows, we want both the browser process and the installer and any | 258 // On Windows, we want both the browser process and the installer and any |
| 259 // other "main, first process" to initialize things. There is no "relauncher" | 259 // other "main, first process" to initialize things. There is no "relauncher" |
| 260 // on Windows, so this is synonymous with initial_client. | 260 // on Windows, so this is synonymous with initial_client. |
| 261 const bool should_initialize_database_and_set_upload_policy = initial_client; | 261 const bool should_initialize_database_and_set_upload_policy = initial_client; |
| 262 #endif | 262 #endif |
| 263 if (should_initialize_database_and_set_upload_policy) { | 263 if (should_initialize_database_and_set_upload_policy) { |
| 264 g_database = | 264 g_database = |
| 265 crashpad::CrashReportDatabase::Initialize(database_path).release(); | 265 crashpad::CrashReportDatabase::Initialize(database_path).release(); |
| 266 | 266 |
| 267 bool enable_uploads = false; | 267 SetUploadConsent(crash_reporter_client->GetCollectStatsConsent()); |
| 268 if (!crash_reporter_client->ReportingIsEnforcedByPolicy(&enable_uploads)) { | |
| 269 // Breakpad provided a --disable-breakpad switch to disable crash dumping | |
| 270 // (not just uploading) here. Crashpad doesn't need it: dumping is enabled | |
| 271 // unconditionally and uploading is gated on consent, which tests/bots | |
| 272 // shouldn't have. As a precaution, uploading is also disabled on bots | |
| 273 // even if consent is present. | |
| 274 enable_uploads = crash_reporter_client->GetCollectStatsConsent() && | |
| 275 !crash_reporter_client->IsRunningUnattended(); | |
| 276 } | |
| 277 | |
| 278 SetUploadsEnabled(enable_uploads); | |
| 279 } | 268 } |
| 280 } | 269 } |
| 281 | 270 |
| 282 } // namespace | 271 } // namespace |
| 283 | 272 |
| 284 void InitializeCrashpad(bool initial_client, const std::string& process_type) { | 273 void InitializeCrashpad(bool initial_client, const std::string& process_type) { |
| 285 InitializeCrashpadImpl(initial_client, process_type, false); | 274 InitializeCrashpadImpl(initial_client, process_type, false); |
| 286 } | 275 } |
| 287 | 276 |
| 288 #if defined(OS_WIN) | 277 #if defined(OS_WIN) |
| 289 void InitializeCrashpadWithEmbeddedHandler(bool initial_client, | 278 void InitializeCrashpadWithEmbeddedHandler(bool initial_client, |
| 290 const std::string& process_type) { | 279 const std::string& process_type) { |
| 291 InitializeCrashpadImpl(initial_client, process_type, true); | 280 InitializeCrashpadImpl(initial_client, process_type, true); |
| 292 } | 281 } |
| 293 #endif // OS_WIN | 282 #endif // OS_WIN |
| 294 | 283 |
| 295 void SetUploadsEnabled(bool enable_uploads) { | 284 void SetUploadConsent(bool consent) { |
| 296 if (g_database) { | 285 if (!g_database) |
| 297 crashpad::Settings* settings = g_database->GetSettings(); | 286 return; |
| 298 settings->SetUploadsEnabled(enable_uploads); | 287 |
| 288 bool enable_uploads = false; | |
| 289 CrashReporterClient* crash_reporter_client = GetCrashReporterClient(); | |
| 290 if (!crash_reporter_client->ReportingIsEnforcedByPolicy(&enable_uploads)) { | |
| 291 // Breakpad provided a --disable-breakpad switch to disable crash dumping | |
| 292 // (not just uploading) here. Crashpad doesn't need it: dumping is enabled | |
| 293 // unconditionally and uploading is gated on consent, which tests/bots | |
| 294 // shouldn't have. As a precaution, uploading is also disabled on bots even | |
| 295 // if consent is present. | |
| 296 enable_uploads = consent && !crash_reporter_client->IsRunningUnattended(); | |
| 299 } | 297 } |
| 298 | |
| 299 crashpad::Settings* settings = g_database->GetSettings(); | |
| 300 settings->SetUploadsEnabled(enable_uploads && | |
| 301 crash_reporter_client->GetCollectStatsInSample()); | |
| 300 } | 302 } |
| 301 | 303 |
| 302 bool GetUploadsEnabled() { | 304 bool GetUploadsEnabled() { |
| 303 if (g_database) { | 305 if (g_database) { |
| 304 crashpad::Settings* settings = g_database->GetSettings(); | 306 crashpad::Settings* settings = g_database->GetSettings(); |
| 305 bool enable_uploads; | 307 bool enable_uploads; |
| 306 if (settings->GetUploadsEnabled(&enable_uploads)) { | 308 if (settings->GetUploadsEnabled(&enable_uploads)) { |
| 307 return enable_uploads; | 309 return enable_uploads; |
| 308 } | 310 } |
| 309 } | 311 } |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 453 } | 455 } |
| 454 | 456 |
| 455 #endif // BUILDFLAG(ENABLE_KASKO) | 457 #endif // BUILDFLAG(ENABLE_KASKO) |
| 456 | 458 |
| 457 } // namespace crash_reporter | 459 } // namespace crash_reporter |
| 458 | 460 |
| 459 #if defined(OS_WIN) | 461 #if defined(OS_WIN) |
| 460 | 462 |
| 461 extern "C" { | 463 extern "C" { |
| 462 | 464 |
| 465 // This function is used in chrome_metrics_services_manager_client.cc to trigger | |
| 466 // changes to the upload-enabled state. This is done when the metrics services | |
| 467 // are initialized, and when the user changes their consent for uploads. See | |
| 468 // crash_reporter::SetUploadConsent for effects. | |
| 469 void __declspec(dllexport) __cdecl SetUploadConsentImpl(bool consent) { | |
|
scottmg
2016/08/18 19:49:10
I'm sorry, I feel like I missed this along the way
jwd
2016/08/18 20:21:33
The reason I kept the argument is to avoid making
scottmg
2016/08/18 20:33:18
OK, I hadn't been looking at Mac. I sort of prefer
jwd
2016/08/18 21:07:34
Done.
| |
| 470 crash_reporter::SetUploadConsent(consent); | |
| 471 } | |
| 472 | |
| 463 // NOTE: This function is used by SyzyASAN to annotate crash reports. If you | 473 // NOTE: This function is used by SyzyASAN to annotate crash reports. If you |
| 464 // change the name or signature of this function you will break SyzyASAN | 474 // change the name or signature of this function you will break SyzyASAN |
| 465 // instrumented releases of Chrome. Please contact syzygy-team@chromium.org | 475 // instrumented releases of Chrome. Please contact syzygy-team@chromium.org |
| 466 // before doing so! See also http://crbug.com/567781. | 476 // before doing so! See also http://crbug.com/567781. |
| 467 void __declspec(dllexport) __cdecl SetCrashKeyValueImpl(const wchar_t* key, | 477 void __declspec(dllexport) __cdecl SetCrashKeyValueImpl(const wchar_t* key, |
| 468 const wchar_t* value) { | 478 const wchar_t* value) { |
| 469 crash_reporter::SetCrashKeyValue(base::UTF16ToUTF8(key), | 479 crash_reporter::SetCrashKeyValue(base::UTF16ToUTF8(key), |
| 470 base::UTF16ToUTF8(value)); | 480 base::UTF16ToUTF8(value)); |
| 471 } | 481 } |
| 472 | 482 |
| 473 void __declspec(dllexport) __cdecl ClearCrashKeyValueImpl(const wchar_t* key) { | 483 void __declspec(dllexport) __cdecl ClearCrashKeyValueImpl(const wchar_t* key) { |
| 474 crash_reporter::ClearCrashKey(base::UTF16ToUTF8(key)); | 484 crash_reporter::ClearCrashKey(base::UTF16ToUTF8(key)); |
| 475 } | 485 } |
| 476 | 486 |
| 477 } // extern "C" | 487 } // extern "C" |
| 478 | 488 |
| 479 #endif // OS_WIN | 489 #endif // OS_WIN |
| OLD | NEW |