Skip to content

Commit

Permalink
move GetUpdateHostUrl out of brave_component
Browse files Browse the repository at this point in the history
  • Loading branch information
jumde committed Sep 14, 2021
1 parent a0bcf22 commit 61fcb3c
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 69 deletions.
16 changes: 14 additions & 2 deletions app/brave_main_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
#include "brave/browser/brave_content_browser_client.h"
#include "brave/common/brave_switches.h"
#include "brave/common/resource_bundle_helper.h"
#include "brave/components/brave_component_updater/browser/brave_component.h"
#include "brave/components/brave_component_updater/browser/features.h"
#include "brave/components/brave_component_updater/browser/switches.h"
#include "brave/components/speedreader/buildflags.h"
#include "brave/renderer/brave_content_renderer_client.h"
#include "brave/utility/brave_content_utility_client.h"
Expand Down Expand Up @@ -87,6 +88,17 @@ const char kBraveOriginTrialsPublicKey[] =

const char kDummyUrl[] = "https://no-thanks.invalid";

std::string GetUpdateURLHost() {
const base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess();
if (!command_line.HasSwitch(brave_component_updater::kUseGoUpdateDev) &&
!base::FeatureList::IsEnabled(
brave_component_updater::kUseDevUpdaterUrl)) {
return UPDATER_PROD_ENDPOINT;
}
return UPDATER_DEV_ENDPOINT;
}

BraveMainDelegate::BraveMainDelegate() : ChromeMainDelegate() {}

BraveMainDelegate::BraveMainDelegate(base::TimeTicks exe_entry_point_ticks)
Expand Down Expand Up @@ -166,7 +178,7 @@ bool BraveMainDelegate::BasicStartupComplete(int* exit_code) {
command_line.AppendSwitch(switches::kEnableDomDistiller);
command_line.AppendSwitch(switches::kNoPings);

auto update_url = brave_component_updater::GetUpdateURLHost();
auto update_url = GetUpdateURLHost();
if (!update_url.empty()) {
std::string source = "url-source=" + update_url;
command_line.AppendSwitchASCII(switches::kComponentUpdater, source.c_str());
Expand Down
6 changes: 6 additions & 0 deletions build/features.gni
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ declare_args() {
updater_prod_endpoint = ""
}

if (is_official_build) {
assert(brave_services_key != "")
assert(updater_dev_endpoint != "")
assert(updater_prod_endpoint != "")
}

brave_service_key_defines = []
if (brave_services_key != "") {
brave_service_key_defines += [ "BRAVE_SERVICES_KEY=\"$brave_services_key\"" ]
Expand Down
59 changes: 59 additions & 0 deletions chromium_src/chrome/common/extensions/chrome_extensions_client.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright (c) 2021 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 "chrome/common/extensions/chrome_extensions_client.h"

#include "base/command_line.h"
#include "base/strings/string_split.h"
#include "components/component_updater/component_updater_switches.h"

#define ChromeExtensionsClient ChromeExtensionsClient_ChromiumImpl
#include "../../../../../chrome/common/extensions/chrome_extensions_client.cc"
#undef ChromeExtensionsClient

namespace extensions {

namespace {

std::string ParseUpdateUrlHost(std::string options) {
std::vector<std::string> flags = base::SplitString(
options, ",", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY);

for (const auto& flag : flags) {
if (flag.empty()) {
continue;
}

std::vector<std::string> values = base::SplitString(
flag, "=", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY);

if (values.size() != 2) {
continue;
}

std::string name = base::ToLowerASCII(values[0]);
std::string value = values[1];

if (name == "url-source") {
return value;
}
}

return "";
}

} // namespace

void ChromeExtensionsClient::InitializeWebStoreUpdateURL() {
auto* command_line = base::CommandLine::ForCurrentProcess();
webstore_update_url_ = GURL(ParseUpdateUrlHost(
command_line->GetSwitchValueASCII(switches::kComponentUpdater)));
}

const GURL& ChromeExtensionsClient::GetWebstoreUpdateURL() const {
return webstore_update_url_;
}

} // namespace extensions
30 changes: 30 additions & 0 deletions chromium_src/chrome/common/extensions/chrome_extensions_client.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) 2021 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 BRAVE_CHROMIUM_SRC_CHROME_COMMON_EXTENSIONS_CHROME_EXTENSIONS_CLIENT_H_
#define BRAVE_CHROMIUM_SRC_CHROME_COMMON_EXTENSIONS_CHROME_EXTENSIONS_CLIENT_H_

#define ChromeExtensionsClient ChromeExtensionsClient_ChromiumImpl
#include "../../../../../chrome/common/extensions/chrome_extensions_client.h"
#undef ChromeExtensionsClient

namespace extensions {

class ChromeExtensionsClient : public ChromeExtensionsClient_ChromiumImpl {
public:
using ChromeExtensionsClient_ChromiumImpl::
ChromeExtensionsClient_ChromiumImpl;

void InitializeWebStoreUpdateURL();
const GURL& GetWebstoreUpdateURL() const override;

private:
GURL webstore_update_url_;
DISALLOW_COPY_AND_ASSIGN(ChromeExtensionsClient);
};

} // namespace extensions

#endif // BRAVE_CHROMIUM_SRC_CHROME_COMMON_EXTENSIONS_CHROME_EXTENSIONS_CLIENT_H_
20 changes: 0 additions & 20 deletions chromium_src/extensions/common/extension_urls.cc

This file was deleted.

14 changes: 0 additions & 14 deletions components/brave_component_updater/browser/brave_component.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,11 @@
#include <utility>

#include "base/bind.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "base/sequenced_task_runner.h"
#include "brave/components/brave_component_updater/browser/features.h"
#include "brave/components/brave_component_updater/browser/switches.h"

namespace brave_component_updater {

std::string GetUpdateURLHost() {
const base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess();
if (!command_line.HasSwitch(brave_component_updater::kUseGoUpdateDev) &&
!base::FeatureList::IsEnabled(
brave_component_updater::kUseDevUpdaterUrl)) {
return UPDATER_PROD_ENDPOINT;
}
return UPDATER_DEV_ENDPOINT;
}

BraveComponent::BraveComponent(Delegate* delegate)
: delegate_(delegate),
weak_factory_(this) {}
Expand Down
2 changes: 0 additions & 2 deletions components/brave_component_updater/browser/brave_component.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ class PrefService;

namespace brave_component_updater {

std::string GetUpdateURLHost();

class BraveComponent {
public:
using ReadyCallback = base::RepeatingCallback<void(const base::FilePath&,
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ test("brave_unit_tests") {
"//brave/chromium_src/services/network/public/cpp/cors/cors_unittest.cc",
"//brave/common/brave_content_client_unittest.cc",
"//brave/components/assist_ranker/ranker_model_loader_impl_unittest.cc",
"//brave/components/brave_component_updater/browser/brave_component_unittest.cc",
"//brave/components/brave_perf_predictor/browser/bandwidth_linreg_unittest.cc",
"//brave/components/brave_perf_predictor/browser/bandwidth_savings_predictor_unittest.cc",
"//brave/components/brave_perf_predictor/browser/named_third_party_registry_unittest.cc",
Expand Down

0 comments on commit 61fcb3c

Please sign in to comment.