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

Android component updater #2484

Merged
merged 13 commits into from
May 24, 2019
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "brave/browser/brave_content_browser_client.h"
#include "brave/common/brave_paths.h"
#include "brave/common/pref_names.h"
#include "brave/components/brave_shields/browser/local_data_files_service.h"
#include "brave/components/brave_component_updater/browser/local_data_files_service.h"
#include "brave/components/brave_shields/browser/autoplay_whitelist_service.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/extensions/extension_browsertest.h"
Expand Down
38 changes: 29 additions & 9 deletions browser/brave_browser_process_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
#include "brave/browser/component_updater/brave_component_updater_delegate.h"
#include "brave/browser/extensions/brave_tor_client_updater.h"
#include "brave/browser/profiles/brave_profile_manager.h"
#include "brave/components/brave_component_updater/browser/local_data_files_service.h"
#include "brave/components/brave_shields/browser/ad_block_custom_filters_service.h"
#include "brave/components/brave_shields/browser/ad_block_regional_service_manager.h"
#include "brave/components/brave_shields/browser/ad_block_service.h"
#include "brave/components/brave_shields/browser/autoplay_whitelist_service.h"
#include "brave/components/brave_shields/browser/extension_whitelist_service.h"
#include "brave/components/brave_shields/browser/https_everywhere_service.h"
#include "brave/components/brave_shields/browser/local_data_files_service.h"
#include "brave/components/brave_shields/browser/referrer_whitelist_service.h"
#include "brave/components/brave_shields/browser/tracking_protection_service.h"
#include "chrome/browser/io_thread.h"
Expand All @@ -48,8 +48,7 @@ BraveBrowserProcessImpl* g_brave_browser_process = nullptr;

using content::BrowserThread;

BraveBrowserProcessImpl::~BraveBrowserProcessImpl() {
}
BraveBrowserProcessImpl::~BraveBrowserProcessImpl() {}

