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

Brave Vpn api integration #9131

Merged
merged 14 commits into from
Jul 7, 2021
Merged

Brave Vpn api integration #9131

merged 14 commits into from
Jul 7, 2021

Conversation

deeppandya
Copy link
Contributor

Resolves brave/brave-browser#14048

Submitter Checklist:

  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally: npm run test -- brave_browser_tests, npm run test -- brave_unit_tests, npm run lint, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)
  • Requested a security/privacy review as needed

Reviewer Checklist:

  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

components/brave_vpn/BUILD.gn Outdated Show resolved Hide resolved
components/brave_vpn/brave_vpn_service.h Outdated Show resolved Hide resolved
@@ -329,6 +330,7 @@ brave_chrome_browser_defines = []

brave_chrome_browser_sources += brave_browser_autocomplete_sources
brave_chrome_browser_sources += brave_browser_binance_sources
brave_chrome_browser_sources += brave_browser_brave_vpn_sources
Copy link
Member

@simonhong simonhong Jun 15, 2021

Choose a reason for hiding this comment

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

Curious we will add all new files/deps here instead of creating our new targets even if there is no circular? @iefremov @bridiver
Sorry if both of you discussed about this and shared already :)

Copy link
Contributor

Choose a reason for hiding this comment

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

As far as I'm aware there is no consensus (at least, with myself :)), but the current approach is having source.gni only for circular dependencies on the Big Chrome

components/brave_vpn/brave_vpn_service.h Outdated Show resolved Hide resolved
components/brave_vpn/brave_vpn_service.cc Outdated Show resolved Hide resolved
components/brave_vpn/brave_vpn_service.cc Outdated Show resolved Hide resolved
components/brave_vpn/brave_vpn_service.cc Outdated Show resolved Hide resolved
components/brave_vpn/brave_vpn_service.cc Outdated Show resolved Hide resolved
components/brave_vpn/brave_vpn_service.h Outdated Show resolved Hide resolved
browser/brave_vpn/brave_vpn_service_factory.cc Outdated Show resolved Hide resolved
browser/brave_vpn/sources.gni Show resolved Hide resolved
browser/brave_vpn/android/brave_vpn_native_worker.cc Outdated Show resolved Hide resolved
@simonhong
Copy link
Member

gn_check caught below. We need to create DEPS to brave_vpn components with //services/network/public/cpp.

[2021-06-15T10:08:28.889Z] ERROR in C:\tion\src\brave\components\brave_vpn\brave_vpn_service.cc

[2021-06-15T10:08:28.889Z]   Illegal include: "services/network/public/cpp/shared_url_loader_factory.h"

[2021-06-15T10:08:28.889Z]     Because of no rule applying.

[2021-06-15T10:08:28.889Z]   Illegal include: "services/network/public/cpp/simple_url_loader.h"

[2021-06-15T10:08:28.889Z]     Because of no rule applying.

@deeppandya deeppandya requested a review from a team as a code owner June 16, 2021 18:09
json, base::JSONParserOptions::JSON_PARSE_RFC);
base::Optional<base::Value>& records_v = value_with_error.value;
const base::Value* subscriber_credential =
records_v->FindKey("subscriber-credential");
Copy link
Member

Choose a reason for hiding this comment

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

Oops, I missed one more. Need to check records_v is dictionary.
If |records_v| is not dictionary, calling FindKey on it will give DCHECK failure.

Copy link
Member

@simonhong simonhong left a comment

Choose a reason for hiding this comment

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

++ :)

const std::string& product_type);

private:
static GURL oauth_endpoint_;
Copy link
Contributor

Choose a reason for hiding this comment

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

these two are not used?

