0
Files
src/content/browser/browser_context_impl.h
Lukasz Anforowicz 729a9e1c5f Avoid using UserData in //content/browser/browser_context.cc
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}
2021-03-31 17:44:01 +00:00

112 lines
3.4 KiB
C++

// Copyright 2021 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 CONTENT_BROWSER_BROWSER_CONTEXT_IMPL_H_
#define CONTENT_BROWSER_BROWSER_CONTEXT_IMPL_H_
#include <memory>
#include <string>
#include "base/memory/scoped_refptr.h"
#include "build/build_config.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/shared_cors_origin_access_list.h"
namespace media {
class VideoDecodePerfHistory;
namespace learning {
class LearningSession;
class LearningSessionImpl;
} // namespace learning
} // namespace media
namespace storage {
class ExternalMountPoints;
} // namespace storage
namespace content {
class BackgroundSyncScheduler;
class BrowsingDataRemover;
class BrowsingDataRemoverImpl;
class DownloadManager;
class StoragePartitionImplMap;
class PermissionController;
// //content-internal parts of BrowserContext.
//
// TODO(https://crbug.com/1179776): Evolve the Impl class into a
// full BrowserContextImpl.
class BrowserContext::Impl {
public:
explicit Impl(BrowserContext* self);
~Impl();
Impl(const Impl&) = delete;
Impl& operator=(const Impl&) = delete;
const std::string& UniqueId() const { return unique_id_; }
bool ShutdownStarted();
void NotifyWillBeDestroyed();
StoragePartitionImplMap* GetOrCreateStoragePartitionMap();
StoragePartitionImplMap* storage_partition_map() {
return storage_partition_map_.get();
}
SharedCorsOriginAccessList* shared_cors_origin_access_list() {
return shared_cors_origin_access_list_.get();
}
BrowsingDataRemover* GetBrowsingDataRemover();
media::learning::LearningSession* GetLearningSession();
storage::ExternalMountPoints* GetMountPoints();
DownloadManager* GetDownloadManager();
void SetDownloadManagerForTesting(
std::unique_ptr<DownloadManager> download_manager);
PermissionController* GetPermissionController();
void SetPermissionControllerForTesting(
std::unique_ptr<PermissionController> permission_controller);
void ShutdownStoragePartitions();
media::VideoDecodePerfHistory* GetVideoDecodePerfHistory();
BackgroundSyncScheduler* background_sync_scheduler() {
return background_sync_scheduler_.get();
}
private:
// TODO(https://crbug.com/1179776): Remove the `self_` field. In the future
// BrowserContext::Impl should become BrowserContextImpl that inherits from
// BrowserContext, making the `self_` member obsolete.
BrowserContext* self_;
const std::string unique_id_ = base::UnguessableToken::Create().ToString();
bool will_be_destroyed_soon_ = false;
std::unique_ptr<StoragePartitionImplMap> storage_partition_map_;
scoped_refptr<SharedCorsOriginAccessList> shared_cors_origin_access_list_ =
SharedCorsOriginAccessList::Create();
std::unique_ptr<BrowsingDataRemoverImpl> browsing_data_remover_;
std::unique_ptr<DownloadManager> download_manager_;
std::unique_ptr<PermissionController> permission_controller_;
scoped_refptr<BackgroundSyncScheduler> background_sync_scheduler_;
std::unique_ptr<media::learning::LearningSessionImpl> learning_session_;
std::unique_ptr<media::VideoDecodePerfHistory> video_decode_perf_history_;
#if BUILDFLAG(IS_CHROMEOS_ASH)
scoped_refptr<storage::ExternalMountPoints> external_mount_points_;
#endif
};
} // namespace content
#endif // CONTENT_BROWSER_BROWSER_CONTEXT_IMPL_H_