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

Confirmations implementation #1469

Closed
wants to merge 41 commits into from
Closed

Confirmations implementation #1469

wants to merge 41 commits into from

Conversation

tmancey
Copy link
Collaborator

@tmancey tmancey commented Jan 26, 2019

fixes brave/brave-browser#3117

Submitter Checklist:

  • Submitted a ticket for my issue if one did not already exist.
  • Used Github auto-closing keywords in the commit message.
  • Added/updated tests for this change (for new code or code which already has tests).
  • Verified that these changes build without errors on
    • Windows
    • macOS
    • Linux
  • Verified that these changes pass automated tests (npm test brave_unit_tests && npm test brave_browser_tests) on
    • Windows
    • macOS
    • Linux
  • Ran git rebase master (if needed).
  • Ran git rebase -i to squash commits (if needed).
  • Tagged reviewers and labelled the pull request as needed.
  • Request a security/privacy review as needed.
  • Add appropriate QA labels (QA/Yes or QA/No) to include the closed issue in milestone

Test Plan:

Reviewer Checklist:

  • New files have MPL-2.0 license header.
  • Request a security/privacy review as needed.
  • Adequate test coverage exists to prevent regressions
  • Verify test plan is specified in PR before merging to source

vendor/bat-native-ledger/src/ledger_impl.cc Outdated Show resolved Hide resolved
@@ -1218,7 +1218,7 @@ void RewardsServiceImpl::OnURLFetchComplete(
return;
}

callback(response_code == 200, body, headers);
callback(response_code, body, headers);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nejc Would be good if you could verify that this commit was done correctly, as far as Rewards is concerned.

@@ -578,18 +580,18 @@ void AdsServiceImpl::ShowNotification(std::unique_ptr<ads::NotificationInfo> inf
}

void AdsServiceImpl::SetCatalogIssuers(std::unique_ptr<ads::IssuersInfo> info) {
// TODO(Terry Mancey): https://github.com/brave/brave-browser/issues/2906
(void)info;
rewards_service_->SetCatalogIssuers(std::move(info));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this return early if (!connected())? I see other methods in here doing that...

Copy link
Collaborator Author

@tmancey tmancey Jan 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch 👍, ideally we should be checking bounds for the rewards service however the lifetime of the rewards service outlasts Ads

ledger::URL_METHOD method,
ledger::URLRequestCallback callback) {
if (!Connected()) {
callback(418, "", std::map<std::string, std::string>());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This HTTP response seems random (I copied it from similar functionality in bat_ledger). Should it just be a generic 400 (and preferably some kind of constant - Chromium probably has definitions for these).

Copy link
Collaborator Author

@tmancey tmancey Jan 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was chosen as an unlikely response that we would get in the real world so that we knew the service had failed. @bridiver your thoughts please? If we do want to use a constant they are available in src/net/http/http_status_code_list.h

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this shouldn't be here at all. The mojo proxy shouldn't have any logic in it

@tmancey tmancey force-pushed the issues/2912-0.62.x branch 2 times, most recently from ec86ca4 to 2cc4133 Compare January 27, 2019 10:45
@tmancey tmancey changed the title Confirmations implementation Confirmations implementation 0.62.x Jan 28, 2019
@tmancey tmancey force-pushed the issues/2912-0.62.x branch 3 times, most recently from 6141c86 to e7301ed Compare January 29, 2019 15:09
@ryanml ryanml mentioned this pull request Jan 30, 2019
18 tasks
@tmancey tmancey force-pushed the issues/2912-0.62.x branch 2 times, most recently from 1410050 to 193f900 Compare January 31, 2019 18:54
return;
}

auto* ads_service = brave_ads::AdsServiceFactory::GetForProfile(profile_); // NOT OWNED
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are we calling this from rewards_service if it calls ads_service?

}

