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

Wallet's mojo interfaces cleanup #20161

Merged
merged 5 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions browser/brave_wallet/asset_discovery_manager_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "brave/browser/brave_wallet/json_rpc_service_factory.h"
#include "brave/browser/brave_wallet/keyring_service_factory.h"
#include "brave/browser/brave_wallet/tx_service_factory.h"
#include "brave/components/brave_wallet/browser/brave_wallet_constants.h"
#include "brave/components/brave_wallet/browser/brave_wallet_service.h"
#include "brave/components/brave_wallet/browser/brave_wallet_service_delegate.h"
#include "brave/components/brave_wallet/browser/brave_wallet_service_observer_base.h"
Expand Down
1 change: 1 addition & 0 deletions browser/brave_wallet/brave_wallet_service_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "brave/browser/brave_wallet/tx_service_factory.h"
#include "brave/components/brave_wallet/browser/blockchain_list_parser.h"
#include "brave/components/brave_wallet/browser/blockchain_registry.h"
#include "brave/components/brave_wallet/browser/brave_wallet_constants.h"
#include "brave/components/brave_wallet/browser/brave_wallet_service_delegate.h"
#include "brave/components/brave_wallet/browser/brave_wallet_service_observer_base.h"
#include "brave/components/brave_wallet/browser/brave_wallet_utils.h"
Expand Down
12 changes: 1 addition & 11 deletions browser/brave_wallet/ethereum_provider_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,20 @@
#include "brave/browser/brave_wallet/keyring_service_factory.h"
#include "brave/browser/brave_wallet/tx_service_factory.h"
#include "brave/components/brave_wallet/browser/asset_ratio_service.h"
#include "brave/components/brave_wallet/browser/brave_wallet_constants.h"
#include "brave/components/brave_wallet/browser/brave_wallet_service.h"
#include "brave/components/brave_wallet/browser/brave_wallet_utils.h"
#include "brave/components/brave_wallet/browser/eth_nonce_tracker.h"
#include "brave/components/brave_wallet/browser/eth_pending_tx_tracker.h"
#include "brave/components/brave_wallet/browser/eth_tx_manager.h"
#include "brave/components/brave_wallet/browser/hd_keyring.h"
#include "brave/components/brave_wallet/browser/json_rpc_service.h"
#include "brave/components/brave_wallet/browser/keyring_service.h"
#include "brave/components/brave_wallet/browser/permission_utils.h"
#include "brave/components/brave_wallet/browser/pref_names.h"
#include "brave/components/brave_wallet/browser/test_utils.h"
#include "brave/components/brave_wallet/browser/tx_service.h"
#include "brave/components/brave_wallet/common/brave_wallet.mojom.h"
#include "brave/components/brave_wallet/common/hex_utils.h"
#include "brave/components/brave_wallet/common/web3_provider_constants.h"
#include "brave/components/permissions/brave_permission_manager.h"
#include "brave/components/permissions/contexts/brave_wallet_permission_context.h"
#include "brave/components/version_info/version_info.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/permissions/permission_manager_factory.h"
#include "chrome/browser/prefs/browser_prefs.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/test/base/scoped_testing_local_state.h"
#include "chrome/test/base/testing_browser_process.h"
Expand All @@ -61,9 +54,6 @@
#include "components/grit/brave_components_strings.h"
#include "components/permissions/permission_request_manager.h"
#include "components/prefs/pref_service.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "components/user_prefs/user_prefs.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/test_web_contents_factory.h"
#include "content/test/test_web_contents.h"
Expand Down
1 change: 0 additions & 1 deletion browser/brave_wallet/notifications/sources.gni
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ brave_browser_brave_wallet_deps =
brave_browser_brave_wallet_sources = []
if (!is_android) {
brave_browser_brave_wallet_sources += [
"//brave/browser/brave_wallet/notifications/wallet_notification_helper_impl.cc",
"//brave/browser/brave_wallet/notifications/wallet_notification_service.cc",
"//brave/browser/brave_wallet/notifications/wallet_notification_service.h",
"//brave/browser/brave_wallet/notifications/wallet_notification_service_factory.cc",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <string>

#include "base/strings/utf_string_conversions.h"
#include "brave/components/brave_wallet/browser/tx_service.h"
#include "chrome/browser/notifications/notification_display_service.h"
#include "chrome/browser/notifications/notification_display_service_factory.h"
#include "chrome/browser/profiles/profile.h"
Expand Down Expand Up @@ -71,8 +72,11 @@ void PushNotification(content::BrowserContext* context,
namespace brave_wallet {

WalletNotificationService::WalletNotificationService(
TxService* tx_service,
content::BrowserContext* context)
: context_(context) {}
: context_(context) {
tx_service->AddObserver(tx_observer_receiver_.BindNewPipeAndPassRemote());
}

WalletNotificationService::~WalletNotificationService() = default;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,20 @@
#include "base/memory/raw_ptr.h"
#include "brave/components/brave_wallet/common/brave_wallet.mojom.h"
#include "components/keyed_service/core/keyed_service.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"

namespace content {
class BrowserContext;
} // namespace content

namespace brave_wallet {
class TxService;

class WalletNotificationService : public KeyedService,
public mojom::TxServiceObserver {
public:
explicit WalletNotificationService(content::BrowserContext* context);
WalletNotificationService(TxService* tx_service,
content::BrowserContext* context);
~WalletNotificationService() override;
WalletNotificationService(const WalletNotificationService&) = delete;
WalletNotificationService operator=(const WalletNotificationService&) =
Expand All @@ -35,10 +36,6 @@ class WalletNotificationService : public KeyedService,
void OnTransactionStatusChanged(mojom::TransactionInfoPtr tx_info) override;
void OnTxServiceReset() override {}

mojo::PendingRemote<mojom::TxServiceObserver> GetReceiver() {
return tx_observer_receiver_.BindNewPipeAndPassRemote();
}

private:
friend class WalletNotificationServiceUnitTest;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ WalletNotificationServiceFactory::~WalletNotificationServiceFactory() = default;

KeyedService* WalletNotificationServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
return new WalletNotificationService(context);
return new WalletNotificationService(
TxServiceFactory::GetServiceForContext(context), context);
}

// static
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class WalletNotificationServiceUnitTest : public testing::Test {
tx_service_ = std::make_unique<TxService>(
json_rpc_service_.get(), nullptr, keyring_service_.get(), prefs(),
temp_dir_.GetPath(), base::SequencedTaskRunner::GetCurrentDefault());
notification_service_ =
std::make_unique<WalletNotificationService>(profile());
notification_service_ = std::make_unique<WalletNotificationService>(
tx_service_.get(), profile());
tester_ = std::make_unique<NotificationDisplayServiceTester>(profile());
keyring_service_->CreateWallet(kMnemonicDivideCruise, "brave",
base::DoNothing());
Expand Down
24 changes: 6 additions & 18 deletions browser/brave_wallet/tx_service_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,11 @@
#include "brave/browser/brave_wallet/brave_wallet_context_utils.h"
#include "brave/browser/brave_wallet/json_rpc_service_factory.h"
#include "brave/browser/brave_wallet/keyring_service_factory.h"
#include "brave/components/brave_wallet/browser/brave_wallet_constants.h"
#include "brave/components/brave_wallet/browser/tx_service.h"
#include "chrome/browser/profiles/incognito_helpers.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/user_prefs/user_prefs.h"

#if !BUILDFLAG(IS_ANDROID)
#include "brave/browser/brave_wallet/wallet_notification_helper.h"
#endif

namespace brave_wallet {

// static
Expand Down Expand Up @@ -148,19 +143,12 @@ TxServiceFactory::~TxServiceFactory() = default;

KeyedService* TxServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
auto* tx_service =
new TxService(JsonRpcServiceFactory::GetServiceForContext(context),
BitcoinWalletServiceFactory::GetServiceForContext(context),
KeyringServiceFactory::GetServiceForContext(context),
user_prefs::UserPrefs::Get(context), context->GetPath(),
base::SequencedTaskRunner::GetCurrentDefault());
#if !BUILDFLAG(IS_ANDROID)
// TODO(apaymyshev): WalletNotificationServiceFactory depends on
// TxServiceFactory and should be responsible for subscribing on TxService.
// Refactor this.
RegisterWalletNotificationService(context, tx_service);
#endif
return tx_service;
return new TxService(
JsonRpcServiceFactory::GetServiceForContext(context),
BitcoinWalletServiceFactory::GetServiceForContext(context),
KeyringServiceFactory::GetServiceForContext(context),
user_prefs::UserPrefs::Get(context), context->GetPath(),
base::SequencedTaskRunner::GetCurrentDefault());
}

content::BrowserContext* TxServiceFactory::GetBrowserContextToUse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,7 @@ IN_PROC_BROWSER_TEST_F(WalletButtonNotificationSourceTest,
"" /* nonce */, "10" /* gas_premium */, "10" /* gas_fee_cap */,
"100" /* gas_limit */, "" /* max_fee */, to_account, "11"));
tx_service()->AddUnapprovedTransaction(
std::move(tx_data), from_account->account_id.Clone(), absl::nullopt,
absl::nullopt,
std::move(tx_data), from_account->account_id.Clone(),
base::BindLambdaForTesting([&](bool success, const std::string& id,
const std::string& err_message) {
first_tx_meta_id = id;
Expand Down Expand Up @@ -237,7 +236,7 @@ IN_PROC_BROWSER_TEST_F(WalletButtonNotificationSourceTest,
std::vector<uint8_t>(), false, absl::nullopt);
tx_service()->AddUnapprovedTransaction(
brave_wallet::mojom::TxDataUnion::NewEthTxData(std::move(tx_data)),
from_account->account_id.Clone(), absl::nullopt, absl::nullopt,
from_account->account_id.Clone(),
base::BindLambdaForTesting([&](bool success, const std::string& id,
const std::string& err_message) {
second_tx_meta_id = id;
Expand Down Expand Up @@ -270,7 +269,7 @@ IN_PROC_BROWSER_TEST_F(WalletButtonNotificationSourceTest,

tx_service()->AddUnapprovedTransaction(
brave_wallet::mojom::TxDataUnion::NewSolanaTxData(std::move(tx_data)),
from_account->account_id.Clone(), absl::nullopt, absl::nullopt,
from_account->account_id.Clone(),
base::BindLambdaForTesting([&](bool success, const std::string& id,
const std::string& err_message) {
third_tx_meta_id = id;
Expand Down Expand Up @@ -367,8 +366,7 @@ IN_PROC_BROWSER_TEST_F(WalletButtonNotificationSourceTest,
"" /* nonce */, "10" /* gas_premium */, "10" /* gas_fee_cap */,
"100" /* gas_limit */, "" /* max_fee */, to_account, "11"));
tx_service()->AddUnapprovedTransaction(
std::move(tx_data), from_account->account_id.Clone(), absl::nullopt,
absl::nullopt,
std::move(tx_data), from_account->account_id.Clone(),
base::BindLambdaForTesting([&](bool success, const std::string& id,
const std::string& err_message) {
tx_meta_id = id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "brave/components/brave_shields/browser/ad_block_service.h"
#include "brave/components/brave_wallet/browser/asset_ratio_service.h"
#include "brave/components/brave_wallet/browser/blockchain_registry.h"
#include "brave/components/brave_wallet/browser/brave_wallet_constants.h"
#include "brave/components/brave_wallet/browser/brave_wallet_service.h"
#include "brave/components/brave_wallet/browser/brave_wallet_utils.h"
#include "brave/components/brave_wallet/browser/json_rpc_service.h"
Expand Down
2 changes: 2 additions & 0 deletions components/brave_wallet/browser/asset_discovery_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include <map>

#include "base/no_destructor.h"
#include "brave/components/brave_wallet/browser/brave_wallet_constants.h"
#include "brave/components/brave_wallet/browser/brave_wallet_service.h"
#include "brave/components/brave_wallet/browser/brave_wallet_utils.h"
#include "brave/components/brave_wallet/browser/json_rpc_service.h"
Expand Down
1 change: 1 addition & 0 deletions components/brave_wallet/browser/asset_ratio_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "base/base64.h"
#include "base/environment.h"
#include "base/json/json_writer.h"
#include "base/no_destructor.h"
#include "base/strings/stringprintf.h"
#include "brave/components/api_request_helper/api_request_helper.h"
#include "brave/components/brave_wallet/browser/brave_wallet_constants.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "brave/components/brave_wallet/browser/bitcoin/bitcoin_transaction.h"
#include "brave/components/brave_wallet/browser/bitcoin/bitcoin_tx_meta.h"
#include "brave/components/brave_wallet/browser/bitcoin/bitcoin_tx_state_manager.h"
#include "components/grit/brave_components_strings.h"
#include "ui/base/l10n/l10n_util.h"

namespace brave_wallet {
Expand Down Expand Up @@ -53,7 +54,6 @@ void BitcoinTxManager::AddUnapprovedTransaction(
mojom::TxDataUnionPtr tx_data_union,
const mojom::AccountIdPtr& from,
const absl::optional<url::Origin>& origin,
const absl::optional<std::string>& group_id,
AddUnapprovedTransactionCallback callback) {
const auto& btc_tx_data = tx_data_union->get_btc_tx_data();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class BitcoinTxManager : public TxManager,
mojom::TxDataUnionPtr tx_data_union,
const mojom::AccountIdPtr& from,
const absl::optional<url::Origin>& origin,
const absl::optional<std::string>& group_id,
AddUnapprovedTransactionCallback) override;
void ApproveTransaction(const std::string& chain_id,
const std::string& tx_meta_id,
Expand Down
4 changes: 2 additions & 2 deletions components/brave_wallet/browser/bitcoin/bitcoin_tx_meta.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ mojom::TransactionInfoPtr BitcoinTxMeta::ToTransactionInfo() const {
base::Milliseconds(created_time_.ToJavaTime()),
base::Milliseconds(submitted_time_.ToJavaTime()),
base::Milliseconds(confirmed_time_.ToJavaTime()),
origin_.has_value() ? MakeOriginInfo(*origin_) : nullptr, group_id_,
chain_id_, tx_->to());
origin_.has_value() ? MakeOriginInfo(*origin_) : nullptr, chain_id_,
tx_->to());
}

} // namespace brave_wallet
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ TEST(BitcoinTxMeta, ToTransactionInfo) {
EXPECT_EQ(ti->from_account_id, btc_account_id);
EXPECT_EQ(ti->tx_status, meta.status());
EXPECT_TRUE(ti->tx_data_union->is_btc_tx_data());
EXPECT_EQ(ti->group_id, meta.group_id());
EXPECT_EQ(meta.created_time().ToJavaTime(),
ti->created_time.InMilliseconds());
EXPECT_EQ(meta.submitted_time().ToJavaTime(),
Expand Down
7 changes: 5 additions & 2 deletions components/brave_wallet/browser/brave_wallet_constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
* 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/brave_wallet/browser/brave_wallet_constants.h"

#include <map>
#include <string>

#include "base/command_line.h"
#include "base/containers/contains.h"
#include "brave/components/brave_wallet/browser/brave_wallet_constants.h"
#include "brave/components/brave_wallet/common/brave_wallet.mojom-shared.h"
#include "base/no_destructor.h"
#include "brave/components/brave_wallet/common/brave_wallet.mojom.h"
#include "brave/components/brave_wallet/common/switches.h"

namespace brave_wallet {

Expand Down
3 changes: 0 additions & 3 deletions components/brave_wallet/browser/brave_wallet_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
#include <string>
#include <vector>

#include "base/no_destructor.h"
#include "brave/components/brave_wallet/common/brave_wallet.mojom.h"
#include "brave/components/brave_wallet/common/brave_wallet_types.h"
#include "brave/components/brave_wallet/common/switches.h"
#include "components/grit/brave_components_strings.h"
#include "ui/base/webui/web_ui_util.h"

Expand Down
2 changes: 1 addition & 1 deletion components/brave_wallet/browser/brave_wallet_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "base/strings/string_util.h"
#include "base/values.h"
#include "brave/components/brave_wallet/browser/blockchain_registry.h"
#include "brave/components/brave_wallet/browser/brave_wallet_constants.h"
#include "brave/components/brave_wallet/browser/brave_wallet_prefs.h"
#include "brave/components/brave_wallet/browser/brave_wallet_utils.h"
#include "brave/components/brave_wallet/browser/eth_allowance_manager.h"
Expand All @@ -22,7 +23,6 @@
#include "brave/components/brave_wallet/browser/pref_names.h"
#include "brave/components/brave_wallet/browser/tx_service.h"
#include "brave/components/brave_wallet/common/brave_wallet.mojom.h"
#include "brave/components/brave_wallet/common/brave_wallet_constants.h"
#include "brave/components/brave_wallet/common/brave_wallet_response_helpers.h"
#include "brave/components/brave_wallet/common/brave_wallet_types.h"
#include "brave/components/brave_wallet/common/common_utils.h"
Expand Down
2 changes: 1 addition & 1 deletion components/brave_wallet/browser/eth_allowance_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include <algorithm>
#include <utility>

#include "base/no_destructor.h"
#include "brave/components/brave_wallet/browser/blockchain_registry.h"
#include "brave/components/brave_wallet/browser/brave_wallet_utils.h"
#include "brave/components/brave_wallet/browser/json_rpc_service.h"
#include "brave/components/brave_wallet/browser/keyring_service.h"
#include "brave/components/brave_wallet/browser/pref_names.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "brave/components/brave_wallet/browser/brave_wallet_prefs.h"
#include "brave/components/brave_wallet/browser/json_rpc_service.h"
#include "brave/components/brave_wallet/common/hex_utils.h"
#include "components/grit/brave_components_strings.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "services/data_decoder/public/cpp/test_support/in_process_data_decoder.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
Expand Down
Loading