Skip to content

Commit

Permalink
Rename memory_infra_background_whitelist to allowlist
Browse files Browse the repository at this point in the history
Also renaming related functions and variables.
Making wording more inclusive.

Bug: 842296
Change-Id: If1121d2496c151a87ecb9a517633195d8e851a7f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2095841
Reviewed-by: Primiano Tucci <primiano@chromium.org>
Reviewed-by: Marc Treib <treib@chromium.org>
Reviewed-by: ssid <ssid@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: Eugene Zemtsov <eugene@chromium.org>
Cr-Commit-Position: refs/heads/master@{#749314}
  • Loading branch information
Djuffin authored and Commit Bot committed Mar 11, 2020
1 parent 51371b2 commit 6dc9eb7
Show file tree
Hide file tree
Showing 14 changed files with 118 additions and 119 deletions.
6 changes: 3 additions & 3 deletions base/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -811,8 +811,8 @@ jumbo_component("base") {
"trace_event/memory_dump_request_args.h",
"trace_event/memory_dump_scheduler.cc",
"trace_event/memory_dump_scheduler.h",
"trace_event/memory_infra_background_whitelist.cc",
"trace_event/memory_infra_background_whitelist.h",
"trace_event/memory_infra_background_allowlist.cc",
"trace_event/memory_infra_background_allowlist.h",
"trace_event/memory_usage_estimator.cc",
"trace_event/memory_usage_estimator.h",
"trace_event/process_memory_dump.cc",
Expand Down Expand Up @@ -2756,7 +2756,7 @@ test("base_unittests") {
"trace_event/memory_allocator_dump_unittest.cc",
"trace_event/memory_dump_manager_unittest.cc",
"trace_event/memory_dump_scheduler_unittest.cc",
"trace_event/memory_infra_background_whitelist_unittest.cc",
"trace_event/memory_infra_background_allowlist_unittest.cc",
"trace_event/memory_usage_estimator_unittest.cc",
"trace_event/process_memory_dump_unittest.cc",
"trace_event/trace_arguments_unittest.cc",
Expand Down
15 changes: 7 additions & 8 deletions base/trace_event/memory_dump_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "base/trace_event/malloc_dump_provider.h"
#include "base/trace_event/memory_dump_provider.h"
#include "base/trace_event/memory_dump_scheduler.h"
#include "base/trace_event/memory_infra_background_whitelist.h"
#include "base/trace_event/memory_infra_background_allowlist.h"
#include "base/trace_event/process_memory_dump.h"
#include "base/trace_event/trace_event.h"
#include "base/trace_event/traced_value.h"
Expand Down Expand Up @@ -180,14 +180,13 @@ void MemoryDumpManager::RegisterDumpProviderInternal(
return;

// Only a handful of MDPs are required to compute the memory metrics. These
// have small enough performance overhead that it is resonable to run them
// have small enough performance overhead that it is reasonable to run them
// in the background while the user is doing other things. Those MDPs are
// 'whitelisted for background mode'.
bool whitelisted_for_background_mode = IsMemoryDumpProviderWhitelisted(name);
// 'allowed in background mode'.
bool allowed_in_background_mode = IsMemoryDumpProviderInAllowlist(name);

scoped_refptr<MemoryDumpProviderInfo> mdpinfo =
new MemoryDumpProviderInfo(mdp, name, std::move(task_runner), options,
whitelisted_for_background_mode);
scoped_refptr<MemoryDumpProviderInfo> mdpinfo = new MemoryDumpProviderInfo(
mdp, name, std::move(task_runner), options, allowed_in_background_mode);

{
AutoLock lock(lock_);
Expand Down Expand Up @@ -348,7 +347,7 @@ void MemoryDumpManager::ContinueAsyncProcessDump(
// providers. Ignore other providers and continue.
if (pmd_async_state->req_args.level_of_detail ==
MemoryDumpLevelOfDetail::BACKGROUND &&
!mdpinfo->whitelisted_for_background_mode) {
!mdpinfo->allowed_in_background_mode) {
pmd_async_state->pending_dump_providers.pop_back();
continue;
}
Expand Down
6 changes: 3 additions & 3 deletions base/trace_event/memory_dump_manager_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include "base/trace_event/memory_dump_provider.h"
#include "base/trace_event/memory_dump_request_args.h"
#include "base/trace_event/memory_dump_scheduler.h"
#include "base/trace_event/memory_infra_background_whitelist.h"
#include "base/trace_event/memory_infra_background_allowlist.h"
#include "base/trace_event/process_memory_dump.h"
#include "build/build_config.h"
#include "testing/gmock/include/gmock/gmock.h"
Expand Down Expand Up @@ -752,7 +752,7 @@ TEST_F(MemoryDumpManagerTest, TriggerDumpWithoutTracing) {
}

TEST_F(MemoryDumpManagerTest, BackgroundWhitelisting) {
SetDumpProviderWhitelistForTesting(kTestMDPWhitelist);
SetDumpProviderAllowlistForTesting(kTestMDPWhitelist);

// Standard provider with default options (create dump for current process).
MockMemoryDumpProvider backgroundMdp;
Expand Down Expand Up @@ -857,7 +857,7 @@ class SimpleMockMemoryDumpProvider : public MemoryDumpProvider {
};

TEST_F(MemoryDumpManagerTest, NoStackOverflowWithTooManyMDPs) {
SetDumpProviderWhitelistForTesting(kTestMDPWhitelist);
SetDumpProviderAllowlistForTesting(kTestMDPWhitelist);

int kMDPCount = 1000;
std::vector<std::unique_ptr<SimpleMockMemoryDumpProvider>> mdps;
Expand Down
4 changes: 2 additions & 2 deletions base/trace_event/memory_dump_provider_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ MemoryDumpProviderInfo::MemoryDumpProviderInfo(
const char* name,
scoped_refptr<SequencedTaskRunner> task_runner,
const MemoryDumpProvider::Options& options,
bool whitelisted_for_background_mode)
bool allowed_in_background_mode)
: dump_provider(dump_provider),
options(options),
name(name),
task_runner(std::move(task_runner)),
whitelisted_for_background_mode(whitelisted_for_background_mode),
allowed_in_background_mode(allowed_in_background_mode),
consecutive_failures(0),
disabled(false) {}

Expand Down
4 changes: 2 additions & 2 deletions base/trace_event/memory_dump_provider_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct BASE_EXPORT MemoryDumpProviderInfo
const char* name,
scoped_refptr<SequencedTaskRunner> task_runner,
const MemoryDumpProvider::Options& options,
bool whitelisted_for_background_mode);
bool allowed_in_background_mode);

// It is safe to access the const fields below from any thread as they are
// never mutated.
Expand All @@ -78,7 +78,7 @@ struct BASE_EXPORT MemoryDumpProviderInfo
const scoped_refptr<SequencedTaskRunner> task_runner;

// True if the dump provider is whitelisted for background mode.
const bool whitelisted_for_background_mode;
const bool allowed_in_background_mode;

// These fields below, instead, are not thread safe and can be mutated only:
// - On the |task_runner|, when not null (i.e. for thread-bound MDPS).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/trace_event/memory_infra_background_whitelist.h"
#include "base/trace_event/memory_infra_background_allowlist.h"

#include <ctype.h>
#include <string.h>
Expand All @@ -15,12 +15,12 @@ namespace base {
namespace trace_event {
namespace {

// The names of dump providers whitelisted for background tracing. Dump
// The names of dump providers allowed to perform background tracing. Dump
// providers can be added here only if the background mode dump has very
// little processor and memory overhead.
// TODO(ssid): Some dump providers do not create ownership edges on background
// dump. So, the effective size will not be correct.
const char* const kDumpProviderWhitelist[] = {
const char* const kDumpProviderAllowlist[] = {
"android::ResourceManagerImpl",
"AutocompleteController",
"BlinkGC",
Expand Down Expand Up @@ -70,7 +70,7 @@ const char* const kDumpProviderWhitelist[] = {

// A list of string names that are allowed for the memory allocator dumps in
// background mode.
const char* const kAllocatorDumpNameWhitelist[] = {
const char* const kAllocatorDumpNameAllowlist[] = {
"blink_gc/main/heap",
"blink_gc/workers/heap/worker_0x?",
"blink_objects/AdSubframe",
Expand Down Expand Up @@ -387,9 +387,9 @@ const char* const kAllocatorDumpNameWhitelist[] = {
nullptr // End of list marker.
};

const char* const* g_dump_provider_whitelist = kDumpProviderWhitelist;
const char* const* g_allocator_dump_name_whitelist =
kAllocatorDumpNameWhitelist;
const char* const* g_dump_provider_allowlist = kDumpProviderAllowlist;
const char* const* g_allocator_dump_name_allowlist =
kAllocatorDumpNameAllowlist;

bool IsMemoryDumpProviderInList(const char* mdp_name, const char* const* list) {
for (size_t i = 0; list[i] != nullptr; ++i) {
Expand All @@ -401,12 +401,12 @@ bool IsMemoryDumpProviderInList(const char* mdp_name, const char* const* list) {

} // namespace

bool IsMemoryDumpProviderWhitelisted(const char* mdp_name) {
return IsMemoryDumpProviderInList(mdp_name, g_dump_provider_whitelist);
bool IsMemoryDumpProviderInAllowlist(const char* mdp_name) {
return IsMemoryDumpProviderInList(mdp_name, g_dump_provider_allowlist);
}

bool IsMemoryAllocatorDumpNameWhitelisted(const std::string& name) {
// Global dumps are explicitly whitelisted for background use.
bool IsMemoryAllocatorDumpNameInAllowlist(const std::string& name) {
// Global dumps that are of hex digits are all allowed for background use.
if (base::StartsWith(name, "global/", CompareCase::SENSITIVE)) {
for (size_t i = strlen("global/"); i < name.size(); i++)
if (!base::IsHexDigit(name[i]))
Expand Down Expand Up @@ -440,20 +440,20 @@ bool IsMemoryAllocatorDumpNameWhitelisted(const std::string& name) {
}
}

for (size_t i = 0; g_allocator_dump_name_whitelist[i] != nullptr; ++i) {
if (stripped_str == g_allocator_dump_name_whitelist[i]) {
for (size_t i = 0; g_allocator_dump_name_allowlist[i] != nullptr; ++i) {
if (stripped_str == g_allocator_dump_name_allowlist[i]) {
return true;
}
}
return false;
}

void SetDumpProviderWhitelistForTesting(const char* const* list) {
g_dump_provider_whitelist = list;
void SetDumpProviderAllowlistForTesting(const char* const* list) {
g_dump_provider_allowlist = list;
}

void SetAllocatorDumpNameWhitelistForTesting(const char* const* list) {
g_allocator_dump_name_whitelist = list;
void SetAllocatorDumpNameAllowlistForTesting(const char* const* list) {
g_allocator_dump_name_allowlist = list;
}

} // namespace trace_event
Expand Down
33 changes: 33 additions & 0 deletions base/trace_event/memory_infra_background_allowlist.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef BASE_TRACE_EVENT_MEMORY_INFRA_BACKGROUND_ALLOWLIST_H_
#define BASE_TRACE_EVENT_MEMORY_INFRA_BACKGROUND_ALLOWLIST_H_

// This file contains the allowlists (aka whitelists) for background mode to
// limit the tracing overhead and remove sensitive information from traces.

#include <string>

#include "base/base_export.h"

namespace base {
namespace trace_event {

// Checks if the given |mdp_name| is in the allow list.
bool BASE_EXPORT IsMemoryDumpProviderInAllowlist(const char* mdp_name);

// Checks if the given |name| matches any of the allowed patterns.
bool BASE_EXPORT IsMemoryAllocatorDumpNameInAllowlist(const std::string& name);

// The allow list is replaced with the given list for tests. The last element
// of the list must be nullptr.
void BASE_EXPORT SetDumpProviderAllowlistForTesting(const char* const* list);
void BASE_EXPORT
SetAllocatorDumpNameAllowlistForTesting(const char* const* list);

} // namespace trace_event
} // namespace base

#endif // BASE_TRACE_EVENT_MEMORY_INFRA_BACKGROUND_ALLOWLIST_H_
37 changes: 37 additions & 0 deletions base/trace_event/memory_infra_background_allowlist_unittest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/trace_event/memory_infra_background_allowlist.h"

#include "testing/gtest/include/gtest/gtest.h"

namespace base {

namespace trace_event {

TEST(MemoryInfraBackgroundAllowlist, Allowlist) {
// Global dumps that are of hex digits are all allowed for background use.
EXPECT_TRUE(IsMemoryAllocatorDumpNameInAllowlist("global/01234ABCDEF"));
EXPECT_TRUE(
IsMemoryAllocatorDumpNameInAllowlist("shared_memory/01234ABCDEF"));

// Global dumps that contain non-hex digits are not in the allowlist.
EXPECT_FALSE(IsMemoryAllocatorDumpNameInAllowlist("global/GHIJK"));
EXPECT_FALSE(IsMemoryAllocatorDumpNameInAllowlist("shared_memory/GHIJK"));

// Test a couple that contain pointer values.
EXPECT_TRUE(IsMemoryAllocatorDumpNameInAllowlist("net/url_request_context"));
EXPECT_TRUE(IsMemoryAllocatorDumpNameInAllowlist(
"net/url_request_context/app_request/0x123/cookie_monster"));
EXPECT_TRUE(
IsMemoryAllocatorDumpNameInAllowlist("net/http_network_session_0x123"));
EXPECT_FALSE(
IsMemoryAllocatorDumpNameInAllowlist("net/http_network_session/0x123"));
EXPECT_TRUE(IsMemoryAllocatorDumpNameInAllowlist(
"net/http_network_session_0x123/quic_stream_factory"));
}

} // namespace trace_event

} // namespace base
33 changes: 0 additions & 33 deletions base/trace_event/memory_infra_background_whitelist.h

This file was deleted.

37 changes: 0 additions & 37 deletions base/trace_event/memory_infra_background_whitelist_unittest.cc

This file was deleted.

4 changes: 2 additions & 2 deletions base/trace_event/process_memory_dump.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "base/memory/shared_memory_tracker.h"
#include "base/process/process_metrics.h"
#include "base/strings/stringprintf.h"
#include "base/trace_event/memory_infra_background_whitelist.h"
#include "base/trace_event/memory_infra_background_allowlist.h"
#include "base/trace_event/trace_event_impl.h"
#include "base/trace_event/traced_value.h"
#include "base/unguessable_token.h"
Expand Down Expand Up @@ -256,7 +256,7 @@ MemoryAllocatorDump* ProcessMemoryDump::AddAllocatorDumpInternal(
// In background mode return the black hole dump, if invalid dump name is
// given.
if (dump_args_.level_of_detail == MemoryDumpLevelOfDetail::BACKGROUND &&
!IsMemoryAllocatorDumpNameWhitelisted(mad->absolute_name())) {
!IsMemoryAllocatorDumpNameInAllowlist(mad->absolute_name())) {
return GetBlackHoleMad();
}

Expand Down
Loading

0 comments on commit 6dc9eb7

Please sign in to comment.