Commit Graph

45 Commits

Author SHA1 Message Date
John Firebaugh
3af3e72bb3 [all] Replace HTTPContextBase/HTTPRequestBase with FileSource 2016-04-14 14:18:19 -07:00
John Firebaugh
6d88a23a60 [core] Remove internal threading from OnlineFileRequest
There's no need to do the work that OnlineFileRequest does on a separate thread from the DefaultFileSource thread, and having AsyncTasks proxy to other tasks across a thread boundary adds needless complexity.
2016-04-14 14:18:19 -07:00
John Firebaugh
169755e89a [core] Unify FileRequest and WorkRequest 2016-03-24 10:54:32 -07:00
Thiago Marcos P. Santos
0c3247bf3c [core] Fix regression of prior expiration time not being respected 2016-03-17 23:57:28 -03:00
Thiago Marcos P. Santos
672727f773 [core] Make OnlineFileSource respect the NetworkStatus
The user can now force the Offline mode and set it back
to Online, triggering the requests waiting for network connection.
2016-03-08 10:31:01 -03:00
Thiago Marcos P. Santos
f683b10e10 [core] Build fix
Fix no viable conversion on OSX.
2016-02-26 04:21:28 +02:00
Thiago Marcos P. Santos
59a45b8400 [core] Add timeout for clock skew
If the server keeps sending replies considered from the client in the
past (there is no way to tell if the server or client clock is wrong),
the client will try to interpolate a valid expiration time based
on the delta of the expiration intervals sent by the server.

If the intervals are always the same, exponential backoff kicks in
until we get a different expiration time from what we already have.
2016-02-26 03:52:02 +02:00
Thiago Marcos P. Santos
843cad04fb [core] Add retry delay on expired tiles
When we receive an expired tile, we don't immediately retry
because in case the server keeps serving an expired tile, that
would cause an infinite retry cycle.

Now we add an exponential delay, similarly to what we do for
connection errors.
2016-02-26 03:20:51 +02:00
Thiago Marcos P. Santos
1efc299e66 [core] Faster access with unordered_set
The ordering won't be affected because requests are made
as they arrive and later stored on the map just for
keeping state.
2016-02-16 23:06:04 +02:00
Thiago Marcos P. Santos
f5b521ffb5 [core] Remove requests from the pending queue on cancel
If we don't do this, we can activate a request twice.

The issue here is that we use memory address as the 'key'. So if
we destroy a request, another request might take the same memory
address, or the same 'key'.

The entry at 'pendingRequests' survives the 'cancel()' and is
ultimatelly removed at 'activatePendingRequest()'. This is fine
unless a request is created using the same 'key' before we call
'activatePendingRequest()'.

