Skip to content

Commit

Permalink
Remove blink deps from /brave/components/brave_ads/core.
Browse files Browse the repository at this point in the history
  • Loading branch information
aseren committed Jan 31, 2023
1 parent 74ea266 commit b32ae23
Show file tree
Hide file tree
Showing 14 changed files with 118 additions and 109 deletions.
2 changes: 1 addition & 1 deletion browser/brave_ads/sources.gni
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ brave_browser_brave_ads_deps = [
"//brave/browser/ui/brave_ads",
"//brave/components/brave_ads/browser",
"//brave/components/brave_ads/common",
"//brave/components/brave_ads/content/browser/search_result_ad",
"//brave/components/brave_ads/content/browser",
"//brave/components/brave_federated",
"//brave/components/brave_federated/public/interfaces",
"//brave/components/brave_rewards/browser",
Expand Down
9 changes: 0 additions & 9 deletions components/brave_ads/common/brave_ads_host.mojom

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at https://mozilla.org/MPL/2.0/.

source_set("search_result_ad") {
static_library("browser") {
sources = [
"search_result_ad_handler.cc",
"search_result_ad_handler.h",
"search_result_ad/search_result_ad_handler.cc",
"search_result_ad/search_result_ad_handler.h",
]

deps = [
"//base",
"//brave/components/brave_ads/browser",
"//brave/components/brave_ads/common",
"//brave/components/brave_ads/core/browser/search_result_ad",
"//brave/components/brave_ads/core/browser",
"//brave/components/brave_search/common",
"//components/schema_org/common:mojom",
"//content/public/browser",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ void SearchResultAdHandler::OnRetrieveSearchResultAdEntities(
return;
}

search_result_ads_ = ConvertWebPageToSearchResultAds(std::move(web_page));
search_result_ads_ =
ConvertWebPageEntitiesToSearchResultAds(web_page->entities);

if (search_result_ads_ && should_trigger_viewed_event_) {
for (const auto& [key, search_result_ad] : *search_result_ads_) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ namespace {
constexpr char kAllowedDomain[] = "https://search.brave.com";
constexpr char kNotAllowedDomain[] = "https://brave.com";

blink::mojom::WebPagePtr CreateTestWebPage() {
blink::mojom::WebPagePtr web_page = blink::mojom::WebPage::New();
web_page->entities = CreateTestWebPageEntities();
return web_page;
}

} // namespace

class SearchResultAdHandlerTest : public ::testing::Test {
Expand Down
4 changes: 4 additions & 0 deletions components/brave_ads/core/DEPS
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include_rules = [
"-content",
"-third_party/blink",
]
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,19 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at https://mozilla.org/MPL/2.0/.

source_set("search_result_ad") {
static_library("browser") {
sources = [
"search_result_ad_converting_util.cc",
"search_result_ad_converting_util.h",
"search_result_ad/search_result_ad_converting_util.cc",
"search_result_ad/search_result_ad_converting_util.h",
]

deps = [
"//base",
"//components/schema_org/common:mojom",
"//services/network/public/cpp",
"//third_party/abseil-cpp:absl",
"//url",
]

public_deps = [
"//brave/vendor/bat-native-ads",
"//third_party/blink/public/mojom:mojom_platform_headers",
"//components/schema_org/common:mojom",
]
}
4 changes: 0 additions & 4 deletions components/brave_ads/core/browser/search_result_ad/DEPS

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@

#include "brave/components/brave_ads/core/browser/search_result_ad/search_result_ad_converting_util.h"

#include <iterator>
#include <string>
#include <utility>
#include <vector>

#include "base/containers/fixed_flat_set.h"
#include "base/containers/flat_set.h"
#include "base/logging.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_number_conversions.h"
#include "brave/vendor/bat-native-ads/include/bat/ads/public/interfaces/ads.mojom.h"
#include "components/schema_org/common/metadata.mojom.h"
#include "third_party/blink/public/mojom/document_metadata/document_metadata.mojom.h"

using ads::mojom::ConversionInfo;
using ads::mojom::ConversionInfoPtr;
Expand Down Expand Up @@ -229,14 +229,16 @@ void ConvertEntityToSearchResultAd(const schema_org::mojom::EntityPtr& entity,

// Not all of attributes were specified.
if (found_attributes.size() != kSearchResultAdAttributes.size()) {
std::vector<base::StringPiece> absent_attributes;
std::set_difference(kSearchResultAdAttributes.begin(),
kSearchResultAdAttributes.end(),
found_attributes.begin(), found_attributes.end(),
std::back_inserter(absent_attributes));

VLOG(6) << "Some of search result ad attributes were not specified: "
<< base::JoinString(absent_attributes, ", ");
if (VLOG_IS_ON(6)) {
std::vector<base::StringPiece> absent_attributes;
base::ranges::set_difference(
kSearchResultAdAttributes.cbegin(), kSearchResultAdAttributes.cend(),
found_attributes.cbegin(), found_attributes.cend(),
std::back_inserter(absent_attributes));

VLOG(6) << "Some of search result ad attributes were not specified: "
<< base::JoinString(absent_attributes, ", ");
}

return;
}
Expand Down Expand Up @@ -302,14 +304,11 @@ void LogSearchResultAdMap(const SearchResultAdMap& search_result_ads) {

} // namespace

SearchResultAdMap ConvertWebPageToSearchResultAds(
blink::mojom::WebPagePtr web_page) {
SearchResultAdMap ConvertWebPageEntitiesToSearchResultAds(
const std::vector<::schema_org::mojom::EntityPtr>& web_page_entities) {
SearchResultAdMap search_result_ads;
if (!web_page) {
return search_result_ads;
}

for (const auto& entity : web_page->entities) {
for (const auto& entity : web_page_entities) {
if (!entity || entity->type != kProductType) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@
#ifndef BRAVE_COMPONENTS_BRAVE_ADS_CORE_BROWSER_SEARCH_RESULT_AD_SEARCH_RESULT_AD_CONVERTING_UTIL_H_
#define BRAVE_COMPONENTS_BRAVE_ADS_CORE_BROWSER_SEARCH_RESULT_AD_SEARCH_RESULT_AD_CONVERTING_UTIL_H_

#include <vector>

#include "base/containers/flat_map.h"
#include "brave/vendor/bat-native-ads/include/bat/ads/public/interfaces/ads.mojom-forward.h"
#include "third_party/blink/public/mojom/document_metadata/document_metadata.mojom-forward.h"
#include "components/schema_org/common/metadata.mojom.h"
#include "url/gurl.h"

namespace brave_ads {

using SearchResultAdMap =
base::flat_map<GURL, ads::mojom::SearchResultAdInfoPtr>;

SearchResultAdMap ConvertWebPageToSearchResultAds(
blink::mojom::WebPagePtr web_page);
SearchResultAdMap ConvertWebPageEntitiesToSearchResultAds(
const std::vector<::schema_org::mojom::EntityPtr>& web_page_entities);

} // namespace brave_ads

Expand Down
Loading

0 comments on commit b32ae23

Please sign in to comment.