[core] network policy dummy

This commit is contained in:
Arsentiy Milchakov 2016-11-28 15:51:59 +03:00
parent ce474ca724
commit a58e7324ca
8 changed files with 112 additions and 15 deletions

View file

@ -27,6 +27,7 @@
#include "platform/local_country_file_utils.hpp"
#include "platform/location.hpp"
#include "platform/measurement_utils.hpp"
#include "platform/network_policy.hpp"
#include "platform/platform.hpp"
#include "platform/preferred_languages.hpp"
#include "platform/settings.hpp"
@ -37,9 +38,19 @@
android::Framework * g_framework = 0;
namespace platform
{
// Dummy, implementation and location should be chosen by android developer.
NetworkPolicy ToNativeNetworkPolicy(jobject obj)
{
return NetworkPolicy(true);
}
} // namespace platform
using namespace storage;
using platform::CountryFile;
using platform::LocalCountryFile;
using platform::ToNativeNetworkPolicy;
static_assert(sizeof(int) >= 4, "Size of jint in less than 4 bytes.");
@ -473,13 +484,21 @@ place_page::Info & Framework::GetPlacePageInfo()
void Framework::RequestBookingMinPrice(string const & hotelId, string const & currencyCode, function<void(string const &, string const &)> const & callback)
{
return m_work.GetBookingApi().GetMinPrice(hotelId, currencyCode, callback);
// Stub obj must be changed.
jobject obj;
auto const bookingApi = m_work.GetBookingApi(ToNativeNetworkPolicy(obj));
if (bookingApi)
bookingApi->GetMinPrice(hotelId, currencyCode, callback);
}
void Framework::RequestBookingInfo(string const & hotelId, string const & lang,
function<void(BookingApi::HotelInfo const &)> const & callback)
{
return m_work.GetBookingApi().GetHotelInfo(hotelId, lang, callback);
// Stub obj must be changed.
jobject obj;
auto const bookingApi = m_work.GetBookingApi(ToNativeNetworkPolicy(obj));
if (bookingApi)
bookingApi->GetHotelInfo(hotelId, lang, callback);
}
bool Framework::HasSpaceForMigration()
@ -517,7 +536,13 @@ uint64_t Framework::RequestUberProducts(ms::LatLon const & from, ms::LatLon cons
uber::ProductsCallback const & callback,
uber::ErrorCallback const & errorCallback)
{
return m_work.GetUberApi().GetAvailableProducts(from, to, callback, errorCallback);
// Stub obj must be changed.
jobject obj;
auto const uberApi = m_work.GetUberApi(ToNativeNetworkPolicy(obj));
if (!uberApi)
return 0;
return uberApi->GetAvailableProducts(from, to, callback, errorCallback);
}
uber::RideRequestLinks Framework::GetUberLinks(string const & productId, ms::LatLon const & from, ms::LatLon const & to)

View file

@ -2,6 +2,8 @@
#include "Framework.h"
#include "platform/network_policy.hpp"
#include "base/string_utils.hpp"
#include "3party/opening_hours/opening_hours.hpp"
@ -13,6 +15,7 @@ NSString * const kUserDefaultsLatLonAsDMSKey = @"UserDefaultsLatLonAsDMS";
} // namespace
using namespace place_page;
using platform::MakeNetworkPolicyIos;
@implementation MWMPlacePageData
{
@ -257,7 +260,7 @@ using namespace place_page;
currencyFormatter.maximumFractionDigits = 0;
string const currency = currencyFormatter.currencyCode.UTF8String;
auto & api = GetFramework().GetBookingApi();
auto const api = GetFramework().GetBookingApi(MakeNetworkPolicyIos(true));
auto const func = [self, label, currency, currencyFormatter](string const & minPrice,
string const & priceCurrency) {
@ -284,7 +287,8 @@ using namespace place_page;
});
};
api.GetMinPrice(self.sponsoredId.UTF8String, currency, func);
if (api)
api->GetMinPrice(self.sponsoredId.UTF8String, currency, func);
}
- (NSString *)address { return @(m_info.GetAddress().c_str()); }

View file

