Skip to content

Commit

Permalink
Handle Brave Payment import failures properly
Browse files Browse the repository at this point in the history
- if session-store-1 and ledger-state.json are missing, skip import
- if rewards is disabled, skip import
- if passphrase or other key fields are missing, skip import

In each of these cases, an error is still logged (to console). But it won't hang the import anymore.

Fixes brave/brave-browser#2337
  • Loading branch information
bsclifton committed Dec 3, 2018
1 parent 4e47a49 commit ae3da74
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
38 changes: 24 additions & 14 deletions utility/importer/brave_importer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,13 @@ void BraveImporter::StartImport(const importer::SourceProfile& source_profile,
}

if ((items & importer::LEDGER) && !cancelled()) {
bridge_->NotifyItemStarted(importer::LEDGER);
// NOTE: RecoverWallet is async.
// Its handler will call NotifyItemEnded/NotifyEnded
ImportLedger();
return;
// `ImportLedger` returns true if "importable"
if (ImportLedger()) {
// NOTE: RecoverWallet is async.
// Its handler will call NotifyItemEnded/NotifyEnded
bridge_->NotifyItemStarted(importer::LEDGER);
return;
}
}

bridge_->NotifyEnded();
Expand Down Expand Up @@ -585,40 +587,48 @@ bool ParsePinnedSites(BraveLedger& ledger,
return true;
}

void BraveImporter::ImportLedger() {
bool BraveImporter::ImportLedger() {
std::unique_ptr<base::Value> session_store_json = ParseBraveStateFile(
"session-store-1");
std::unique_ptr<base::Value> ledger_state_json = ParseBraveStateFile(
"ledger-state.json");
if (!(session_store_json && ledger_state_json))
return;
if (!(session_store_json && ledger_state_json)) {
return false;
}

BraveLedger ledger;

if (!ParsePaymentsPreferences(ledger, *session_store_json)) {
LOG(ERROR) << "Failed to parse preferences for Brave Payments";
return false;
}

// It should be considered fatal if an error occurs while
// parsing any of the below expected fields. This could
// indicate a corrupt session-store-1
if (!ParseWalletPassphrase(ledger, *session_store_json)) {
LOG(ERROR) << "Failed to parse wallet passphrase";
return;
return false;
}

if (!ParsePaymentsPreferences(ledger, *session_store_json)) {
LOG(ERROR) << "Failed to parse preferences for Brave Payments";
return;
if (!ledger.settings.payments.enabled) {
LOG(INFO) << "Skipping `Brave Payments` import (feature was disabled)";
return false;
}

// only do the import if Brave Payments is enabled
if (!ParseExcludedSites(ledger, *session_store_json)) {
LOG(ERROR) << "Failed to parse list of excluded sites for Brave Payments";
return;
return false;
}

if (!ParsePinnedSites(ledger, *session_store_json)) {
LOG(ERROR) << "Failed to parse list of pinned sites for Brave Payments";
return;
return false;
}

bridge_->UpdateLedger(ledger);
return true;
}

void BraveImporter::ImportReferral() {
Expand Down
2 changes: 1 addition & 1 deletion utility/importer/brave_importer.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class BraveImporter : public ChromeImporter {
void ImportBookmarks() override;
void ImportHistory() override;
void ImportStats();
void ImportLedger();
bool ImportLedger();
void ImportWindows();
void ImportReferral();

Expand Down

0 comments on commit ae3da74

Please sign in to comment.