The check if the request was canceled at 'activatePendingRequest()'
will be no longer valid, activating the request. At the same time
the request will be activated again by the task scheduled at the
constructor of the 'OnlineFileRequestImpl' class.
2016-02-16 23:06:04 +02:00
Konstantin Käfer
5726d2b357 [core] use std::move() to prevent copies 2016-02-11 12:17:33 +01:00
John Firebaugh
ff15bd51b9 [core] Throttle the number of concurrent requests to 20 2016-02-10 15:40:20 -08:00
John Firebaugh
5d42321b73 [core] Make {Default,Online}FileSource::Impl more similar 2016-02-10 15:40:20 -08:00
John Firebaugh
025375ad0b [core] Cache with mapbox:// tile URLs 2016-02-10 15:40:20 -08:00
John Firebaugh
dbb8e58aea [core] Moving caching logic to DefaultFileSource
This results in OnlineFileSource containing precisely the logic we want for reuse by OfflineFileSource, and no more.
2016-02-10 15:40:20 -08:00
John Firebaugh
a877b9b192 [core] Include prior values of caching headers in Resource
This allows the FileSource interface itself to support revalidation. We could (and probably should) now rewrite HTTPContextBase implementations as FileSource implementations.
2016-01-22 18:42:53 -08:00
John Firebaugh
1c21d0fd4c [core] Use better types for modified / expires / etag 2016-01-21 11:22:11 -08:00
John Firebaugh
c33ed50c98 [core] Eliminate Response::stale and inline Response::isExpired()
Response::isExpired() had subtle and potentially confusing behavior around Seconds::zero(). It's best to inline it and comment why.
2016-01-21 11:22:11 -08:00
John Firebaugh
1766d7dcbf [core] Eliminate RequestBase
HTTPRequestBase can now itself be the base class.
2016-01-21 11:22:11 -08:00
John Firebaugh
0066637e58 [core] Let SQLiteCache decide when store or refresh responses 2016-01-14 13:46:03 -08:00
John Firebaugh
2aafdbc1b8 [core] Add an explicit "not modified" indicator to Response 2016-01-14 13:46:03 -08:00
John Firebaugh
2ee1fe4178 [core] std::shared_ptr<const Response> ⇢ const Response& 2016-01-14 13:46:03 -08:00
John Firebaugh
7fb5e973ed [core] Eliminate FileCache interface
There is only one implementation and we're unlikely to add more.
2016-01-14 13:46:03 -08:00
John Firebaugh
618902e06c [core] Remove request coalescing in OnlineFileSource 2016-01-13 13:43:05 -08:00
John Firebaugh
716a9c92cb [core] Inline a temporary variable which is now used only once 2016-01-13 13:40:31 -08:00
John Firebaugh
86c8446d3a [core] Simplify asset:// implementation
* Move asset:// URL handling to DefaultFileSource.
* AssetFileSource implements FileSource interface and follows familiar implementation patterns.
* Move default implementation to platform/default, zip implementation to platform/android.
* Don't bother with modified / expires / etag -- assets are not cached so it doesn't matter.
* Don't bother with interleaving individual IO calls on the implementation thread. That adds a lot of complexity for very little benefit.
2016-01-13 13:40:31 -08:00
John Firebaugh
2126e34e52 [core] Further clarify timeout calculations 2016-01-13 13:38:12 -08:00
John Firebaugh
54fc3831f2 [core] Use Seconds::max() rather than -1 for simpler logic 2016-01-13 13:38:12 -08:00
John Firebaugh
96781c0a8d [core] Inline OnlineFileRequestImpl::setResponse
In the cache response case, we don't want the failedRequests logic; cached errors, should they occur, shouldn't affect the scheduling behavior for real requests.
2016-01-13 13:38:12 -08:00
John Firebaugh
601e3d9d45 [core] Refactor down to two methods for scheduling a cache or real request 2016-01-13 13:38:12 -08:00
John Firebaugh
682b2335e5 [core] Inline OnlineFileRequestImpl::getRetryTimeout 2016-01-13 13:38:12 -08:00
John Firebaugh
ea45075e4d [core] Inline OnlineFileRequestImpl::checkResponseFreshness 2016-01-13 13:38:12 -08:00
John Firebaugh
6f9de6ae47 [core] Refactor to instance methods on OnlineFileRequestImpl 2016-01-13 13:38:12 -08:00
John Firebaugh
e9eb29719b [core] Simplify logic for notification with pre-existing response
We already had a condition that checks if a response is immediately available for an incoming request. Call the callback there, rather than in addObserver.
2016-01-13 13:38:12 -08:00
John Firebaugh
dd3ca81589 [core] Inline sole use of OnlineFileSource::Impl::update 2016-01-13 13:38:12 -08:00
John Firebaugh
f8d3cf41ae [core] Simplify OnlineFileSource::Impl::reschedule 2016-01-13 13:38:12 -08:00
Thiago Marcos P. Santos
d7fdcc73bf [core] Get rid of ::unref() for Timer and AsyncTask
Not need, legacy from libuv. The RunLoop keep the main
loop running until is explicitly no longer needed.
2016-01-09 01:26:29 +02:00
John Firebaugh
0a8fef1f51 [core] Merge OnlineFileRequestImpl::notify into OnlineFileRequestImpl::setResponse
In every case where setResponse is called, notify was called soon after. In one case immediately, in another, after intervening functions which are safe to reorder after notifications.

The null-check of response is safe to eliminate because response must not be null inside setResponse.
2016-01-08 12:29:11 -08:00
John Firebaugh
adf3dea4e5 [core] Simplify OnlineFileSource's Timer use
There is no need for the timer to be created only under certain conditions. Stopping a non-started timer is a no-op. Therefore it can simply be a direct member.

While here, rename the variable. It's a timer, not a request.
2016-01-08 12:23:48 -08:00
Konstantin Käfer
a06f28ddb7 [core] only cache successful or NotFound responses
We don't want other types of error end up in our cache, since it'll likely evict perfectly good content.
2016-01-08 16:25:54 +01:00
Konstantin Käfer
4479f5db6c [core] don't consult cache for asset resources 2016-01-08 13:05:51 +01:00
Konstantin Käfer
bc309d84d7 [core] unify URL prefix detection (asset:// and mapbox://) 2016-01-08 12:14:39 +01:00
John Firebaugh
7a6076ea9d [tests] Test with OnlineFileSource
When we introduce OfflineFileSource, the behavior of existing tests should
not change.
2015-12-23 14:55:12 -08:00
John Firebaugh
c972a251da [core] Remove Resource dependency from low-level classes
These classes should not be coupled to domain-specific resource types.
2015-12-23 14:30:20 -08:00
John Firebaugh
ab0efe5d00 [core] Move OnlineFileSource to platform
Preparation for OfflineFileSource which depends on SQLite
2015-12-22 12:09:14 -08:00