Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Shields domain-specific ad/fingerprint block setting questions #12583

Merged
merged 3 commits into from
Apr 12, 2022

Conversation

DJAndries
Copy link
Collaborator

@DJAndries DJAndries commented Mar 11, 2022

Resolves brave/brave-browser#21546

Resolves brave/brave-browser#22064
Resolves brave/brave-browser#22063

Submitter Checklist:

  • I confirm that no security/privacy review is needed, or that I have requested one
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally: npm run test -- brave_browser_tests, npm run test -- brave_unit_tests, npm run lint, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

  1. Open browser with default settings
  2. Verify that the P3A metrics Brave.Shields.DomainAdsSettingsAboveGlobal, Brave.Shields.DomainAdsSettingsBelowGlobal, Brave.Shields.DomainFingerprintSettingsAboveGlobal, Brave.Shields.DomainFingerprintSettingsBelowGlobal all have values of 0 on the brave://local-state page.
  3. Access a website, update the domain-specific ad-blocking setting to "Aggressive"
  4. Verify that the P3A metric Brave.Shields.DomainAdsSettingsAboveGlobal has a value of 1.
  5. Access another website, update the domain-specific ad-blocking setting to "Allow"
  6. Verify that the P3A metric Brave.Shields.DomainAdsSettingsBelowGlobal has a value of 1, and that Brave.Shields.DomainAdsSettingsAboveGlobal still has a value of 1.
  7. Access a website, update the domain-specific fingerprint blocking setting to "Aggressive"
  8. Verify that the P3A metric Brave.Shields.DomainFingerprintSettingsAboveGlobal has a value of 1.
  9. Access another website, update the domain-specific fingerprint blocking setting to "Allow"
  10. Verify that the P3A metric Brave.Shields.DomainFingerprintSettingsBelowGlobal has a value of 1, and that Brave.Shields.DomainFingerprintSettingsAboveGlobal still has a value of 1.

@DJAndries DJAndries requested review from iefremov and a team as code owners March 11, 2022 20:46
@DJAndries DJAndries added this to the 1.38.x - Nightly milestone Mar 11, 2022
RecordShieldsFingerprintSetting(global_fp_setting);

ShieldsSettingCounts fp_counts = GetFPSettingCount(map);
ShieldsSettingCounts ads_counts = GetAdsSettingCount(map);
Copy link
Collaborator Author

@DJAndries DJAndries Mar 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When performing the first recording of the metrics for a given profile, the domain-specific settings are counted by iterating through the HostContentSettingsMap rules. This will ensure that any settings made by the user before the browser upgrade will be accounted for in the metrics.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a comment in the code

<< GetDomainSettingCount(profile_prefs, is_fingerprint,
*prev_setting);
}
UpdateDomainSettingCount(profile_prefs, is_fingerprint, new_setting, 1);
Copy link
Collaborator Author

@DJAndries DJAndries Mar 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any changes made to the domain-specific settings will be recorded in internal counts stored in the profile preferences. We keep a count of domains for each setting value. When a user changes a setting for a domain, we decrement the count for the previous setting value (if one existed), and increment the count for the new setting value. This is less costly compared to iterating through the HostContentSettingsMap rules every time a user changes a setting.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please put this comment into the code

