|
5 | 5 |
|
6 | 6 | #include "brave/components/brave_rewards/browser/rewards_service_impl.h"
|
7 | 7 |
|
| 8 | +#include <stdint.h> |
| 9 | + |
8 | 10 | #include <algorithm>
|
9 | 11 | #include <functional>
|
10 | 12 | #include <limits>
|
|
55 | 57 | #include "chrome/browser/browser_process_impl.h"
|
56 | 58 | #include "chrome/browser/favicon/favicon_service_factory.h"
|
57 | 59 | #include "chrome/browser/profiles/profile.h"
|
| 60 | +#include "components/country_codes/country_codes.h" |
58 | 61 | #include "components/favicon/core/favicon_service.h"
|
59 | 62 | #include "components/favicon_base/favicon_types.h"
|
60 | 63 | #include "components/prefs/pref_service.h"
|
@@ -1528,8 +1531,35 @@ void RewardsServiceImpl::GetAddresses(const GetAddressesCallback& callback) {
|
1528 | 1531 | return;
|
1529 | 1532 | }
|
1530 | 1533 |
|
1531 |
| - bat_ledger_->GetAddresses(base::BindOnce(&RewardsServiceImpl::OnGetAddresses, |
1532 |
| - AsWeakPtr(), callback)); |
| 1534 | + bat_ledger_->GetAddressesLimitedCountries( |
| 1535 | + base::BindOnce(&RewardsServiceImpl::OnGetAddressesLimitedCountries, |
| 1536 | + AsWeakPtr(), callback)); |
| 1537 | +} |
| 1538 | + |
| 1539 | +void RewardsServiceImpl::OnGetAddressesLimitedCountries( |
| 1540 | + const GetAddressesCallback& callback, |
| 1541 | + const std::vector<std::string>& country_chars) { |
| 1542 | + int32_t current_code = country_codes::GetCountryIDFromPrefs( |
| 1543 | + profile_->GetPrefs()); |
| 1544 | + if (!current_country_for_test_.empty()) { |
| 1545 | + current_code = country_codes::CountryCharsToCountryID( |
| 1546 | + current_country_for_test_.at(0), current_country_for_test_.at(1)); |
| 1547 | + } |
| 1548 | + |
| 1549 | + |
| 1550 | + for (const std::string& country_code : country_chars) { |
| 1551 | + if (country_code.size() == 2 && |
| 1552 | + current_code == country_codes::CountryCharsToCountryID( |
| 1553 | + country_code.at(0), country_code.at(1))) { |
| 1554 | + bat_ledger_->GetAddresses(true, |
| 1555 | + base::BindOnce(&RewardsServiceImpl::OnGetAddresses, |
| 1556 | + AsWeakPtr(), callback)); |
| 1557 | + return; |
| 1558 | + } |
| 1559 | + } |
| 1560 | + bat_ledger_->GetAddresses(false, |
| 1561 | + base::BindOnce(&RewardsServiceImpl::OnGetAddresses, |
| 1562 | + AsWeakPtr(), callback)); |
1533 | 1563 | }
|
1534 | 1564 |
|
1535 | 1565 | void RewardsServiceImpl::SetRewardsMainEnabled(bool enabled) {
|
@@ -2592,6 +2622,13 @@ void RewardsServiceImpl::HandleFlags(const std::string& options) {
|
2592 | 2622 |
|
2593 | 2623 | SetShortRetries(short_retries);
|
2594 | 2624 | }
|
| 2625 | + |
| 2626 | + if (name == "current-country") { |
| 2627 | + const std::string& current_country_(base::ToUpperASCII(value)); |
| 2628 | + if (!current_country_.empty() && current_country_.size() == 2) { |
| 2629 | + SetCurrentCountry(current_country_); |
| 2630 | + } |
| 2631 | + } |
2595 | 2632 | }
|
2596 | 2633 | }
|
2597 | 2634 |
|
@@ -2701,6 +2738,11 @@ void RewardsServiceImpl::SetShortRetries(bool short_retries) {
|
2701 | 2738 | bat_ledger_service_->SetShortRetries(short_retries);
|
2702 | 2739 | }
|
2703 | 2740 |
|
| 2741 | +void RewardsServiceImpl::SetCurrentCountry( |
| 2742 | + const std::string& current_country_) { |
| 2743 | + current_country_for_test_ = current_country_; |
| 2744 | +} |
| 2745 | + |
2704 | 2746 | ledger::Result SavePendingContributionOnFileTaskRunner(
|
2705 | 2747 | PublisherInfoDatabase* backend,
|
2706 | 2748 | const ledger::PendingContributionList& list) {
|
|
0 commit comments