void RewardsServiceImpl::SetConfirmationsIsReady(const bool is_ready) {
if (!Connected()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is only necessary when we're using the mojo interfaces

fetcher->Start();
}

void RewardsServiceImpl::SaveConfirmationsState(const std::string& name,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need individual methods for these. We just need a generic Save and Load method like AdsService which can be used by all state files

bat_ledger_->AdSustained(info->ToJson());
}

void RewardsServiceImpl::URLRequest(const std::string& url,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we adding this? We already have LoadURL

@@ -112,6 +112,36 @@ class LogStreamImpl : public ledger::LogStream {
DISALLOW_COPY_AND_ASSIGN(LogStreamImpl);
};

class ConfirmationsLogStreamImpl : public confirmations::LogStream {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need duplicates of all this stuff for Confirmations

@@ -257,6 +287,27 @@ time_t GetCurrentTimestamp() {
return base::Time::NowFromSystemTime().ToTimeT();
}

std::string LoadOnFileTaskRunner(const base::FilePath& path) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't need duplicates of this stuff either

Copy link
Collaborator

@bridiver bridiver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to go through this together because there are a lot of issues here that need to be addressed

@tmancey tmancey force-pushed the issues/2912-0.62.x branch 3 times, most recently from 011c7d7 to ca3621b Compare February 4, 2019 22:32
@@ -94,6 +94,8 @@ source_set("browser") {
}

deps += [
"//brave/vendor/bat-native-ads",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs a brave_ads_enabled guard

@@ -20,6 +20,8 @@ static_library("lib") {

deps = [
"//base",
"//brave/vendor/bat-native-ads",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here with brave_ads_enabled

#include "bat/ledger/ledger_client.h"
#include "brave/components/services/bat_ledger/public/interfaces/bat_ledger.mojom.h"
#include "brave/components/brave_rewards/browser/rewards_service.h"
#include "brave/components/brave_ads/browser/ads_service.h"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no reason for these to be here. Only add includes to the header file if they are needed for the declaration. Everything else should go in the cc file

@@ -10,14 +10,19 @@
#include <memory>
#include <string>

#include "bat/ads/issuers_info.h"
#include "bat/ads/notification_info.h"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be a forward declaration

#include "bat/ledger/ledger.h"
#include "bat/ledger/wallet_info.h"
#include "base/files/file_path.h"
#include "base/observer_list.h"
#include "base/memory/weak_ptr.h"
#include "bat/confirmations/confirmations_client.h"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't appear to be needed at all

@@ -10,14 +10,19 @@
#include <memory>
#include <string>

#include "bat/ads/issuers_info.h"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be a forward declaration

CurrentReconciles current_reconciles_;
bool auto_contribute_ = false;
bool rewards_enabled_ = false;
};

struct GRANTS_PROPERTIES_ST {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is a vector of grant responses called GRANTS_PROPERTIES_ST? Also we should stop using this all caps naming

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was following the naming conventions of the other response structs, I can update

ledger::OnLoadCallback callback) = 0;
virtual void ResetConfirmationsState(const std::string& name,
ledger::OnResetCallback callback) = 0;
virtual uint32_t SetConfirmationsTimer(const uint64_t time_offset) = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we shouldn't have duplicates of this either

ledger::OnResetCallback callback) = 0;
virtual uint32_t SetConfirmationsTimer(const uint64_t time_offset) = 0;
virtual void KillConfirmationsTimer(uint32_t timer_id) = 0;
virtual void SetConfirmationsIsReady(const bool is_ready) = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this both a Ledger and LedgerClient method? I'm very confused about what it's supposed to do

@@ -584,6 +592,20 @@ void AdsServiceImpl::ShowNotification(
timer_id, notification_id));
}

void AdsServiceImpl::SetCatalogIssuers(std::unique_ptr<ads::IssuersInfo> info) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we calling this on ads service if it calls rewards service?

const ledger::URL_METHOD method,
ledger::URLRequestCallback callback) = 0;

virtual void SaveConfirmationsState(const std::string& name,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this stuff should not be added to LedgerClient, LedgerImpl should just proxy to the LedgerClient methods for SetTimer, LoadURL, etc..

@tmancey
Copy link
Collaborator Author

tmancey commented Feb 13, 2019

Closing PR as superseded by #1645

@tmancey tmancey closed this Feb 13, 2019
@tmancey tmancey deleted the issues/2912-0.62.x branch February 21, 2019 20:03
@tmancey tmancey removed this from the 0.62.x - Dev milestone Feb 27, 2019
@tmancey tmancey changed the title Confirmations implementation 0.62.x Confirmations implementation Feb 27, 2019
fmarier pushed a commit that referenced this pull request Oct 29, 2019
Add options for installer signing key on Mac
petemill pushed a commit that referenced this pull request Jul 27, 2020
Add options for installer signing key on Mac
petemill pushed a commit that referenced this pull request Jul 28, 2020
Add options for installer signing key on Mac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Confirmations implementation
4 participants