Skip to content

Commit

Permalink
Share prefs between Tor profile and its parent profile.
Browse files Browse the repository at this point in the history
  • Loading branch information
yrliou committed Oct 2, 2019
1 parent 3418ed7 commit 0979ed1
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* Copyright (c) 2019 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "brave/browser/profiles/profile_util.h"

#define BRAVE_BUILD_SERVICE_INSTANCE_FOR brave::IsSessionProfile(profile) ||
#include "../../../../../chrome/browser/content_settings/host_content_settings_map_factory.cc"
62 changes: 52 additions & 10 deletions chromium_src/chrome/browser/profiles/pref_service_builder_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,31 @@

#include "chrome/browser/profiles/pref_service_builder_utils.h"

#define RegisterProfilePrefs RegisterProfilePrefs_ChromiumImpl
#include "../../../../../chrome/browser/profiles/pref_service_builder_utils.cc"
#undef RegisterProfilePrefs

#include "brave/browser/brave_profile_prefs.h"
#include "brave/browser/profiles/brave_profile_impl.h"
#include "brave/browser/profiles/profile_util.h"
#include "brave/browser/themes/brave_theme_service.h"
#include "brave/browser/tor/buildflags.h"
#include "brave/common/pref_names.h"
#include "brave/components/brave_rewards/browser/rewards_service.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/prefs/pref_service_syncable_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/common/pref_names.h"
#include "components/spellcheck/browser/pref_names.h"

#if BUILDFLAG(ENABLE_TOR)
#include "brave/browser/tor/tor_profile_service.h"
#if BUILDFLAG(ENABLE_EXTENSIONS)
#include "extensions/browser/extension_pref_store.h"
#include "extensions/browser/extension_pref_value_map_factory.h"
#endif

#define CreatePrefService CreatePrefService_ChromiumImpl
#define RegisterProfilePrefs RegisterProfilePrefs_ChromiumImpl
#include "../../../../../chrome/browser/profiles/pref_service_builder_utils.cc"
#undef CreatePrefService
#undef RegisterProfilePrefs

// Prefs for KeyedService
void RegisterProfilePrefs(bool is_signin_profile,
const std::string& locale,
Expand All @@ -32,10 +41,6 @@ void RegisterProfilePrefs(bool is_signin_profile,
BraveThemeService::RegisterProfilePrefs(registry);
#endif

#if BUILDFLAG(ENABLE_TOR)
tor::TorProfileService::RegisterProfilePrefs(registry);
#endif

brave_rewards::RewardsService::RegisterProfilePrefs(registry);

// Disable spell check service
Expand All @@ -53,3 +58,40 @@ void RegisterProfilePrefs(bool is_signin_profile,
registry->SetDefaultPrefValue(prefs::kUsesSystemTheme, base::Value(false));
#endif
}

std::unique_ptr<sync_preferences::PrefServiceSyncable> CreatePrefService(
scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry,
PrefStore* extension_pref_store,
policy::PolicyService* policy_service,
policy::ChromeBrowserPolicyConnector* browser_policy_connector,
prefs::mojom::TrackedPreferenceValidationDelegatePtr
pref_validation_delegate,
scoped_refptr<base::SequencedTaskRunner> io_task_runner,
SimpleFactoryKey* key,
const base::FilePath& path,
bool async_prefs) {
// Create prefs using the same approach that chromium used when creating an
// off-the-record profile from its original profile.
if (brave::IsSessionProfilePath(path)) {
base::FilePath original_path = brave::GetParentProfilePath(path);
Profile* original_profile =
g_browser_process->profile_manager()->GetProfileByPath(original_path);
DCHECK(original_profile);
PrefStore* extension_pref_store;
#if BUILDFLAG(ENABLE_EXTENSIONS)
extension_pref_store = new ExtensionPrefStore(
ExtensionPrefValueMapFactory::GetForBrowserContext(original_profile),
true);
#endif
return CreateIncognitoPrefServiceSyncable(
PrefServiceSyncableFromProfile(original_profile),
extension_pref_store,
InProcessPrefServiceFactoryFactory::GetInstanceForKey(key)
->CreateDelegate());
}

return CreatePrefService_ChromiumImpl(
pref_registry, extension_pref_store, policy_service,
browser_policy_connector, std::move(pref_validation_delegate),
io_task_runner, key, path, async_prefs);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* Copyright (c) 2019 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#include "brave/browser/profiles/profile_util.h"

// Use the same SupervisedUserSettingsService, which handles a part of
// preferences, as its parent profile. Chromium's incognito profile also shares
// it with its original profile.
#define BRAVE_GET_KEY_TO_USE \
if (brave::IsSessionProfilePath(key->GetPath())) { \
return brave::GetParentProfile(key->GetPath())->GetProfileKey(); \
}

#include "../../../../../chrome/browser/supervised_user/supervised_user_settings_service_factory.cc"
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/chrome/browser/content_settings/host_content_settings_map_factory.cc b/chrome/browser/content_settings/host_content_settings_map_factory.cc
index a3797e6705b879e917c33bc907ce6482c5c10c68..0d2c8792432e1dfeb80511d9ff54d8df9cd06519 100644
--- a/chrome/browser/content_settings/host_content_settings_map_factory.cc
+++ b/chrome/browser/content_settings/host_content_settings_map_factory.cc
@@ -80,6 +80,7 @@ scoped_refptr<RefcountedKeyedService>

scoped_refptr<HostContentSettingsMap> settings_map(new HostContentSettingsMap(
profile->GetPrefs(),
+ BRAVE_BUILD_SERVICE_INSTANCE_FOR
profile->IsIncognitoProfile() || profile->IsGuestSession(),
/*store_last_modified=*/true,
base::FeatureList::IsEnabled(features::kPermissionDelegation)));
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/chrome/browser/supervised_user/supervised_user_settings_service_factory.cc b/chrome/browser/supervised_user/supervised_user_settings_service_factory.cc
index 5f85a90f2f2800c00bf0367c1de83ff36d8b8fe7..9ab88b8a25b36afdbe3016fd20cc29343395e634 100644
--- a/chrome/browser/supervised_user/supervised_user_settings_service_factory.cc
+++ b/chrome/browser/supervised_user/supervised_user_settings_service_factory.cc
@@ -36,6 +36,7 @@ SupervisedUserSettingsServiceFactory::BuildServiceInstanceFor(

SimpleFactoryKey* SupervisedUserSettingsServiceFactory::GetKeyToUse(
SimpleFactoryKey* key) const {
+ BRAVE_GET_KEY_TO_USE
ProfileKey* profile_key = ProfileKey::FromSimpleFactoryKey(key);
return profile_key->GetOriginalKey();
}

0 comments on commit 0979ed1

Please sign in to comment.