Skip to content

Commit

Permalink
Avoid using UserData in //content/browser/browser_context.cc
Browse files Browse the repository at this point in the history
Before this CL, //content/browser/browser_context.cc would rely on
base::SupportsUserData to simulate 10+ fields of BrowserContext.  The
motivation for this was to hide //content-internal details (e.g. the
fields and their types) from //content/public API (e.g. from the
declaration of the BrowserContext class).

After this CL, explicit fields are used while still being hidden from
//content/public API behind a private, fwd-declared Impl class.

Motivation:

- Removing the SupportsUserData dependency is a necessary step toward
  migration to separate BrowserContext, BrowserContextImpl and
  BrowserContextDelegate classes.

- Explicit fields are easier to read and use (when coding or when
  using a debugger).

Bug: 1179776
Change-Id: Ifdc3ff1d7b945678fa0a915af780c9631c998058
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2706279
Commit-Queue: Łukasz Anforowicz <lukasza@chromium.org>
Reviewed-by: Chrome Cunningham <chcunningham@chromium.org>
Reviewed-by: John Abd-El-Malek <jam@chromium.org>
Reviewed-by: danakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#868166}
  • Loading branch information
anforowicz authored and Chromium LUCI CQ committed Mar 31, 2021
1 parent 608a85d commit 729a9e1
Show file tree
Hide file tree
Showing 7 changed files with 495 additions and 342 deletions.
2 changes: 2 additions & 0 deletions content/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,8 @@ source_set("browser") {
"browser_child_process_host_impl.h",
"browser_child_process_host_impl_receiver_bindings.cc",
"browser_context.cc",
"browser_context_impl.cc",
"browser_context_impl.h",
"browser_interface_binders.cc",
"browser_interface_binders.h",
"browser_interface_broker_impl.h",
Expand Down
16 changes: 2 additions & 14 deletions content/browser/background_sync/background_sync_scheduler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@
#include <algorithm>

#include "base/memory/scoped_refptr.h"
#include "base/supports_user_data.h"
#include "content/browser/browser_context_impl.h"
#include "content/browser/storage_partition_impl.h"
#include "content/public/browser/background_sync_controller.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"

namespace content {

const char kBackgroundSyncSchedulerKey[] = "background-sync-scheduler";

using DelayedProcessingInfoMap =
std::map<StoragePartitionImpl*, std::unique_ptr<base::OneShotTimer>>;

Expand All @@ -26,17 +24,7 @@ BackgroundSyncScheduler* BackgroundSyncScheduler::GetFor(
DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK(browser_context);

if (!browser_context->GetUserData(kBackgroundSyncSchedulerKey)) {
scoped_refptr<BackgroundSyncScheduler> scheduler =
base::MakeRefCounted<BackgroundSyncScheduler>();
browser_context->SetUserData(
kBackgroundSyncSchedulerKey,
std::make_unique<base::UserDataAdapter<BackgroundSyncScheduler>>(
scheduler.get()));
}

return base::UserDataAdapter<BackgroundSyncScheduler>::Get(
browser_context, kBackgroundSyncSchedulerKey);
return browser_context->impl()->background_sync_scheduler();
}

BackgroundSyncScheduler::BackgroundSyncScheduler() = default;
Expand Down
3 changes: 0 additions & 3 deletions content/browser/background_sync/background_sync_scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ namespace content {

class StoragePartitionImpl;

// Key name on BrowserContext.
extern const char kBackgroundSyncSchedulerKey[];

// This contains the logic to schedule delayed processing of (periodic)
// Background Sync registrations.
// It keeps track of all storage partitions, and the soonest time we should
Expand Down

0 comments on commit 729a9e1

Please sign in to comment.