@ -9,9 +9,11 @@
#include "platform/measurement_utils.hpp"
#include "platform/mwm_version.hpp"
#include "platform/network_policy.hpp"
#include "platform/platform.hpp"
using feature::Metadata;
using platform::MakeNetworkPolicyIos;
static NSString * const kUserDefaultsLatLonAsDMSKey = @"UserDefaultsLatLonAsDMS";
@ -131,7 +133,9 @@ void initFieldsMap()
currencyFormatter.numberStyle = NSNumberFormatterCurrencyStyle;
currencyFormatter.maximumFractionDigits = 0;
string const currency = currencyFormatter.currencyCode.UTF8String;
GetFramework().GetBookingApi().GetMinPrice(
auto const api = GetFramework().GetBookingApi(MakeNetworkPolicyIos(true));
if (api)
api->GetMinPrice(
m_info.GetMetadata().Get(Metadata::FMD_SPONSORED_ID), currency,
[self, completion, failure, currency, currencyFormatter](string const & minPrice,
string const & priceCurrency) {

View file

@ -59,6 +59,7 @@
#include "platform/local_country_file_utils.hpp"
#include "platform/measurement_utils.hpp"
#include "platform/mwm_version.hpp"
#include "platform/network_policy.hpp"
#include "platform/platform.hpp"
#include "platform/preferred_languages.hpp"
#include "platform/settings.hpp"
@ -447,6 +448,30 @@ Framework::~Framework()
m_model.SetOnMapDeregisteredCallback(nullptr);
}
BookingApi * Framework::GetBookingApi(platform::NetworkPolicy const & policy)
{
if (policy.CanUse())
return m_bookingApi.get();
return nullptr;
}
BookingApi const * Framework::GetBookingApi(platform::NetworkPolicy const & policy) const
{
if (policy.CanUse())
return m_bookingApi.get();
return nullptr;
}
uber::Api * Framework::GetUberApi(platform::NetworkPolicy const & policy)
{
if (policy.CanUse())
return m_uberApi.get();
return nullptr;
}
void Framework::DrawWatchFrame(m2::PointD const & center, int zoomModifier,
uint32_t pxWidth, uint32_t pxHeight,
df::watch::FrameSymbols const & symbols,
@ -795,10 +820,11 @@ void Framework::FillInfoFromFeatureType(FeatureType const & ft, place_page::Info
if (ftypes::IsBookingChecker::Instance()(ft))
{
ASSERT(m_bookingApi, ());
info.m_sponsoredType = SponsoredType::Booking;
auto const & baseUrl = info.GetMetadata().Get(feature::Metadata::FMD_WEBSITE);
info.m_sponsoredUrl = GetBookingApi().GetBookHotelUrl(baseUrl);
info.m_sponsoredDescriptionUrl = GetBookingApi().GetDescriptionUrl(baseUrl);
info.m_sponsoredUrl = m_bookingApi->GetBookHotelUrl(baseUrl);
info.m_sponsoredDescriptionUrl = m_bookingApi->GetDescriptionUrl(baseUrl);
}
else if (ftypes::IsOpentableChecker::Instance()(ft))
{

View file

@ -91,6 +91,11 @@ namespace df
}
}
namespace platform
{
class NetworkPolicy;
}
/// Uncomment line to make fixed position settings and
/// build version for screenshots.
//#define FIXED_LOCATION
@ -160,9 +165,8 @@ protected:
BookmarkManager m_bmManager;
BookingApi m_bookingApi;
uber::Api m_uberApi;
unique_ptr<BookingApi> m_bookingApi = make_unique<BookingApi>();
unique_ptr<uber::Api> m_uberApi = make_unique<uber::Api>();
df::DrapeApi m_drapeApi;
@ -195,13 +199,12 @@ public:
virtual ~Framework();
/// Get access to booking api helpers
BookingApi & GetBookingApi() { return m_bookingApi; }
BookingApi const & GetBookingApi() const { return m_bookingApi; }
BookingApi * GetBookingApi(platform::NetworkPolicy const & policy);
BookingApi const * GetBookingApi(platform::NetworkPolicy const & policy) const;
uber::Api * GetUberApi(platform::NetworkPolicy const & policy);
df::DrapeApi & GetDrapeApi() { return m_drapeApi; }
uber::Api & GetUberApi() { return m_uberApi;}
/// Migrate to new version of very different data.
bool IsEnoughSpaceForMigrate() const;
storage::TCountryId PreMigrate(ms::LatLon const & position, storage::Storage::TChangeCountryFunction const & change,

View file

@ -0,0 +1,30 @@
#pragma once
class _jobject;
typedef _jobject * jobject;
namespace platform
{
/// Class that is used to allow or disallow remote calls.
class NetworkPolicy
{
// Maker for android.
friend NetworkPolicy ToNativeNetworkPolicy(jobject obj);
// Maker for ios.
// Dummy, real signature should be chosen by ios developer.
friend NetworkPolicy MakeNetworkPolicyIos(bool canUseNetwork);
public:
bool CanUse() const { return m_canUse; }
private:
NetworkPolicy(bool const canUseNetwork) : m_canUse(canUseNetwork) {}
bool m_canUse = false;
};
// Dummy, real signature, implementation and location should be chosen by ios developer.
inline NetworkPolicy MakeNetworkPolicyIos(bool canUseNetwork)
{
return NetworkPolicy(canUseNetwork);
}
} // namespace platform

View file

@ -87,6 +87,7 @@ HEADERS += \
measurement_utils.hpp \
mwm_traits.hpp \
mwm_version.hpp \
network_policy.hpp \
platform.hpp \
preferred_languages.hpp \
servers_list.hpp \

View file

@ -16,6 +16,7 @@
3D30587D1D8320E4004AC712 /* http_client.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 3D30587B1D8320E4004AC712 /* http_client.hpp */; };
3D30587F1D880910004AC712 /* http_client_apple.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3D30587E1D880910004AC712 /* http_client_apple.mm */; };
3D97F64B1D9C05E800380945 /* http_client.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3D97F64A1D9C05E800380945 /* http_client.cpp */; };
3DE8B98F1DEC3115000E6083 /* network_policy.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 3DE8B98E1DEC3115000E6083 /* network_policy.hpp */; };
56EB1EDC1C6B6E6C0022D831 /* file_logging.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 56EB1ED81C6B6E6C0022D831 /* file_logging.cpp */; };
56EB1EDD1C6B6E6C0022D831 /* file_logging.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 56EB1ED91C6B6E6C0022D831 /* file_logging.hpp */; };
56EB1EDE1C6B6E6C0022D831 /* mwm_traits.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 56EB1EDA1C6B6E6C0022D831 /* mwm_traits.cpp */; };
@ -111,6 +112,7 @@
3D30587B1D8320E4004AC712 /* http_client.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = http_client.hpp; sourceTree = "<group>"; };
3D30587E1D880910004AC712 /* http_client_apple.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = http_client_apple.mm; sourceTree = "<group>"; };
3D97F64A1D9C05E800380945 /* http_client.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = http_client.cpp; sourceTree = "<group>"; };
3DE8B98E1DEC3115000E6083 /* network_policy.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = network_policy.hpp; sourceTree = "<group>"; };
56EB1ED81C6B6E6C0022D831 /* file_logging.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = file_logging.cpp; sourceTree = "<group>"; };
56EB1ED91C6B6E6C0022D831 /* file_logging.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = file_logging.hpp; sourceTree = "<group>"; };
56EB1EDA1C6B6E6C0022D831 /* mwm_traits.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = mwm_traits.cpp; sourceTree = "<group>"; };
@ -316,6 +318,7 @@
6753437A1A3F5CF500A0A8C3 /* platform */ = {
isa = PBXGroup;
children = (
3DE8B98E1DEC3115000E6083 /* network_policy.hpp */,
34513AF71DCB37C100471BDA /* marketing_service_ios.mm */,
34513AF81DCB37C100471BDA /* marketing_service.cpp */,
34513AF91DCB37C100471BDA /* marketing_service.hpp */,
@ -429,6 +432,7 @@
674125091B4C00CC00A3E828 /* country_defines.hpp in Headers */,
675343CD1A3F5D5A00A0A8C3 /* platform.hpp in Headers */,
6741250F1B4C00CC00A3E828 /* local_country_file.hpp in Headers */,
3DE8B98F1DEC3115000E6083 /* network_policy.hpp in Headers */,
675E88A11DB7B0F200F8EBDA /* test_socket.hpp in Headers */,
675343CF1A3F5D5A00A0A8C3 /* preferred_languages.hpp in Headers */,
3D30587D1D8320E4004AC712 /* http_client.hpp in Headers */,