Skip to content

Commit

Permalink
Disable logs
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Aug 18, 2020
1 parent f0f1ba2 commit db71ef7
Show file tree
Hide file tree
Showing 18 changed files with 162 additions and 3 deletions.
36 changes: 35 additions & 1 deletion components/brave_rewards/browser/rewards_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2323,7 +2323,7 @@ void RewardsServiceImpl::DiagnosticLog(
const int line,
const int verbose_level,
const std::string& message) {
if (ledger_for_testing_) {
if (ledger_for_testing_ || !should_persist_logs_) {
return;
}

Expand Down Expand Up @@ -2571,6 +2571,16 @@ void RewardsServiceImpl::HandleFlags(const std::string& options) {

continue;
}

if (name == "persist-logs") {
const std::string lower = base::ToLowerASCII(value);

if (lower == "true" || lower == "1") {
should_persist_logs_ = true;
} else {
should_persist_logs_ = false;
}
}
}
}

Expand Down Expand Up @@ -3773,4 +3783,28 @@ void RewardsServiceImpl::WalletDisconnected(const std::string& wallet_type) {
OnDisconnectWallet(wallet_type, ledger::Result::LEDGER_OK);
}

void RewardsServiceImpl::DeleteLog(ledger::ResultCallback callback) {
diagnostic_log_.Close();
base::PostTaskAndReplyWithResult(
file_task_runner_.get(),
FROM_HERE,
base::BindOnce(
&RewardsServiceImpl::DeleteLogTaskRunner,
base::Unretained(this)),
base::BindOnce(
&RewardsServiceImpl::OnDeleteLog,
AsWeakPtr(),
std::move(callback)));
}

bool RewardsServiceImpl::DeleteLogTaskRunner() {
return base::DeleteFile(diagnostic_log_path_);
}

void RewardsServiceImpl::OnDeleteLog(
ledger::ResultCallback callback,
const bool success) {
callback(success ? ledger::Result::LEDGER_OK : ledger::Result::LEDGER_ERROR);
}

} // namespace brave_rewards
7 changes: 7 additions & 0 deletions components/brave_rewards/browser/rewards_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,8 @@ class RewardsServiceImpl : public RewardsService,

void WalletDisconnected(const std::string& wallet_type) override;

void DeleteLog(ledger::ResultCallback callback) override;

// end ledger::LedgerClient

// Mojo Proxy methods
Expand Down Expand Up @@ -702,6 +704,10 @@ class RewardsServiceImpl : public RewardsService,

void OnCompleteReset(SuccessCallback callback, const bool success);

bool DeleteLogTaskRunner();

void OnDeleteLog(ledger::ResultCallback callback, const bool success);

#if defined(OS_ANDROID)
ledger::Environment GetServerEnvironmentForAndroid();
void CreateWalletAttestationResult(
Expand Down Expand Up @@ -748,6 +754,7 @@ class RewardsServiceImpl : public RewardsService,
bool is_wallet_initialized_ = false;
bool ledger_for_testing_ = false;
bool resetting_rewards_ = false;
bool should_persist_logs_ = false;

GetTestResponseCallback test_response_callback_;

Expand Down
12 changes: 12 additions & 0 deletions components/services/bat_ledger/bat_ledger_client_mojo_bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -392,4 +392,16 @@ void BatLedgerClientMojoBridge::WalletDisconnected(
bat_ledger_client_->WalletDisconnected(wallet_type);
}

void OnDeleteLog(
const ledger::ResultCallback callback,
const ledger::Result result) {
callback(result);
}

void BatLedgerClientMojoBridge::DeleteLog(
ledger::ResultCallback callback) {
bat_ledger_client_->DeleteLog(
base::BindOnce(&OnDeleteLog, std::move(callback)));
}

} // namespace bat_ledger
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ class BatLedgerClientMojoBridge :

void WalletDisconnected(const std::string& wallet_type) override;

void DeleteLog(ledger::ResultCallback callback) override;

private:
bool Connected() const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,4 +385,25 @@ void LedgerClientMojoBridge::WalletDisconnected(
ledger_client_->WalletDisconnected(wallet_type);
}

// static
void LedgerClientMojoBridge::OnDeleteLog(
CallbackHolder<DeleteLogCallback>* holder,
const ledger::Result result) {
DCHECK(holder);
if (holder->is_valid()) {
std::move(holder->get()).Run(result);
}
delete holder;
}

void LedgerClientMojoBridge::DeleteLog(DeleteLogCallback callback) {
auto* holder = new CallbackHolder<DeleteLogCallback>(
AsWeakPtr(),
std::move(callback));
ledger_client_->DeleteLog(
std::bind(LedgerClientMojoBridge::OnDeleteLog,
holder,
_1));
}

} // namespace bat_ledger
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ class LedgerClientMojoBridge :

void WalletDisconnected(const std::string& wallet_type) override;

void DeleteLog(DeleteLogCallback callback) override;

private:
// workaround to pass base::OnceCallback into std::bind
template <typename Callback>
Expand Down Expand Up @@ -199,6 +201,10 @@ class LedgerClientMojoBridge :
const std::string& script,
const int table_version);

static void OnDeleteLog(
CallbackHolder<DeleteLogCallback>* holder,
const ledger::Result result);

