From 887a55aa770b137e3cf2878e07becf47b29e5406 Mon Sep 17 00:00:00 2001 From: "Brian R. Bondy" Date: Thu, 6 Jun 2019 09:09:05 -0400 Subject: [PATCH] Keep track of tags after deserializing --- .../brave_shields/browser/ad_block_base_service.cc | 9 +++++++++ components/brave_shields/browser/ad_block_base_service.h | 1 + 2 files changed, 10 insertions(+) diff --git a/components/brave_shields/browser/ad_block_base_service.cc b/components/brave_shields/browser/ad_block_base_service.cc index a331a6345cb3..79f660446266 100644 --- a/components/brave_shields/browser/ad_block_base_service.cc +++ b/components/brave_shields/browser/ad_block_base_service.cc @@ -180,8 +180,14 @@ void AdBlockBaseService::EnableTagOnIOThread( DCHECK_CURRENTLY_ON(BrowserThread::IO); if (enabled) { ad_block_client_->addTag(tag); + tags_.push_back(tag); } else { ad_block_client_->removeTag(tag); + std::vector::iterator it = + std::find(tags_.begin(), tags_.end(), tag); + if (it != tags_.end()) { + tags_.erase(it); + } } } @@ -220,6 +226,9 @@ void AdBlockBaseService::UpdateAdBlockClient( DCHECK_CURRENTLY_ON(BrowserThread::IO); ad_block_client_ = std::move(ad_block_client); buffer_ = std::move(buffer); + std::for_each(tags_.begin(), tags_.end(), [&](const std::string tag) { + ad_block_client_->addTag(tag); + }); } diff --git a/components/brave_shields/browser/ad_block_base_service.h b/components/brave_shields/browser/ad_block_base_service.h index f12b71ff8f8d..2c60d05fe5b2 100644 --- a/components/brave_shields/browser/ad_block_base_service.h +++ b/components/brave_shields/browser/ad_block_base_service.h @@ -63,6 +63,7 @@ class AdBlockBaseService : public BaseBraveShieldsService { void OnPreferenceChanges(const std::string& pref_name); brave_component_updater::DATFileDataBuffer buffer_; + std::vector tags_; base::WeakPtrFactory weak_factory_; base::WeakPtrFactory weak_factory_io_thread_; DISALLOW_COPY_AND_ASSIGN(AdBlockBaseService);