Skip to content

Commit

Permalink
Delete BrowserContext::Initialize and InstanceGroup getters.
Browse files Browse the repository at this point in the history
Bug: 977637
Change-Id: I0f4695f9ed12f08b96712fc7a5a3a58b0c7ebe67
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2146930
Reviewed-by: John Abd-El-Malek <jam@chromium.org>
Commit-Queue: Robert Sesek <rsesek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#758563}
  • Loading branch information
rsesek authored and Commit Bot committed Apr 13, 2020
1 parent c64c72d commit 80e710f
Show file tree
Hide file tree
Showing 20 changed files with 19 additions and 211 deletions.
2 changes: 0 additions & 2 deletions android_webview/browser/aw_browser_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,6 @@ AwBrowserContext::AwBrowserContext()
g_browser_context = this;
SimpleKeyMap::GetInstance()->Associate(this, &simple_factory_key_);

BrowserContext::Initialize(this, context_storage_path_);

CreateUserPrefService();

visitedlink_writer_.reset(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ const char kTestHostDeviceName[] = "Test Device";
// This is the expected return value from GetChromeOSDeviceName() in tests.
const char kTestDeviceType[] = "Chrome device";

const base::Token kTestServiceInstanceGroup{0x0123456789abcdefull,
0xfedcba9876543210ull};

class TestMessageCenter : public message_center::FakeMessageCenter {
public:
TestMessageCenter() = default;
Expand Down Expand Up @@ -125,7 +122,7 @@ class MultiDeviceNotificationPresenterTest : public NoSessionAshTestBase {
test_session_client->AddUserSession(
kTestUserEmail, user_manager::USER_TYPE_REGULAR,
true /* enable_settings */, true /* provide_pref_service */,
false /* is_new_profile */, kTestServiceInstanceGroup);
false /* is_new_profile */);
test_session_client->SetSessionState(session_manager::SessionState::ACTIVE);
test_session_client->SwitchActiveUser(
AccountId::FromUserEmail(kTestUserEmail));
Expand Down
1 change: 0 additions & 1 deletion ash/public/cpp/session/user_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ UserInfo::~UserInfo() = default;

ASH_PUBLIC_EXPORT bool operator==(const UserInfo& a, const UserInfo& b) {
return a.type == b.type && a.account_id == b.account_id &&
a.service_instance_group == b.service_instance_group &&
a.display_name == b.display_name &&
a.display_email == b.display_email && a.avatar == b.avatar &&
a.is_new_profile == b.is_new_profile &&
Expand Down
1 change: 0 additions & 1 deletion ash/public/cpp/session/user_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ struct ASH_PUBLIC_EXPORT UserInfo {

user_manager::UserType type = user_manager::USER_TYPE_REGULAR;
AccountId account_id;
base::Optional<base::Token> service_instance_group;
std::string display_name;
std::string display_email;
UserAvatar avatar;
Expand Down
4 changes: 1 addition & 3 deletions ash/session/test_session_controller_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,14 @@ void TestSessionControllerClient::AddUserSession(
user_manager::UserType user_type,
bool enable_settings,
bool provide_pref_service,
bool is_new_profile,
const base::Optional<base::Token>& service_instance_group) {
bool is_new_profile) {
auto account_id = AccountId::FromUserEmail(
use_lower_case_user_id_ ? GetUserIdFromEmail(display_email)
: display_email);
UserSession session;
session.session_id = ++fake_session_id_;
session.user_info.type = user_type;
session.user_info.account_id = account_id;
session.user_info.service_instance_group = service_instance_group;
session.user_info.display_name = "Über tray Über tray Über tray Über tray";
session.user_info.display_email = display_email;
session.user_info.is_ephemeral = false;
Expand Down
4 changes: 1 addition & 3 deletions ash/session/test_session_controller_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ class TestSessionControllerClient : public SessionControllerClient {
user_manager::UserType user_type = user_manager::USER_TYPE_REGULAR,
bool enable_settings = true,
bool provide_pref_service = true,
bool is_new_profile = false,
const base::Optional<base::Token>& service_instance_group =
base::nullopt);
bool is_new_profile = false);

// Creates a test PrefService and associates it with the user.
void ProvidePrefServiceForUser(const AccountId& account_id);
Expand Down
3 changes: 0 additions & 3 deletions chrome/browser/profiles/off_the_record_profile_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,6 @@ OffTheRecordProfileImpl::OffTheRecordProfileImpl(
start_time_(base::Time::Now()),
key_(std::make_unique<ProfileKey>(profile_->GetPath(),
profile_->GetProfileKey())) {
// Must happen before we ask for prefs as prefs needs the connection to the
// service manager, which is set up in Initialize.
BrowserContext::Initialize(this, profile_->GetPath());
prefs_ = CreateIncognitoPrefServiceSyncable(
PrefServiceSyncableFromProfile(profile_),
CreateExtensionPrefStore(profile_, true));
Expand Down
2 changes: 0 additions & 2 deletions chrome/browser/profiles/profile_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,6 @@ ProfileImpl::ProfileImpl(
LoadPrefsForNormalStartup(async_prefs);
#endif

content::BrowserContext::Initialize(this, path_);

// Register on BrowserContext.
user_prefs::UserPrefs::Set(this, prefs_.get());

Expand Down
2 changes: 0 additions & 2 deletions chrome/browser/ui/ash/session_controller_client_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ std::unique_ptr<ash::UserSession> UserToUserSession(const User& user) {
session->user_info.has_gaia_account = user.has_gaia_account();
session->user_info.should_display_managed_ui =
profile && chrome::ShouldDisplayManagedUi(profile);
session->user_info.service_instance_group =
content::BrowserContext::GetServiceInstanceGroupFor(profile);
session->user_info.is_new_profile = profile->IsNewProfile();

session->user_info.avatar.image = user.GetImage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ TEST_F(SessionControllerClientImplTest, SendUserSession) {
const AccountId account_id(
AccountId::FromUserEmailGaiaId("user@test.com", "5555555555"));
const user_manager::User* user = user_manager()->AddUser(account_id);
TestingProfile* user_profile = CreateTestingProfile(user);
CreateTestingProfile(user);
session_manager_.CreateSession(
account_id,
chromeos::ProfileHelper::GetUserIdHashByUserIdForTesting(
Expand All @@ -431,9 +431,6 @@ TEST_F(SessionControllerClientImplTest, SendUserSession) {
// User session was sent.
EXPECT_EQ(1, session_controller.update_user_session_count());
ASSERT_TRUE(session_controller.last_user_session());
EXPECT_EQ(content::BrowserContext::GetServiceInstanceGroupFor(user_profile),
session_controller.last_user_session()
->user_info.service_instance_group.value());

// Simulate a request for an update where nothing changed.
client.SendUserSession(*user_manager()->GetLoggedInUsers()[0]);
Expand Down
2 changes: 0 additions & 2 deletions chrome/test/base/testing_profile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,6 @@ void TestingProfile::Init() {
key_ = std::make_unique<TestingProfileKey>(this, profile_path_);
}

BrowserContext::Initialize(this, profile_path_);

#if defined(OS_ANDROID)
signin::DisableInteractionWithSystemAccounts();
#endif
Expand Down
1 change: 0 additions & 1 deletion chromecast/browser/cast_browser_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ void CastBrowserContext::InitWhileIOAllowed() {
// shared in a single location as defined here.
CHECK(base::PathService::Get(DIR_CAST_HOME, &path_));
#endif // defined(OS_ANDROID)
BrowserContext::Initialize(this, path_);
}

#if !defined(OS_ANDROID)
Expand Down
130 changes: 0 additions & 130 deletions content/browser/browser_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@
#include "base/debug/dump_without_crashing.h"
#include "base/feature_list.h"
#include "base/files/file_path.h"
#include "base/guid.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/memory/weak_ptr.h"
#include "base/metrics/field_trial_params.h"
#include "base/no_destructor.h"
#include "base/rand_util.h"
#include "base/supports_user_data.h"
#include "base/task/post_task.h"
#include "base/threading/sequenced_task_runner_handle.h"
Expand All @@ -53,25 +51,18 @@
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/shared_cors_origin_access_list.h"
#include "content/public/browser/site_instance.h"
#include "content/public/browser/system_connector.h"
#include "content/public/common/content_client.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/service_manager_connection.h"
#include "content/public/common/service_names.mojom.h"
#include "media/base/media_switches.h"
#include "media/capabilities/in_memory_video_decode_stats_db_impl.h"
#include "media/capabilities/video_decode_stats_db_impl.h"
#include "media/learning/common/media_learning_tasks.h"
#include "media/learning/impl/learning_session_impl.h"
#include "media/mojo/services/video_decode_perf_history.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "net/cookies/cookie_store.h"
#include "net/url_request/url_request_context.h"
#include "services/content/service.h"
#include "services/network/public/cpp/features.h"
#include "services/service_manager/public/cpp/connector.h"
#include "services/service_manager/public/cpp/service.h"
#include "services/service_manager/public/mojom/service.mojom.h"
#include "storage/browser/blob/blob_storage_context.h"
#include "storage/browser/database/database_tracker.h"
#include "storage/browser/file_system/external_mount_points.h"
Expand All @@ -82,26 +73,6 @@ namespace content {

namespace {

using TokenToContextMap = std::map<base::Token, BrowserContext*>;
TokenToContextMap& GetTokenToContextMap() {
static base::NoDestructor<TokenToContextMap> map;
return *map;
}

class ServiceInstanceGroupHolder : public base::SupportsUserData::Data {
public:
explicit ServiceInstanceGroupHolder(const base::Token& instance_group)
: instance_group_(instance_group) {}
~ServiceInstanceGroupHolder() override {}

const base::Token& instance_group() const { return instance_group_; }

private:
base::Token instance_group_;

DISALLOW_COPY_AND_ASSIGN(ServiceInstanceGroupHolder);
};

class ContentServiceHolder : public base::SupportsUserData::Data {
public:
explicit ContentServiceHolder(BrowserContext* browser_context)
Expand All @@ -125,8 +96,6 @@ const char kBrowsingDataRemoverKey[] = "browsing-data-remover";
const char kContentServiceKey[] = "content-service";
const char kDownloadManagerKeyName[] = "download_manager";
const char kPermissionControllerKey[] = "permission-controller";
const char kServiceManagerConnection[] = "service-manager-connection";
const char kServiceInstanceGroup[] = "service-instance-group";
const char kStoragePartitionMapKeyName[] = "content_storage_partition_map";
const char kVideoDecodePerfHistoryId[] = "video-decode-perf-history";
const char kLearningSession[] = "learning-session";
Expand All @@ -135,16 +104,6 @@ const char kLearningSession[] = "learning-session";
const char kMountPointsKey[] = "mount_points";
#endif // defined(OS_CHROMEOS)

void RemoveBrowserContextFromInstanceGroupMap(BrowserContext* browser_context) {
ServiceInstanceGroupHolder* holder = static_cast<ServiceInstanceGroupHolder*>(
browser_context->GetUserData(kServiceInstanceGroup));
if (holder) {
auto it = GetTokenToContextMap().find(holder->instance_group());
if (it != GetTokenToContextMap().end())
GetTokenToContextMap().erase(it);
}
}

StoragePartitionImplMap* GetStoragePartitionMap(
BrowserContext* browser_context) {
StoragePartitionImplMap* partition_map =
Expand Down Expand Up @@ -195,26 +154,6 @@ void SetDownloadManager(
context->SetUserData(kDownloadManagerKeyName, std::move(download_manager));
}

class BrowserContextServiceManagerConnectionHolder
: public base::SupportsUserData::Data {
public:
explicit BrowserContextServiceManagerConnectionHolder(
service_manager::mojom::ServiceRequest request)
: service_manager_connection_(ServiceManagerConnection::Create(
std::move(request),
base::CreateSingleThreadTaskRunner({BrowserThread::IO}))) {}
~BrowserContextServiceManagerConnectionHolder() override {}

ServiceManagerConnection* service_manager_connection() {
return service_manager_connection_.get();
}

private:
std::unique_ptr<ServiceManagerConnection> service_manager_connection_;

DISALLOW_COPY_AND_ASSIGN(BrowserContextServiceManagerConnectionHolder);
};

base::WeakPtr<storage::BlobStorageContext> BlobStorageContextGetterForBrowser(
scoped_refptr<ChromeBlobStorageContext> blob_context) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
Expand Down Expand Up @@ -425,14 +364,6 @@ void BrowserContext::NotifyWillBeDestroyed(BrowserContext* browser_context) {
return;
browser_context->was_notify_will_be_destroyed_called_ = true;

// Stop the ServiceManagerConnection from handling any new incoming requests
// before we tear anything down. This prevents races at shutdown.
BrowserContextServiceManagerConnectionHolder* connection_holder =
static_cast<BrowserContextServiceManagerConnectionHolder*>(
browser_context->GetUserData(kServiceManagerConnection));
if (connection_holder)
connection_holder->service_manager_connection()->Stop();

// Subclasses of BrowserContext may expect there to be no more
// RenderProcessHosts using them by the time this function returns. We
// therefore explicitly tear down embedded Content Service instances now to
Expand Down Expand Up @@ -526,69 +457,10 @@ void BrowserContext::SetPermissionControllerForTesting(
std::move(permission_controller));
}

// static
void BrowserContext::Initialize(BrowserContext* browser_context,
const base::FilePath& path) {
const base::Token new_group = base::Token::CreateRandom();
RemoveBrowserContextFromInstanceGroupMap(browser_context);
GetTokenToContextMap()[new_group] = browser_context;
browser_context->SetUserData(
kServiceInstanceGroup,
std::make_unique<ServiceInstanceGroupHolder>(new_group));

auto* system_connector = GetSystemConnector();
if (system_connector && base::ThreadTaskRunnerHandle::IsSet()) {
// NOTE: Many unit tests create a TestBrowserContext without initializing
// Mojo or the global service manager connection.

mojo::PendingRemote<service_manager::mojom::Service> service;
auto service_receiver = service.InitWithNewPipeAndPassReceiver();

mojo::Remote<service_manager::mojom::ProcessMetadata> metadata;
service_manager::Identity identity(mojom::kBrowserServiceName, new_group,
base::Token{},
base::Token::CreateRandom());
system_connector->RegisterServiceInstance(
identity, std::move(service), metadata.BindNewPipeAndPassReceiver());
metadata->SetPID(base::GetCurrentProcId());

BrowserContextServiceManagerConnectionHolder* connection_holder =
new BrowserContextServiceManagerConnectionHolder(
std::move(service_receiver));
browser_context->SetUserData(kServiceManagerConnection,
base::WrapUnique(connection_holder));
ServiceManagerConnection* connection =
connection_holder->service_manager_connection();

connection->Start();
}
}

// static
const base::Token& BrowserContext::GetServiceInstanceGroupFor(
BrowserContext* browser_context) {
ServiceInstanceGroupHolder* holder = static_cast<ServiceInstanceGroupHolder*>(
browser_context->GetUserData(kServiceInstanceGroup));
CHECK(holder) << "Attempting to get the instance group for a BrowserContext "
<< "that was never Initialized().";
return holder->instance_group();
}

// static
BrowserContext* BrowserContext::GetBrowserContextForServiceInstanceGroup(
const base::Token& instance_group) {
auto it = GetTokenToContextMap().find(instance_group);
return it != GetTokenToContextMap().end() ? it->second : nullptr;
}

BrowserContext::BrowserContext()
: unique_id_(base::UnguessableToken::Create().ToString()) {}

BrowserContext::~BrowserContext() {
CHECK(GetUserData(kServiceInstanceGroup))
<< "Attempting to destroy a BrowserContext that never called "
<< "Initialize()";

DCHECK(!GetUserData(kStoragePartitionMapKeyName))
<< "StoragePartitionMap is not shut down properly";

Expand All @@ -597,8 +469,6 @@ BrowserContext::~BrowserContext() {
base::debug::DumpWithoutCrashing();
}

RemoveBrowserContextFromInstanceGroupMap(this);

if (GetUserData(kDownloadManagerKeyName))
GetDownloadManager(this)->Shutdown();
}
Expand Down
Loading

0 comments on commit 80e710f

Please sign in to comment.