Skip to content

Commit

Permalink
Optimized initialization of PrefChangeRegistrar (avoiding multiple in…
Browse files Browse the repository at this point in the history
…its)

Thanks to @simonhong for going through the docs w/ me to confirm life-cycle:
https://chromium.googlesource.com/chromium/src.git/+/master/docs/webui_explainer.md
  • Loading branch information
bsclifton committed Nov 25, 2019
1 parent b429694 commit e7b2d99
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
24 changes: 12 additions & 12 deletions browser/ui/webui/settings/brave_privacy_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@
#include "brave/browser/gcm_driver/brave_gcm_channel_status.h"
#endif

BravePrivacyHandler::BravePrivacyHandler() {
local_state_change_registrar_.Init(g_browser_process->local_state());
local_state_change_registrar_.Add(
kRemoteDebuggingEnabled,
base::Bind(&BravePrivacyHandler::OnRemoteDebuggingEnabledChanged,
base::Unretained(this)));
}

BravePrivacyHandler::~BravePrivacyHandler() {
local_state_change_registrar_.RemoveAll();
}

void BravePrivacyHandler::RegisterMessages() {
profile_ = Profile::FromWebUI(web_ui());

Expand Down Expand Up @@ -51,18 +63,6 @@ void BravePrivacyHandler::RegisterMessages() {
base::Unretained(this)));
}

void BravePrivacyHandler::OnJavascriptAllowed() {
local_state_change_registrar_.Init(g_browser_process->local_state());
local_state_change_registrar_.Add(
kRemoteDebuggingEnabled,
base::Bind(&BravePrivacyHandler::OnRemoteDebuggingEnabledChanged,
base::Unretained(this)));
}

void BravePrivacyHandler::OnJavascriptDisallowed() {
local_state_change_registrar_.RemoveAll();
}

// static
void BravePrivacyHandler::AddLoadTimeData(content::WebUIDataSource* data_source,
Profile* profile) {
Expand Down
8 changes: 4 additions & 4 deletions browser/ui/webui/settings/brave_privacy_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ class Profile;

class BravePrivacyHandler : public settings::SettingsPageUIHandler {
public:
BravePrivacyHandler() = default;
~BravePrivacyHandler() override = default;
BravePrivacyHandler();
~BravePrivacyHandler() override;
static void AddLoadTimeData(content::WebUIDataSource* data_source,
Profile* profile);

private:
// SettingsPageUIHandler overrides:
void RegisterMessages() override;
void OnJavascriptAllowed() override;
void OnJavascriptDisallowed() override;
void OnJavascriptAllowed() override {}
void OnJavascriptDisallowed() override {}

void SetWebRTCPolicy(const base::ListValue* args);
void GetWebRTCPolicy(const base::ListValue* args);
Expand Down

0 comments on commit e7b2d99

Please sign in to comment.