Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(149)

Side by Side Diff: components/crash/content/app/crashpad.cc

Issue 2221833005: Adding support for sampling crashes in Chrome on Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: scottmg's comments, adding DCHECK Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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) {
470 DCHECK_EQ(consent,
471 crash_reporter::GetCrashReporterClient()->GetCollectStatsConsent());
472 crash_reporter::SetUploadConsent(consent);
473 }
474
463 // NOTE: This function is used by SyzyASAN to annotate crash reports. If you 475 // 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 476 // change the name or signature of this function you will break SyzyASAN
465 // instrumented releases of Chrome. Please contact syzygy-team@chromium.org 477 // instrumented releases of Chrome. Please contact syzygy-team@chromium.org
466 // before doing so! See also http://crbug.com/567781. 478 // before doing so! See also http://crbug.com/567781.
467 void __declspec(dllexport) __cdecl SetCrashKeyValueImpl(const wchar_t* key, 479 void __declspec(dllexport) __cdecl SetCrashKeyValueImpl(const wchar_t* key,
468 const wchar_t* value) { 480 const wchar_t* value) {
469 crash_reporter::SetCrashKeyValue(base::UTF16ToUTF8(key), 481 crash_reporter::SetCrashKeyValue(base::UTF16ToUTF8(key),
470 base::UTF16ToUTF8(value)); 482 base::UTF16ToUTF8(value));
471 } 483 }
472 484
473 void __declspec(dllexport) __cdecl ClearCrashKeyValueImpl(const wchar_t* key) { 485 void __declspec(dllexport) __cdecl ClearCrashKeyValueImpl(const wchar_t* key) {
474 crash_reporter::ClearCrashKey(base::UTF16ToUTF8(key)); 486 crash_reporter::ClearCrashKey(base::UTF16ToUTF8(key));
475 } 487 }
476 488
477 } // extern "C" 489 } // extern "C"
478 490
479 #endif // OS_WIN 491 #endif // OS_WIN
OLDNEW
« no previous file with comments | « components/crash/content/app/crashpad.h ('k') | components/metrics_services_manager/metrics_services_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698