if (url.is_empty()) {
// If global setting changed, report to P3A
RecordShieldsFingerprintSetting(type);
if (!map->IsOffTheRecord()) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is important that we ignore any domain-specific changes made in the guest/incognito profile.

Copy link
Contributor

@pes10k pes10k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The policy looks good to me, but others would be better than me to review the implementation

@DJAndries DJAndries force-pushed the shields-p3a-multiple-domains branch from 4bd6752 to d6d353e Compare March 11, 2022 22:40
@@ -92,6 +92,10 @@ constexpr const char* kCollectedHistograms[] = {
"Brave.Shields.UsageStatus",
"Brave.Shields.AdBlockSetting",
"Brave.Shields.FingerprintBlockSetting",
"Brave.Shields.DomainAdsSettingsAboveGlobal",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's keep it sorted

@@ -56,6 +61,10 @@ AdBlockPrefService::AdBlockPrefService(AdBlockService* ad_block_service,
OnPreferenceChanged(prefs::kFBEmbedControlType);
OnPreferenceChanged(prefs::kTwitterEmbedControlType);
OnPreferenceChanged(prefs::kLinkedInEmbedControlType);

if (is_regular_profile) {
MaybeRecordInitialShieldsSettings(prefs, host_content_settings_map);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really follow why do we need to pass all the stuff (HostContentSettingsMap, is_regular_profile) to this service (why this one?) just to record P3A. Am I missing something important about this specific location? Maybe we could do that around BraveProfileManager that already has some P3A initialization?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now that you point it out, i agree. moved the function call to browser/profiles/profile_util.cc

@@ -335,9 +334,6 @@ bool AdBlockService::Start() {
regional_service_manager();
subscription_service_manager();

MaybeRecordDefaultShieldsAdsSetting(local_state_);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why recording here doesn't work?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no access to profile

Profile::FromBrowserContext(context)->GetPrefs());
g_brave_browser_process->ad_block_service(), profile->GetPrefs(),
HostContentSettingsMapFactory::GetForProfile(profile),
profile->IsRegularProfile() && !profile->IsGuestSession());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i guess GuestSession is never Regular (see comments for IsRegularProfile())

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general I'm not in favor of passing new things to this service just for P3A

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed, removed

@@ -335,12 +355,21 @@ bool AllowReferrers(HostContentSettingsMap* map, const GURL& url) {
void SetFingerprintingControlType(HostContentSettingsMap* map,
ControlType type,
const GURL& url,
PrefService* local_state) {
PrefService* local_state,
PrefService* profile_state) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use local_state?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or vice versa, erase local state and use only prefs

Copy link
Collaborator Author

@DJAndries DJAndries Apr 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shields settings are per profile, so it may be best to store global/domain-specific setting counts on a per profile basis. The info from the last used profile will be transmitted at P3A report time.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only shields P3A function that uses local_state is MaybeRecordShieldsUsageP3A, which was present before this PR. Perhaps it would be best to refactor that function to use profile prefs in a separate issue/PR

const ContentSettingsForOneType& ads_rules) {
ShieldsSettingCounts result = {};

std::unordered_set<std::string> block_set;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switched to set

@@ -15,6 +15,7 @@

class PrefChangeRegistrar;
class PrefService;
class HostContentSettingsMap;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed

@@ -10,6 +10,7 @@
#include "brave/components/brave_shields/browser/ad_block_regional_service_manager.h"
#include "brave/components/brave_shields/browser/ad_block_service.h"
#include "brave/components/brave_shields/browser/ad_block_subscription_service_manager.h"
#include "brave/components/brave_shields/browser/brave_shields_p3a.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed

@@ -7,6 +7,7 @@

#include "brave/browser/brave_browser_process.h"
#include "brave/components/brave_shields/browser/ad_block_pref_service.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed

@DJAndries DJAndries force-pushed the shields-p3a-multiple-domains branch from d9ebe58 to cb01fb3 Compare April 8, 2022 17:19
@@ -239,16 +239,21 @@ void BraveShieldsDataController::SetAdBlockMode(AdBlockMode mode) {

if (mode == AdBlockMode::AGGRESSIVE) {
control_type_cosmetic = ControlType::BLOCK; // aggressive
} else {
} else if (mode == AdBlockMode::STANDARD) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also confirmed with @nullhook yesterday

Copy link
Collaborator

@bridiver bridiver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chromium_src change looks ok

@DJAndries DJAndries force-pushed the shields-p3a-multiple-domains branch from cb01fb3 to 2e08e18 Compare April 11, 2022 23:42
@DJAndries DJAndries force-pushed the shields-p3a-multiple-domains branch from 2e08e18 to 066a3dd Compare April 11, 2022 23:43
@DJAndries
Copy link
Collaborator Author

force-pushed a rebase

@GeetaSarvadnya
Copy link

GeetaSarvadnya commented Apr 13, 2022

Verification PASSED on

Brave | 1.39.53 Chromium: 100.0.4896.88 (Official Build) nightly (64-bit)
-- | --
Revision | 4450653bfa91182e85723d8f1dee64dd6ce40ed4-refs/branch-heads/4896@{#1086}
OS | Windows 10 Version 21H2 (Build 19044.1586)

[Note: Discussed with @DJAndries, the fix is only for the adblocking "Allow". The other two settings "Aggressive" and "Block" give the same internal preferences values in both 1.39.47 and 1.39.53 ]

Case 1:Verify cosmetic filtering preference_ad blocking settings set to "Allow"
  • Confirmed that cosmetic filtering preference settings is set to 1 when the ad-blocking setting is set to "Allow"
Before the fix - 1.39.47 After the fix - 1.39.53
image image
Case 2:Verify cosmetic filtering preference_ad blocking settings set to "Aggressive"
  • Confirmed that cosmetic filtering preference settings is set to 2 when the ad-blocking setting is set to "Aggressive"
    image
Case 3:Verify cosmetic filtering preference_ad blocking settings set to "Block trackers and ads"
  • Confirmed that cosmetic filtering preference settings is set to 2 when the ad-blocking setting is set to "Block trackers and ads"
    image

@GeetaSarvadnya
Copy link

GeetaSarvadnya commented Apr 13, 2022

@DJAndries I don't see any difference in cosmetic filtering preference for shields v1 and v2 when ad blocking settings are set to "Allow" or "Aggressive" or "Block". Compared the internal cosmetic filtering preferences in 1.37.x and 1.39.x. Just trying to understand what is fixed as part of this PR.

Also, this PR is only for ad-blocking cosmetic filtering internal preferences? does it not applicable for Fingerprint and block cookies settings?

v1 - 1.37.113 v2 - 1.39.53
image image

@DJAndries
Copy link
Collaborator Author

@GeetaSarvadnya it would be best to compare 1.39.53 against a slightly older version of nightly, since this bug is related to the new Shields UI, which is not available in 1.37.x.

This PR involves both the ad-block/cosmetic filtering, and fingerprint blocking settings. However, the commit that addresses brave/brave-browser#22249 only involves the ad-block/cosmetic setting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants