Skip to content

Commit

Permalink
Rename GetCrashDumpPercentageForWebView() and use base::RandInt()
Browse files Browse the repository at this point in the history
The original name can easily be mistaken to imply the method only
applies to WebView, when it actually applies to all Android.

Use base::RandInt() to ensure a properly seeded generator is used.

Bug: 923475
Change-Id: I54a4165dca1cd723f304b16a95746adb08613d0a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1503622
Reviewed-by: Robert Sesek <rsesek@chromium.org>
Reviewed-by: Ben Mason <benmason@chromium.org>
Reviewed-by: Tobias Sargeant <tobiasjs@chromium.org>
Commit-Queue: Joshua Peraza <jperaza@chromium.org>
Cr-Commit-Position: refs/heads/master@{#637875}
  • Loading branch information
Joshua Peraza authored and Commit Bot committed Mar 5, 2019
1 parent e0e7bca commit e4b78e3
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class AwCrashReporterClient : public crash_reporter::CrashReporterClient {
*sanitize_stacks = true;
}

unsigned int GetCrashDumpPercentageForWebView() override { return 100; }
unsigned int GetCrashDumpPercentage() override { return 100; }

bool GetBrowserProcessType(std::string* ptype) override {
*ptype = base::CommandLine::ForCurrentProcess()->HasSwitch(
Expand Down
2 changes: 1 addition & 1 deletion components/crash/content/app/crash_reporter_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ bool CrashReporterClient::ReportingIsEnforcedByPolicy(bool* breakpad_enabled) {
}

#if defined(OS_ANDROID)
unsigned int CrashReporterClient::GetCrashDumpPercentageForWebView() {
unsigned int CrashReporterClient::GetCrashDumpPercentage() {
return 100;
}

Expand Down
2 changes: 1 addition & 1 deletion components/crash/content/app/crash_reporter_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class CrashReporterClient {
// Used by WebView to sample crashes without generating the unwanted dumps. If
// the returned value is less than 100, crash dumping will be sampled to that
// percentage.
virtual unsigned int GetCrashDumpPercentageForWebView();
virtual unsigned int GetCrashDumpPercentage();

// Returns true if |ptype| was set to a value to override the default `ptype`
// annotation used for the browser process.
Expand Down
6 changes: 4 additions & 2 deletions components/crash/content/app/crashpad_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "base/path_service.h"
#include "base/posix/eintr_wrapper.h"
#include "base/posix/global_descriptors.h"
#include "base/rand_util.h"
#include "base/stl_util.h"
#include "base/strings/stringprintf.h"
#include "build/build_config.h"
Expand Down Expand Up @@ -700,8 +701,9 @@ base::FilePath PlatformCrashpadInitialization(
base::android::SetJavaExceptionCallback(SetJavaExceptionInfo);

unsigned int dump_percentage =
GetCrashReporterClient()->GetCrashDumpPercentageForWebView();
if (dump_percentage < 100 && rand() % 100 >= dump_percentage) {
GetCrashReporterClient()->GetCrashDumpPercentage();
if (dump_percentage < 100 &&
static_cast<unsigned int>(base::RandInt(0, 99)) >= dump_percentage) {
dump_at_crash = false;
}
#endif // OS_ANDROID
Expand Down

0 comments on commit e4b78e3

Please sign in to comment.