if (set_app_ident) {
request->headers.SetHeader("GRD-App-Ident", "Brave-Client");
}
auto url_loader = network::SimpleURLLoader::Create(
Copy link
Contributor

Choose a reason for hiding this comment

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

there is a new utility called BraveApiRequest that probably could be used here to reduce boilerplate


scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;
SimpleURLLoaderList url_loaders_;
base::WeakPtrFactory<BraveVpnService> weak_factory_;
Copy link
Contributor

Choose a reason for hiding this comment

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

not used

const std::unique_ptr<std::string> response_body);

void OnGetAllServerRegions(ResponseCallback callback,
const int status,
Copy link
Contributor

Choose a reason for hiding this comment

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

const is not needed for primitive arguments

@@ -0,0 +1,3 @@
include_rules = [
"+services/network/public/cpp",
Copy link
Contributor

Choose a reason for hiding this comment

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

you need more deps, e.g. components/keyed_service. base and url are not needed


bool success = status == 200;
if (success) {
json_response = body;
Copy link
Contributor

Choose a reason for hiding this comment

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

could be moved to save few clocks

Copy link
Contributor

Choose a reason for hiding this comment

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

I gather these 4 identical methods could be replaced by a single one?

brave_vpn_service_(nullptr),
weak_factory_(this) {
Java_BraveVpnNativeWorker_setNativePtr(env, obj, reinterpret_cast<intptr_t>(this));
brave_vpn_service_ = BraveVpnServiceFactory::GetForProfile(
Copy link
Contributor

Choose a reason for hiding this comment

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

AFAIU this doesn't track the service runtime? the service can die at any moment, so we'd better ensure that we don't use this pointer after this.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this wasn't fixed (or I don't understand why the current code is correct). Can you please clarify the lifetime of the worker? I.e. when it is created and when destroyed

Copy link
Contributor

Choose a reason for hiding this comment

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

So I'd like to understand whether the worker can outlive the service

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This concern has been addressed.

Copy link
Contributor

@iefremov iefremov left a comment

Choose a reason for hiding this comment

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

needs some improvements

@deeppandya deeppandya force-pushed the vpn_api_integration branch 2 times, most recently from 72c8754 to f17b955 Compare June 25, 2021 16:27
#ifndef BRAVE_COMPONENTS_BRAVE_VPN_BROWSER_BRAVE_VPN_SERVICE_H_
#define BRAVE_COMPONENTS_BRAVE_VPN_BROWSER_BRAVE_VPN_SERVICE_H_

#include <list>
Copy link
Contributor

Choose a reason for hiding this comment

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

some includes are not used now, please double-check


namespace network {
class SharedURLLoaderFactory;
class SimpleURLLoader;
Copy link
Contributor

Choose a reason for hiding this comment

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

not needed?

#include "base/bind.h"
#include "base/callback_forward.h"
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

not used

include_rules = [
"+services/network/public/cpp",
"+base",
"+components/keyed_service/core",
Copy link
Contributor

Choose a reason for hiding this comment

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

formatting


class BraveVpnService;

namespace chrome {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the code convention wants some empty lines in between

@iefremov
Copy link
Contributor

everything looks good to me except some codestyle nits and the service/worker lifetime question

@iefremov iefremov self-requested a review June 29, 2021 13:56
void BraveVpnNativeWorker::GetAllServerRegions(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& jcaller) {
BraveVpnService* brave_vpn_service = GetBraveVpnService();
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: you can do if (BraveVpnService* brave_vpn_service = GetBraveVpnService()) {

Copy link
Member

@bsclifton bsclifton left a comment

Choose a reason for hiding this comment

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

There are a few oustanding or unresolved comments; those aside, this looks great 😄

I had used this as a reference for understanding a lot of what how VPN works (ex: which steps need to happen in which order; helped a lot for Desktop planning)

@deeppandya deeppandya merged commit 94f9b4f into master Jul 7, 2021
@deeppandya deeppandya deleted the vpn_api_integration branch July 7, 2021 16:35
@bsclifton bsclifton mentioned this pull request Jul 7, 2021
24 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Android] Guardian API integration for VPN
4 participants