Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] OnlineFileSource is never accessed directly
Browse files Browse the repository at this point in the history
  • Loading branch information
pozdnyakov committed Feb 26, 2020
1 parent d9294ae commit d410b47
Show file tree
Hide file tree
Showing 10 changed files with 144 additions and 154 deletions.
2 changes: 1 addition & 1 deletion include/mbgl/storage/online_file_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class OnlineFileSource : public FileSource {
OnlineFileSource();
~OnlineFileSource() override;

private:
// FileSource overrides
std::unique_ptr<AsyncRequest> request(const Resource&, Callback) override;
bool canRequest(const Resource&) const override;
Expand All @@ -19,7 +20,6 @@ class OnlineFileSource : public FileSource {
mapbox::base::Value getProperty(const std::string&) const override;
void setResourceTransform(ResourceTransform) override;

private:
class Impl;
const std::unique_ptr<Impl> impl;
};
Expand Down
3 changes: 1 addition & 2 deletions platform/android/src/file_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ FileSource::FileSource(jni::JNIEnv& _env, const jni::String& accessToken, const
mbgl::FileSourceManager::get()->getFileSource(mbgl::FileSourceType::ResourceLoader, resourceOptions);
databaseSource = std::static_pointer_cast<mbgl::DatabaseFileSource>(std::shared_ptr<mbgl::FileSource>(
mbgl::FileSourceManager::get()->getFileSource(mbgl::FileSourceType::Database, resourceOptions)));
onlineSource = std::static_pointer_cast<mbgl::OnlineFileSource>(std::shared_ptr<mbgl::FileSource>(
mbgl::FileSourceManager::get()->getFileSource(mbgl::FileSourceType::Network, resourceOptions)));
onlineSource = mbgl::FileSourceManager::get()->getFileSource(mbgl::FileSourceType::Network, resourceOptions);
}

FileSource::~FileSource() {
Expand Down
2 changes: 1 addition & 1 deletion platform/android/src/file_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class FileSource {
std::unique_ptr<Actor<ResourceTransform::TransformCallback>> resourceTransform;
std::function<void()> pathChangeCallback;
std::shared_ptr<mbgl::DatabaseFileSource> databaseSource;
std::shared_ptr<mbgl::OnlineFileSource> onlineSource;
std::shared_ptr<mbgl::FileSource> onlineSource;
std::shared_ptr<mbgl::FileSource> resourceLoader;
};

Expand Down
4 changes: 2 additions & 2 deletions platform/darwin/src/MGLOfflineStorage.mm
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ @interface MGLOfflineStorage ()

@property (nonatomic, strong, readwrite) NSMutableArray<MGLOfflinePack *> *packs;
@property (nonatomic) std::shared_ptr<mbgl::DatabaseFileSource> mbglDatabaseFileSource;
@property (nonatomic) std::shared_ptr<mbgl::OnlineFileSource> mbglOnlineFileSource;
@property (nonatomic) std::shared_ptr<mbgl::FileSource> mbglOnlineFileSource;
@property (nonatomic) std::shared_ptr<mbgl::FileSource> mbglFileSource;
@property (nonatomic) std::string mbglCachePath;
@property (nonatomic, getter=isPaused) BOOL paused;
Expand Down Expand Up @@ -233,7 +233,7 @@ - (instancetype)init {
options.withCachePath(_mbglCachePath)
.withAssetPath([NSBundle mainBundle].resourceURL.path.UTF8String);
_mbglFileSource = mbgl::FileSourceManager::get()->getFileSource(mbgl::FileSourceType::ResourceLoader, options);
_mbglOnlineFileSource = std::static_pointer_cast<mbgl::OnlineFileSource>(std::shared_ptr<mbgl::FileSource>(mbgl::FileSourceManager::get()->getFileSource(mbgl::FileSourceType::Network, options)));
_mbglOnlineFileSource = mbgl::FileSourceManager::get()->getFileSource(mbgl::FileSourceType::Network, options);
_mbglDatabaseFileSource = std::static_pointer_cast<mbgl::DatabaseFileSource>(std::shared_ptr<mbgl::FileSource>(mbgl::FileSourceManager::get()->getFileSource(mbgl::FileSourceType::Database, options)));

// Observe for changes to the API base URL (and find out the current one).
Expand Down
2 changes: 1 addition & 1 deletion platform/darwin/src/MGLOfflineStorage_Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ NS_ASSUME_NONNULL_BEGIN
/**
The shared online file source object owned by the shared offline storage object.
*/
@property (nonatomic) std::shared_ptr<mbgl::OnlineFileSource> mbglOnlineFileSource;
@property (nonatomic) std::shared_ptr<mbgl::FileSource> mbglOnlineFileSource;

/**
The shared resource loader file source object owned by the shared offline storage object.
Expand Down
2 changes: 1 addition & 1 deletion platform/default/src/mbgl/storage/file_source_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class DefaultFileSourceManagerImpl final : public FileSourceManager {
[](const ResourceOptions&) { return std::make_unique<LocalFileSource>(); });

registerFileSourceFactory(FileSourceType::Network, [](const ResourceOptions& options) {
auto networkSource = std::make_unique<OnlineFileSource>();
std::unique_ptr<FileSource> networkSource = std::make_unique<OnlineFileSource>();
networkSource->setProperty(ACCESS_TOKEN_KEY, options.accessToken());
networkSource->setProperty(API_BASE_URL_KEY, options.baseURL());
return networkSource;
Expand Down
2 changes: 1 addition & 1 deletion platform/qt/src/qmapboxgl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1753,7 +1753,7 @@ QMapboxGLPrivate::QMapboxGLPrivate(QMapboxGL *q, const QMapboxGLSettings &settin
}};
std::shared_ptr<mbgl::FileSource> fs =
mbgl::FileSourceManager::get()->getFileSource(mbgl::FileSourceType::Network, resourceOptions);
std::static_pointer_cast<mbgl::OnlineFileSource>(fs)->setResourceTransform(std::move(transform));
fs->setResourceTransform(std::move(transform));
}

// Needs to be Queued to give time to discard redundant draw calls via the `renderQueued` flag.
Expand Down
4 changes: 2 additions & 2 deletions test/src/mbgl/test/fake_file_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ class FakeOnlineFileSource : public FakeFileSource {
}

mapbox::base::Value getProperty(const std::string& property) const override {
return onlineFs.getProperty(property);
return onlineFs->getProperty(property);
}

OnlineFileSource onlineFs;
std::unique_ptr<FileSource> onlineFs = std::make_unique<OnlineFileSource>();
};

} // namespace mbgl
3 changes: 1 addition & 2 deletions test/storage/main_resource_loader.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,9 +530,8 @@ TEST(MainResourceLoader, TEST_REQUIRES_SERVER(NoCacheRefreshModifiedModified)) {
TEST(MainResourceLoader, TEST_REQUIRES_SERVER(SetResourceTransform)) {
util::RunLoop loop;
MainResourceLoader resourceLoader(ResourceOptions{});
std::shared_ptr<FileSource> fs =
std::shared_ptr<FileSource> onlinefs =
FileSourceManager::get()->getFileSource(FileSourceType::Network, ResourceOptions{});
auto onlinefs = std::static_pointer_cast<OnlineFileSource>(fs);

// Translates the URL "localhost://test to http://127.0.0.1:3000/test
Actor<ResourceTransform::TransformCallback> transform(
Expand Down
Loading

0 comments on commit d410b47

Please sign in to comment.