Skip to content

Commit

Permalink
Move UD/ENS/SNS prefs from BravePrefServiceBridge to BraveLocalState …
Browse files Browse the repository at this point in the history
…Java wrapper
  • Loading branch information
AlexeyBarabash committed Jan 4, 2023
1 parent 121f8d5 commit 0b34338
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import org.chromium.brave_wallet.mojom.TxData1559;
import org.chromium.brave_wallet.mojom.TxDataUnion;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.BraveLocalState;
import org.chromium.chrome.browser.app.BraveActivity;
import org.chromium.chrome.browser.app.domain.SendModel;
import org.chromium.chrome.browser.app.domain.WalletModel;
Expand All @@ -88,7 +89,7 @@
import org.chromium.chrome.browser.crypto_wallet.util.WalletUtils;
import org.chromium.chrome.browser.decentralized_dns.EnsOffchainResolveMethod;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.preferences.BravePrefServiceBridge;
import org.chromium.chrome.browser.preferences.BravePref;
import org.chromium.chrome.browser.qrreader.BarcodeTracker;
import org.chromium.chrome.browser.qrreader.BarcodeTrackerFactory;
import org.chromium.chrome.browser.qrreader.CameraSource;
Expand Down Expand Up @@ -1220,8 +1221,8 @@ private void onResolveWalletAddressDone(

Button mBtnEnableEnsOffchainLookup = findViewById(R.id.btn_enable_ens_offchain_lookup);
mBtnEnableEnsOffchainLookup.setOnClickListener(v -> {
BravePrefServiceBridge.getInstance().setENSOffchainResolveMethod(
EnsOffchainResolveMethod.ENABLED);
BraveLocalState.get().setInteger(
BravePref.ENS_OFFCHAIN_RESOLVE_METHOD, EnsOffchainResolveMethod.ENABLED);
mEnsOffchainLookupSection.setVisibility(View.GONE);
maybeResolveWalletAddress();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
import androidx.preference.PreferenceFragmentCompat;

import org.chromium.chrome.R;
import org.chromium.chrome.browser.preferences.BravePrefServiceBridge;
import org.chromium.chrome.browser.BraveLocalState;
import org.chromium.chrome.browser.preferences.BravePref;
import org.chromium.components.browser_ui.settings.SettingsUtils;

public class ENSSettingsFragment extends PreferenceFragmentCompat {
Expand All @@ -27,10 +28,10 @@ public void onCreatePreferences(@Nullable Bundle savedInstanceState, String root
(RadioButtonGroupDDnsResolveMethodPreference) findPreference(
PREF_ENS_RESOLVE_METHOD);
radioButtonGroupDDnsResolveMethodPreference.initialize(
BravePrefServiceBridge.getInstance().getENSResolveMethod());
BraveLocalState.get().getInteger(BravePref.ENS_RESOLVE_METHOD));
radioButtonGroupDDnsResolveMethodPreference.setOnPreferenceChangeListener(
(preference, newValue) -> {
BravePrefServiceBridge.getInstance().setENSResolveMethod((int) newValue);
BraveLocalState.get().setInteger(BravePref.ENS_RESOLVE_METHOD, (int) newValue);
return true;
});

Expand All @@ -39,11 +40,11 @@ public void onCreatePreferences(@Nullable Bundle savedInstanceState, String root
(RadioButtonGroupEnsOffchainResolveMethodPreference) findPreference(
PREF_ENS_OFFCHAIN_LOOKUP_METHOD);
radioButtonGroupEnsOffchainResolveMethodPreference.initialize(
BravePrefServiceBridge.getInstance().getENSOffchainResolveMethod());
BraveLocalState.get().getInteger(BravePref.ENS_OFFCHAIN_RESOLVE_METHOD));
radioButtonGroupEnsOffchainResolveMethodPreference.setOnPreferenceChangeListener(
(preference, newValue) -> {
BravePrefServiceBridge.getInstance().setENSOffchainResolveMethod(
(int) newValue);
BraveLocalState.get().setInteger(
BravePref.ENS_OFFCHAIN_RESOLVE_METHOD, (int) newValue);
return true;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
import androidx.preference.PreferenceFragmentCompat;

import org.chromium.chrome.R;
import org.chromium.chrome.browser.preferences.BravePrefServiceBridge;
import org.chromium.chrome.browser.BraveLocalState;
import org.chromium.chrome.browser.preferences.BravePref;
import org.chromium.components.browser_ui.settings.SettingsUtils;

public class SnsSettingsFragment extends PreferenceFragmentCompat {
Expand All @@ -27,12 +28,12 @@ public void onCreatePreferences(@Nullable Bundle savedInstanceState, String root
PREF_SNS_RESOLVE_METHOD);

radioButtonGroupDDnsResolveMethodPreference.initialize(
BravePrefServiceBridge.getInstance().getSnsResolveMethod());
BraveLocalState.get().getInteger(BravePref.SNS_RESOLVE_METHOD));

radioButtonGroupDDnsResolveMethodPreference.setOnPreferenceChangeListener(
(preference, newValue) -> {
int method = (int) newValue;
BravePrefServiceBridge.getInstance().setSnsResolveMethod(method);
BraveLocalState.get().setInteger(BravePref.SNS_RESOLVE_METHOD, method);
return true;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
import androidx.preference.PreferenceFragmentCompat;

import org.chromium.chrome.R;
import org.chromium.chrome.browser.preferences.BravePrefServiceBridge;
import org.chromium.chrome.browser.BraveLocalState;
import org.chromium.chrome.browser.preferences.BravePref;
import org.chromium.components.browser_ui.settings.SettingsUtils;

public class UnstoppableDomainsSettingsFragment extends PreferenceFragmentCompat {
Expand All @@ -28,12 +29,13 @@ public void onCreatePreferences(@Nullable Bundle savedInstanceState, String root
PREF_UNSTOPPABLE_DOMAINS_RESOLVE_METHOD);

radioButtonGroupDDnsResolveMethodPreference.initialize(
BravePrefServiceBridge.getInstance().getUnstoppableDomainsResolveMethod());
BraveLocalState.get().getInteger(BravePref.UNSTOPPABLE_DOMAINS_RESOLVE_METHOD));

radioButtonGroupDDnsResolveMethodPreference.setOnPreferenceChangeListener(
(preference, newValue) -> {
int method = (int) newValue;
BravePrefServiceBridge.getInstance().setUnstoppableDomainsResolveMethod(method);
BraveLocalState.get().setInteger(
BravePref.UNSTOPPABLE_DOMAINS_RESOLVE_METHOD, method);
return true;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,38 +162,6 @@ public boolean GetBooleanForContentSetting(int content_type) {
return BravePrefServiceBridgeJni.get().getBooleanForContentSetting(content_type);
}

public void setUnstoppableDomainsResolveMethod(int method) {
BravePrefServiceBridgeJni.get().setUnstoppableDomainsResolveMethod(method);
}

public int getUnstoppableDomainsResolveMethod() {
return BravePrefServiceBridgeJni.get().getUnstoppableDomainsResolveMethod();
}

public void setENSResolveMethod(int method) {
BravePrefServiceBridgeJni.get().setENSResolveMethod(method);
}

public int getENSResolveMethod() {
return BravePrefServiceBridgeJni.get().getENSResolveMethod();
}

public void setENSOffchainResolveMethod(int method) {
BravePrefServiceBridgeJni.get().setENSOffchainResolveMethod(method);
}

public int getENSOffchainResolveMethod() {
return BravePrefServiceBridgeJni.get().getENSOffchainResolveMethod();
}

public void setSnsResolveMethod(int method) {
BravePrefServiceBridgeJni.get().setSnsResolveMethod(method);
}

public int getSnsResolveMethod() {
return BravePrefServiceBridgeJni.get().getSnsResolveMethod();
}

public void setWebrtcPolicy(int policy) {
BravePrefServiceBridgeJni.get().setWebrtcPolicy(policy);
}
Expand Down Expand Up @@ -261,15 +229,6 @@ interface Natives {
void resetPromotionLastFetchStamp();
boolean getBooleanForContentSetting(int content_type);

void setUnstoppableDomainsResolveMethod(int method);
int getUnstoppableDomainsResolveMethod();
void setENSResolveMethod(int method);
int getENSResolveMethod();
void setENSOffchainResolveMethod(int method);
int getENSOffchainResolveMethod();
void setSnsResolveMethod(int method);
int getSnsResolveMethod();

void setWebrtcPolicy(int policy);
int getWebrtcPolicy();

Expand Down
1 change: 1 addition & 0 deletions browser/android/preferences/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ java_cpp_strings("java_pref_names_srcjar") {
"//brave/components/constants/pref_names.cc",
"//brave/components/de_amp/common/pref_names.cc",
"//brave/components/debounce/common/pref_names.cc",
"//brave/components/decentralized_dns/core/pref_names.cc",
"//brave/components/ntp_background_images/common/pref_names.cc",
"//brave/components/omnibox/browser/brave_omnibox_prefs.cc",
"//brave/components/p3a/pref_names.cc",
Expand Down
44 changes: 0 additions & 44 deletions browser/android/preferences/brave_pref_service_bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -376,50 +376,6 @@ void JNI_BravePrefServiceBridge_SetWebrtcPolicy(JNIEnv* env, jint policy) {
GetWebRTCIPHandlingPreference((WebRTCIPHandlingPolicy)policy));
}

void JNI_BravePrefServiceBridge_SetUnstoppableDomainsResolveMethod(
JNIEnv* env,
jint method) {
g_browser_process->local_state()->SetInteger(
decentralized_dns::kUnstoppableDomainsResolveMethod, method);
}

jint JNI_BravePrefServiceBridge_GetUnstoppableDomainsResolveMethod(
JNIEnv* env) {
return g_browser_process->local_state()->GetInteger(
decentralized_dns::kUnstoppableDomainsResolveMethod);
}

void JNI_BravePrefServiceBridge_SetENSResolveMethod(JNIEnv* env, jint method) {
g_browser_process->local_state()->SetInteger(
decentralized_dns::kENSResolveMethod, method);
}

jint JNI_BravePrefServiceBridge_GetENSResolveMethod(JNIEnv* env) {
return g_browser_process->local_state()->GetInteger(
decentralized_dns::kENSResolveMethod);
}

void JNI_BravePrefServiceBridge_SetENSOffchainResolveMethod(JNIEnv* env,
jint method) {
g_browser_process->local_state()->SetInteger(
decentralized_dns::kEnsOffchainResolveMethod, method);
}

jint JNI_BravePrefServiceBridge_GetENSOffchainResolveMethod(JNIEnv* env) {
return g_browser_process->local_state()->GetInteger(
decentralized_dns::kEnsOffchainResolveMethod);
}

void JNI_BravePrefServiceBridge_SetSnsResolveMethod(JNIEnv* env, jint method) {
g_browser_process->local_state()->SetInteger(
decentralized_dns::kSnsResolveMethod, method);
}

jint JNI_BravePrefServiceBridge_GetSnsResolveMethod(JNIEnv* env) {
return g_browser_process->local_state()->GetInteger(
decentralized_dns::kSnsResolveMethod);
}

void JNI_BravePrefServiceBridge_SetNewsOptIn(JNIEnv* env, jboolean value) {
GetOriginalProfile()->GetPrefs()->SetBoolean(
brave_news::prefs::kBraveTodayOptedIn, value);
Expand Down
1 change: 1 addition & 0 deletions components/decentralized_dns/core/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
static_library("core") {
sources = [
"constants.h",
"pref_names.cc",
"pref_names.h",
"utils.cc",
"utils.h",
Expand Down
19 changes: 19 additions & 0 deletions components/decentralized_dns/core/pref_names.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* Copyright (c) 2023 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/components/decentralized_dns/core/pref_names.h"

namespace decentralized_dns {

const char kUnstoppableDomainsResolveMethod[] =
"brave.unstoppable_domains.resolve_method";

const char kENSResolveMethod[] = "brave.ens.resolve_method";

const char kEnsOffchainResolveMethod[] = "brave.ens.offchain_resolve_method";

const char kSnsResolveMethod[] = "brave.sns.resolve_method";

} // namespace decentralized_dns
10 changes: 4 additions & 6 deletions components/decentralized_dns/core/pref_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,23 @@ namespace decentralized_dns {
// Disabled: Disable all unstoppable domains resolution.
// Ask: Ask users if they want to enable support of unstoppable domains.
// Enabled: Resolve domain name using Ethereum JSON-RPC server.
constexpr char kUnstoppableDomainsResolveMethod[] =
"brave.unstoppable_domains.resolve_method";
extern const char kUnstoppableDomainsResolveMethod[];

// Used to determine which method should be used to resolve ENS domains,
// between:
// Disabled: Disable all ENS domains resolution.
// Ask: Ask users if they want to enable support of ENS.
// Enabled: Resolve domain name using Ethereum JSON-RPC server.
constexpr char kENSResolveMethod[] = "brave.ens.resolve_method";
extern const char kENSResolveMethod[];

constexpr char kEnsOffchainResolveMethod[] =
"brave.ens.offchain_resolve_method";
extern const char kEnsOffchainResolveMethod[];

// Used to determine which method should be used to resolve SNS domains,
// between:
// Disabled: Disable all SNS domains resolution.
// Ask: Ask users if they want to enable support of SNS.
// Enabled: Resolve domain name using Solana JSON-RPC server.
constexpr char kSnsResolveMethod[] = "brave.sns.resolve_method";
extern const char kSnsResolveMethod[];

} // namespace decentralized_dns

Expand Down

0 comments on commit 0b34338

Please sign in to comment.