ledger::LedgerClient* ledger_client_;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,6 @@ interface BatLedgerClient {
ClearAllNotifications();

WalletDisconnected(string wallet_type);

DeleteLog() => (ledger.mojom.Result result);
};
2 changes: 2 additions & 0 deletions vendor/bat-native-ledger/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,8 @@ source_set("ledger") {
"src/bat/ledger/internal/state/state_migration_v2.h",
"src/bat/ledger/internal/state/state_migration_v3.cc",
"src/bat/ledger/internal/state/state_migration_v3.h",
"src/bat/ledger/internal/state/state_migration_v4.cc",
"src/bat/ledger/internal/state/state_migration_v4.h",
"src/bat/ledger/internal/legacy/client_state.cc",
"src/bat/ledger/internal/legacy/client_state.h",
"src/bat/ledger/internal/legacy/publisher_settings_state.cc",
Expand Down
2 changes: 2 additions & 0 deletions vendor/bat-native-ledger/include/bat/ledger/ledger_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ class LEDGER_EXPORT LedgerClient {
virtual void ClearAllNotifications() = 0;

virtual void WalletDisconnected(const std::string& wallet_type) = 0;

virtual void DeleteLog(ledger::ResultCallback callback) = 0;
};

} // namespace ledger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ class MockLedgerClient : public LedgerClient {
MOCK_METHOD0(ClearAllNotifications, void());

MOCK_METHOD1(WalletDisconnected, void(const std::string& wallet_type));

MOCK_METHOD1(DeleteLog, void(const ledger::ResultCallback callback));
};

} // namespace ledger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ using std::placeholders::_1;

namespace {

const int kCurrentVersionNumber = 3;
const int kCurrentVersionNumber = 4;

} // namespace

Expand All @@ -22,8 +22,9 @@ StateMigration::StateMigration(bat_ledger::LedgerImpl* ledger) :
v1_(std::make_unique<StateMigrationV1>(ledger)),
v2_(std::make_unique<StateMigrationV2>(ledger)),
v3_(std::make_unique<StateMigrationV3>()),
v4_(std::make_unique<StateMigrationV4>(ledger)),
ledger_(ledger) {
DCHECK(v1_ && v2_ && v3_);
DCHECK(v1_ && v2_ && v3_ && v4_);
}

StateMigration::~StateMigration() = default;
Expand Down Expand Up @@ -56,6 +57,10 @@ void StateMigration::Migrate(ledger::ResultCallback callback) {
v3_->Migrate(migrate_callback);
return;
}
case 4: {
v4_->Migrate(migrate_callback);
return;
}
}

BLOG(0, "Migration version is not handled " << new_version);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "bat/ledger/internal/state/state_migration_v1.h"
#include "bat/ledger/internal/state/state_migration_v2.h"
#include "bat/ledger/internal/state/state_migration_v3.h"
#include "bat/ledger/internal/state/state_migration_v4.h"
#include "bat/ledger/ledger.h"

namespace bat_ledger {
Expand All @@ -36,6 +37,7 @@ class StateMigration {
std::unique_ptr<StateMigrationV1> v1_;
std::unique_ptr<StateMigrationV2> v2_;
std::unique_ptr<StateMigrationV3> v3_;
std::unique_ptr<StateMigrationV4> v4_;
bat_ledger::LedgerImpl* ledger_; // NOT OWNED
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* Copyright (c) 2020 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 http://mozilla.org/MPL/2.0/. */
#include "bat/ledger/internal/state/state_migration_v4.h"

#include "bat/ledger/internal/ledger_impl.h"

namespace braveledger_state {

StateMigrationV4::StateMigrationV4(bat_ledger::LedgerImpl* ledger) :
ledger_(ledger) {
DCHECK(ledger_);
}

StateMigrationV4::~StateMigrationV4() = default;

void StateMigrationV4::Migrate(ledger::ResultCallback callback) {
ledger_->ledger_client()->DeleteLog(callback);
}

} // namespace braveledger_state
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* Copyright (c) 2020 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 http://mozilla.org/MPL/2.0/. */

#ifndef BRAVELEDGER_BAT_STATE_STATE_MIGRATION_V4_H_
#define BRAVELEDGER_BAT_STATE_STATE_MIGRATION_V4_H_

#include "bat/ledger/ledger.h"

namespace bat_ledger {
class LedgerImpl;
}

namespace braveledger_state {

class StateMigrationV4 {
public:
explicit StateMigrationV4(bat_ledger::LedgerImpl* ledger);
~StateMigrationV4();

void Migrate(ledger::ResultCallback callback);

private:
bat_ledger::LedgerImpl* ledger_; // NOT OWNED
};

} // namespace braveledger_state

#endif // BRAVELEDGER_BAT_STATE_STATE_MIGRATION_V4_H_
5 changes: 5 additions & 0 deletions vendor/brave-ios/Ledger/BATBraveLedger.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1921,4 +1921,9 @@ - (void)walletDisconnected:(const std::string &)wallet_type
}
}

- (void)deleteLog:(ledger::ResultCallback)callback
{
// TODO implement
}

@end
1 change: 1 addition & 0 deletions vendor/brave-ios/Ledger/Generated/NativeLedgerClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,5 @@ class NativeLedgerClient : public ledger::LedgerClient {
void PendingContributionSaved(const ledger::Result result) override;
void ClearAllNotifications() override;
void WalletDisconnected(const std::string& wallet_type) override;
void DeleteLog(ledger::ResultCallback callback) override;
};
3 changes: 3 additions & 0 deletions vendor/brave-ios/Ledger/Generated/NativeLedgerClient.mm
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,6 @@
void NativeLedgerClient::WalletDisconnected(const std::string& wallet_type) {
[bridge_ walletDisconnected:wallet_type];
}
void NativeLedgerClient::DeleteLog(ledger::ResultCallback callback) {
[bridge_ deleteLog:callback];
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@
- (void)pendingContributionSaved:(const ledger::Result)result;
- (void)clearAllNotifications;
- (void)walletDisconnected:(const std::string&)wallet_type;
- (void)deleteLog:(ledger::ResultCallback)callback;

@end

0 comments on commit db71ef7

Please sign in to comment.