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

Disable logs (uplift to 1.13.x) #6441

Merged
merged 1 commit into from
Aug 19, 2020
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
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 @@ -2497,7 +2497,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 @@ -2745,6 +2745,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 @@ -3966,4 +3976,28 @@ void RewardsServiceImpl::OnCompleteReset(
std::move(callback).Run(true);
}

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 @@ -658,6 +658,8 @@ class RewardsServiceImpl : public RewardsService,

void ClearAllNotifications() override;

void DeleteLog(ledger::ResultCallback callback) override;

// end ledger::LedgerClient

// Mojo Proxy methods
Expand Down Expand Up @@ -729,6 +731,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 @@ -777,6 +783,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 @@ -470,4 +470,16 @@ void BatLedgerClientMojoBridge::ClearAllNotifications() {
bat_ledger_client_->ClearAllNotifications();
}

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 @@ -146,6 +146,8 @@ class BatLedgerClientMojoBridge :

void ClearAllNotifications() 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 @@ -467,4 +467,25 @@ void LedgerClientMojoBridge::ClearAllNotifications() {
ledger_client_->ClearAllNotifications();
}

// 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 @@ -161,6 +161,8 @@ class LedgerClientMojoBridge :

void ClearAllNotifications() override;

void DeleteLog(DeleteLogCallback callback) override;

private:
// workaround to pass base::OnceCallback into std::bind
template <typename Callback>
Expand Down Expand Up @@ -224,6 +226,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 @@ -252,4 +252,6 @@ interface BatLedgerClient {
Log(string file, int32 line, int32 verbose_level, string message);

ClearAllNotifications();

DeleteLog() => (ledger.mojom.Result result);
};
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ class ConfirmationsClientMock : public ConfirmationsClient {
MOCK_METHOD1(PendingContributionSaved, void(const ledger::Result result));

MOCK_METHOD0(ClearAllNotifications, void());

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

} // namespace confirmations
Expand Down
2 changes: 2 additions & 0 deletions vendor/bat-native-ledger/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,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/state/state_util.cc",
"src/bat/ledger/internal/state/state_util.h",
"src/bat/ledger/internal/legacy/client_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 @@ -187,6 +187,8 @@ class LEDGER_EXPORT LedgerClient {
virtual void PendingContributionSaved(const ledger::Result result) = 0;

virtual void ClearAllNotifications() = 0;

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

} // namespace ledger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ class MockLedgerClient : public LedgerClient {
MOCK_METHOD1(PendingContributionSaved, void(const ledger::Result result));

MOCK_METHOD0(ClearAllNotifications, void());

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

} // namespace ledger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1755,4 +1755,8 @@ void LedgerImpl::GetCredsBatchesByTriggers(
bat_database_->GetCredsBatchesByTriggers(trigger_ids, callback);
}

void LedgerImpl::DeleteLog(ledger::ResultCallback callback) {
ledger_client_->DeleteLog(callback);
}

} // namespace bat_ledger
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,8 @@ class LedgerImpl : public ledger::Ledger {
const std::vector<std::string>& trigger_ids,
ledger::GetCredsBatchListCallback callback);

void DeleteLog(ledger::ResultCallback callback);

private:
void OnInitialized(
const ledger::Result result,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ using std::placeholders::_1;

namespace {

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

} // namespace

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

StateMigration::~StateMigration() = default;
Expand Down Expand Up @@ -57,6 +58,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_->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 @@ -1987,4 +1987,9 @@ - (void)pendingContributionSaved:(const ledger::Result)result
}
}

- (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 @@ -64,4 +64,5 @@ class NativeLedgerClient : public ledger::LedgerClient {
void GetCreateScript(ledger::GetCreateScriptCallback callback) override;
void PendingContributionSaved(const ledger::Result result) override;
void ClearAllNotifications() 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 @@ -158,3 +158,6 @@
void NativeLedgerClient::ClearAllNotifications() {
[bridge_ clearAllNotifications];
}
void NativeLedgerClient::DeleteLog(ledger::ResultCallback callback) {
[bridge_ deleteLog:callback];
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,6 @@
- (void)getCreateScript:(ledger::GetCreateScriptCallback)callback;
- (void)pendingContributionSaved:(const ledger::Result)result;
- (void)clearAllNotifications;
- (void)deleteLog:(ledger::ResultCallback)callback;

@end