Skip to content

Commit

Permalink
move FilePath operations out of adblock ui
Browse files Browse the repository at this point in the history
  • Loading branch information
antonok-edm committed Aug 20, 2021
1 parent 1ab371c commit be1073b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
13 changes: 3 additions & 10 deletions browser/ui/webui/brave_adblock_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@
#include "brave/components/brave_shields/browser/ad_block_service_helper.h"
#include "brave/components/brave_shields/browser/ad_block_subscription_service_manager.h"
#include "brave/components/brave_shields/browser/ad_block_subscription_service_manager_observer.h"
#include "brave/components/brave_shields/common/brave_shield_constants.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_navigator_params.h"
#include "chrome/browser/ui/singleton_tabs.h"
#include "components/grit/brave_components_resources.h"
#include "content/public/browser/web_ui_message_handler.h"
#include "net/base/filename_util.h"

namespace {

Expand Down Expand Up @@ -258,14 +256,9 @@ void AdblockDOMHandler::HandleViewSubscriptionSource(
return;
}

// TODO(bridiver) - the ui shouldn't have to figure this out
const auto cached_list_path =
g_brave_browser_process->ad_block_service()
->subscription_service_manager()
->GetSubscriptionPath(list_url)
.AppendASCII(brave_shields::kCustomSubscriptionListText);

const GURL file_url = net::FilePathToFileURL(cached_list_path);
const GURL file_url = g_brave_browser_process->ad_block_service()
->subscription_service_manager()
->GetListTextFileUrl(list_url);

auto* browser =
chrome::FindBrowserWithWebContents(web_ui()->GetWebContents());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
#include "brave/components/brave_shields/browser/ad_block_service_helper.h"
#include "brave/components/brave_shields/browser/ad_block_subscription_service.h"
#include "brave/components/brave_shields/browser/ad_block_subscription_service_manager_observer.h"
#include "brave/components/brave_shields/common/brave_shield_constants.h"
#include "brave/components/brave_shields/common/pref_names.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "content/public/browser/browser_task_traits.h"
#include "crypto/sha2.h"
#include "net/base/filename_util.h"

namespace brave_shields {

Expand Down Expand Up @@ -85,6 +87,16 @@ base::FilePath AdBlockSubscriptionServiceManager::GetSubscriptionPath(
return subscription_path_.AppendASCII(pathsafe_id);
}

GURL AdBlockSubscriptionServiceManager::GetListTextFileUrl(
const SubscriptionIdentifier id) const {
base::FilePath cached_list_path = GetSubscriptionPath(id).AppendASCII(
brave_shields::kCustomSubscriptionListText);

const GURL file_url = net::FilePathToFileURL(cached_list_path);

return file_url;
}

void AdBlockSubscriptionServiceManager::CreateSubscription(
const GURL& list_url) {
FilterListSubscriptionInfo info;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,14 @@ class AdBlockSubscriptionServiceManager {
const base::FilePath& user_data_dir);
~AdBlockSubscriptionServiceManager();

// Returns the directory used to store cached list data for the given
// subscription.
base::FilePath GetSubscriptionPath(const SubscriptionIdentifier id) const;

// Returns a `file://` URL that points directly to the cached list text file
// used for the given subscription.
GURL GetListTextFileUrl(const SubscriptionIdentifier id) const;

std::vector<FilterListSubscriptionInfo> GetSubscriptions() const;
void EnableSubscription(const SubscriptionIdentifier& id, bool enabled);
void DeleteSubscription(const SubscriptionIdentifier& id);
Expand Down

0 comments on commit be1073b

Please sign in to comment.