Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ads_engine.cpp « partners_api - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1283289ee7f8f457fdf40540bcd65fbc86f6dd5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "partners_api/ads_engine.hpp"
#include "partners_api/facebook_ads.hpp"
#include "partners_api/google_ads.hpp"
#include "partners_api/mopub_ads.hpp"
#include "partners_api/rb_ads.hpp"

#include "indexer/feature_data.hpp"

#include <algorithm>
#include <memory>

namespace ads
{
Engine::Engine()
{
  // The banner systems are placed by priority. First has a top priority.
  m_banners.emplace_back(Banner::Type::RB, std::make_unique<Rb>());
  m_banners.emplace_back(Banner::Type::Mopub, std::make_unique<Mopub>());

  m_searchBanners.emplace_back(Banner::Type::Facebook, std::make_unique<Facebook>());
}

bool Engine::HasBanner(feature::TypesHolder const & types, storage::CountriesVec const & countryIds,
                       std::string const & userLanguage) const
{
  for (auto const & countryId : countryIds)
  {
    for (auto const & item : m_banners)
    {
      if (item.m_enabled && item.m_container->HasBanner(types, countryId, userLanguage))
        return true;
    }
  }

  return false;
}

std::vector<Banner> Engine::GetBanners(feature::TypesHolder const & types,
                                       storage::CountriesVec const & countryIds,
                                       std::string const & userLanguage) const
{
  std::vector<Banner> result;

  for (auto const & item : m_banners)
  {
    if (!item.m_enabled)
      continue;

    for (auto const & countryId : countryIds)
    {
      auto const bannerId = item.m_container->GetBannerId(types, countryId, userLanguage);
      // We need to add banner for every banner system just once.
      if (!bannerId.empty())
      {
        result.emplace_back(item.m_type, bannerId);
        break;
      }
    }
  }

  return result;
}

bool Engine::HasSearchBanner() const
{
  for (auto const & item : m_searchBanners)
  {
    if (item.m_enabled && item.m_container->HasSearchBanner())
      return true;
  }

  return false;
}

std::vector<Banner> Engine::GetSearchBanners() const
{
  std::vector<Banner> result;

  for (auto const & item : m_searchBanners)
  {
    auto const bannerId = item.m_container->GetSearchBannerId();

    if (!bannerId.empty())
      result.emplace_back(item.m_type, bannerId);
  }

  return result;
}

void Engine::DisableAdProvider(Banner::Type const type, Banner::Place const place)
{
  SetAdProviderEnabled(place == Banner::Place::Search ? m_searchBanners : m_banners, type, false);
}

void Engine::SetAdProviderEnabled(std::vector<Engine::ContainerItem> & banners,
                                  Banner::Type const type, bool const isEnabled)
{
  for (auto & item : banners)
  {
    if (item.m_type == type)
    {
      item.m_enabled = isEnabled;
      return;
    }
  }
}
}  // namespace ads