BraveBrowserProcessImpl::BraveBrowserProcessImpl(StartupData* startup_data)
: BrowserProcessImpl(startup_data) {
Expand Down Expand Up @@ -115,6 +114,23 @@ BraveBrowserProcessImpl::component_updater() {
return component_updater_.get();
}

void BraveBrowserProcessImpl::ResourceDispatcherHostCreated() {
BrowserProcessImpl::ResourceDispatcherHostCreated();
ad_block_service()->Start();
ad_block_custom_filters_service()->Start();
ad_block_regional_service_manager()->Start();
https_everywhere_service()->Start();

autoplay_whitelist_service();
#if BUILDFLAG(ENABLE_EXTENSIONS)
extension_whitelist_service();
#endif
referrer_whitelist_service();
tracking_protection_service();
// Now start the local data files service, which calls all observers.
local_data_files_service()->Start();
}

ProfileManager* BraveBrowserProcessImpl::profile_manager() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (!created_profile_manager_)
Expand Down Expand Up @@ -154,7 +170,8 @@ brave_shields::AutoplayWhitelistService*
BraveBrowserProcessImpl::autoplay_whitelist_service() {
if (!autoplay_whitelist_service_) {
autoplay_whitelist_service_ =
brave_shields::AutoplayWhitelistServiceFactory();
brave_shields::AutoplayWhitelistServiceFactory(
local_data_files_service());
}
return autoplay_whitelist_service_.get();
}
Expand All @@ -164,7 +181,8 @@ brave_shields::ExtensionWhitelistService*
BraveBrowserProcessImpl::extension_whitelist_service() {
if (!extension_whitelist_service_) {
extension_whitelist_service_ =
brave_shields::ExtensionWhitelistServiceFactory();
brave_shields::ExtensionWhitelistServiceFactory(
local_data_files_service());
}
return extension_whitelist_service_.get();
}
Expand All @@ -174,7 +192,8 @@ brave_shields::ReferrerWhitelistService*
BraveBrowserProcessImpl::referrer_whitelist_service() {
if (!referrer_whitelist_service_) {
referrer_whitelist_service_ =
brave_shields::ReferrerWhitelistServiceFactory();
brave_shields::ReferrerWhitelistServiceFactory(
local_data_files_service());
}
return referrer_whitelist_service_.get();
}
Expand All @@ -183,7 +202,8 @@ brave_shields::TrackingProtectionService*
BraveBrowserProcessImpl::tracking_protection_service() {
if (!tracking_protection_service_) {
tracking_protection_service_ =
brave_shields::TrackingProtectionServiceFactory();
brave_shields::TrackingProtectionServiceFactory(
local_data_files_service());
}
return tracking_protection_service_.get();
}
Expand All @@ -197,11 +217,11 @@ BraveBrowserProcessImpl::https_everywhere_service() {
return https_everywhere_service_.get();
}

brave_shields::LocalDataFilesService*
brave_component_updater::LocalDataFilesService*
BraveBrowserProcessImpl::local_data_files_service() {
if (!local_data_files_service_)
local_data_files_service_ =
brave_shields::LocalDataFilesServiceFactory(
brave_component_updater::LocalDataFilesServiceFactory(
brave_component_updater_delegate());
return local_data_files_service_.get();
}
Expand Down
10 changes: 7 additions & 3 deletions browser/brave_browser_process_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@ class BraveStatsUpdater;
class BraveWidevineBundleManager;
#endif

namespace brave_component_updater {
class LocalDataFilesService;
}

namespace brave_shields {
class AdBlockService;
class AdBlockCustomFiltersService;
class AdBlockRegionalServiceManager;
class AutoplayWhitelistService;
class ExtensionWhitelistService;
class HTTPSEverywhereService;
class LocalDataFilesService;
class ReferrerWhitelistService;
class TrackingProtectionService;
} // namespace brave_shields
Expand All @@ -49,6 +52,7 @@ class BraveBrowserProcessImpl : public BrowserProcessImpl {

// BrowserProcess implementation.
component_updater::ComponentUpdateService* component_updater() override;
void ResourceDispatcherHostCreated() override;

ProfileManager* profile_manager() override;

Expand All @@ -63,7 +67,7 @@ class BraveBrowserProcessImpl : public BrowserProcessImpl {
brave_shields::ReferrerWhitelistService* referrer_whitelist_service();
brave_shields::TrackingProtectionService* tracking_protection_service();
brave_shields::HTTPSEverywhereService* https_everywhere_service();
brave_shields::LocalDataFilesService* local_data_files_service();
brave_component_updater::LocalDataFilesService* local_data_files_service();
#if BUILDFLAG(ENABLE_TOR)
extensions::BraveTorClientUpdater* tor_client_updater();
#endif
Expand Down Expand Up @@ -92,7 +96,7 @@ class BraveBrowserProcessImpl : public BrowserProcessImpl {
tracking_protection_service_;
std::unique_ptr<brave_shields::HTTPSEverywhereService>
https_everywhere_service_;
std::unique_ptr<brave_shields::LocalDataFilesService>
std::unique_ptr<brave_component_updater::LocalDataFilesService>
local_data_files_service_;
std::unique_ptr<brave::BraveStatsUpdater> brave_stats_updater_;
#if BUILDFLAG(ENABLE_BRAVE_REFERRALS)
Expand Down
12 changes: 11 additions & 1 deletion browser/component_updater/brave_component_updater_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "brave/browser/component_updater/brave_component_updater_delegate.h"

#include "base/sequenced_task_runner.h"
#include "base/task/post_task.h"
#include "brave/browser/component_updater/brave_component_installer.h"
#include "chrome/browser/ui/webui/components_ui.h"
#include "chrome/browser/browser_process.h"
Expand All @@ -13,7 +15,11 @@ using brave_component_updater::BraveComponent;

namespace brave {

BraveComponentUpdaterDelegate::BraveComponentUpdaterDelegate() {
BraveComponentUpdaterDelegate::BraveComponentUpdaterDelegate()
: task_runner_(
base::CreateSequencedTaskRunnerWithTraits({base::MayBlock(),
base::TaskPriority::USER_VISIBLE,
base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN})) {
}

BraveComponentUpdaterDelegate::~BraveComponentUpdaterDelegate() {}
Expand Down Expand Up @@ -41,4 +47,8 @@ void BraveComponentUpdaterDelegate::OnDemandUpdate(
ComponentsUI::OnDemandUpdate(component_id);
}

scoped_refptr<base::SequencedTaskRunner> BraveComponentUpdaterDelegate::GetTaskRunner() {
return task_runner_;
}

} // namespace brave
7 changes: 7 additions & 0 deletions browser/component_updater/brave_component_updater_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

using brave_component_updater::BraveComponent;

namespace base {
class SequencedTaskRunner;
}

namespace brave {

class BraveComponentUpdaterDelegate : public BraveComponent::Delegate {
Expand All @@ -26,8 +30,11 @@ class BraveComponentUpdaterDelegate : public BraveComponent::Delegate {
BraveComponent::ReadyCallback ready_callback) override;
bool Unregister(const std::string& component_id) override;
void OnDemandUpdate(const std::string& component_id) override;
scoped_refptr<base::SequencedTaskRunner> GetTaskRunner() override;

private:
scoped_refptr<base::SequencedTaskRunner> task_runner_;

DISALLOW_COPY_AND_ASSIGN(BraveComponentUpdaterDelegate);
};

Expand Down
38 changes: 0 additions & 38 deletions browser/component_updater/brave_crx_update_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,44 +42,6 @@ void BraveCrxUpdateService::Start() {
base::DoNothing());
}

bool BraveCrxUpdateService::RegisterComponent(const CrxComponent& component) {
DCHECK(thread_checker_.CalledOnValidThread());
if (component.pk_hash.empty() || !component.version.IsValid() ||
!component.installer) {
return false;
}

// Update the registration data if the component has been registered before.
const std::string id(GetCrxComponentID(component));
auto it = components_.find(id);
if (it != components_.end()) {
it->second = component;
return true;
}

components_.insert(std::make_pair(id, component));
components_order_.push_back(id);
for (const auto& mime_type : component.handled_mime_types)
component_ids_by_mime_type_[mime_type] = id;

// Create an initial state for this component. The state is mutated in
// response to events from the UpdateClient instance.
CrxUpdateItem item;
item.id = id;
item.component = component;
const auto inserted = component_states_.insert(std::make_pair(id, item));
DCHECK(inserted.second);

// Start the timer if this is the first component registered. The first timer
// event occurs after an interval defined by the component update
// configurator. The subsequent timer events are repeated with a period
// defined by the same configurator.
if (components_.size() == 1)
Start();

return true;
}

bool BraveCrxUpdateService::CheckForUpdates(
UpdateScheduler::OnFinishedCallback on_finished) {
DCHECK(thread_checker_.CalledOnValidThread());
Expand Down
1 change: 0 additions & 1 deletion browser/component_updater/brave_crx_update_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class BraveCrxUpdateService : public CrxUpdateService {
std::unique_ptr<UpdateScheduler> scheduler,
scoped_refptr<UpdateClient> update_client);

bool RegisterComponent(const CrxComponent& component) override;
~BraveCrxUpdateService() override {}

private:
Expand Down
4 changes: 2 additions & 2 deletions browser/extensions/brave_extension_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#include "base/strings/utf_string_conversions.h"
#include "brave/browser/brave_browser_process_impl.h"
#include "brave/common/extensions/extension_constants.h"
#include "brave/components/brave_component_updater/browser/local_data_files_service.h"
#include "brave/components/brave_shields/browser/extension_whitelist_service.h"
#include "brave/components/brave_shields/browser/local_data_files_service.h"
#include "brave/grit/brave_generated_resources.h"
#include "ui/base/l10n/l10n_util.h"

Expand Down Expand Up @@ -61,7 +61,7 @@ bool BraveExtensionProvider::IsVetted(const std::string id) {
pdfjs_extension_id,
hangouts_extension_id,
widevine_extension_id,
brave_shields::kLocalDataFilesComponentId,
brave_component_updater::kLocalDataFilesComponentId,
// Web Store
"ahfgeienlihckogmohjhadlkjgocpleb",
// Brave Automation Extension
Expand Down
19 changes: 5 additions & 14 deletions browser/net/brave_ad_block_tp_network_delegate_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ bool GetPolyfillForAdBlock(bool allow_brave_shields, bool allow_ads,
return false;
}

void OnBeforeURLRequestAdBlockTPOnTaskRunner(
void OnBeforeURLRequestAdBlockTP(
std::shared_ptr<BraveRequestInfo> ctx) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
// If the following info isn't available, then proper content settings can't
// be looked up, so do nothing.
if (ctx->tab_origin.is_empty() || !ctx->tab_origin.has_host() ||
Expand Down Expand Up @@ -120,12 +121,7 @@ void OnBeforeURLRequestAdBlockTPOnTaskRunner(
&ctx->cancel_request_explicitly)) {
ctx->blocked_by = kTrackerBlocked;
}
}

void OnBeforeURLRequestDispatchOnIOThread(
const ResponseCallback& next_callback,
std::shared_ptr<BraveRequestInfo> ctx) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
if (ctx->blocked_by == kAdBlocked) {
brave_shields::DispatchBlockedEventFromIO(ctx->request_url,
ctx->render_frame_id, ctx->render_process_id, ctx->frame_tree_node_id,
Expand All @@ -135,8 +131,6 @@ void OnBeforeURLRequestDispatchOnIOThread(
ctx->render_frame_id, ctx->render_process_id, ctx->frame_tree_node_id,
brave_shields::kTrackers);
}

next_callback.Run();
}

int OnBeforeURLRequest_AdBlockTPPreWork(
Expand Down Expand Up @@ -169,13 +163,10 @@ int OnBeforeURLRequest_AdBlockTPPreWork(
return net::OK;
}

g_brave_browser_process->ad_block_service()->
GetTaskRunner()->PostTaskAndReply(FROM_HERE,
base::Bind(&OnBeforeURLRequestAdBlockTPOnTaskRunner, ctx),
base::Bind(base::IgnoreResult(
&OnBeforeURLRequestDispatchOnIOThread), next_callback, ctx));
// TODO(bridiver) - fix this
OnBeforeURLRequestAdBlockTP(ctx);
Copy link
Member

Choose a reason for hiding this comment

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

Can you elaborate on what you want to fix here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

actually the comment can just be removed, I had that there as a reminder from before our conversation


return net::ERR_IO_PENDING;
return net::OK;
}

} // namespace brave
9 changes: 0 additions & 9 deletions chromium_src/chrome/browser/browser_process_impl.cc

This file was deleted.

4 changes: 4 additions & 0 deletions components/brave_component_updater/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ source_set("browser") {
"brave_component.h",
"dat_file_util.cc",
"dat_file_util.h",
"local_data_files_service.cc",
"local_data_files_service.h",
"local_data_files_observer.cc",
"local_data_files_observer.h",
]

deps = [
Expand Down
Loading