Skip to content

Commit

Permalink
Add listener for brave://settings/privacy to ensure P3A enabled value…
Browse files Browse the repository at this point in the history
… is in sync

For example, if you had two windows with brave://settings/privacy open

Fixes brave/brave-browser#7289

This is something I missed while implementing #3242
  • Loading branch information
bsclifton committed Dec 9, 2019
1 parent 31683c7 commit d056a21
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ Polymer({
this.addWebUIListener('remote-debugging-enabled-changed', (enabled) => {
this.remoteDebuggingEnabled_ = enabled
})
this.addWebUIListener('p3a-enabled-changed', (enabled) => {
this.p3aEnabled_ = enabled
})
},

/**
Expand Down
13 changes: 13 additions & 0 deletions browser/ui/webui/settings/brave_privacy_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ BravePrivacyHandler::BravePrivacyHandler() {
kRemoteDebuggingEnabled,
base::Bind(&BravePrivacyHandler::OnRemoteDebuggingEnabledChanged,
base::Unretained(this)));
local_state_change_registrar_.Add(
brave::kP3AEnabled,
base::Bind(&BravePrivacyHandler::OnP3AEnabledChanged,
base::Unretained(this)));
}

BravePrivacyHandler::~BravePrivacyHandler() {
Expand Down Expand Up @@ -119,6 +123,15 @@ void BravePrivacyHandler::GetP3AEnabled(const base::ListValue* args) {
ResolveJavascriptCallback(args->GetList()[0].Clone(), base::Value(enabled));
}

void BravePrivacyHandler::OnP3AEnabledChanged() {
if (IsJavascriptAllowed()) {
PrefService* local_state = g_browser_process->local_state();
bool enabled = local_state->GetBoolean(brave::kP3AEnabled);

FireWebUIListener("p3a-enabled-changed", base::Value(enabled));
}
}

void BravePrivacyHandler::SetRemoteDebuggingEnabled(
const base::ListValue* args) {
CHECK_EQ(args->GetSize(), 1U);
Expand Down
1 change: 1 addition & 0 deletions browser/ui/webui/settings/brave_privacy_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class BravePrivacyHandler : public settings::SettingsPageUIHandler {

void SetP3AEnabled(const base::ListValue* args);
void GetP3AEnabled(const base::ListValue* args);
void OnP3AEnabledChanged();

void SetRemoteDebuggingEnabled(const base::ListValue* args);
void GetRemoteDebuggingEnabled(const base::ListValue* args);
Expand Down

0 comments on commit d056a21

Please sign in to comment.