Only LOAD_VALIDATE_CACHE for validated resources.
When fetching an URL with LOAD_VALIDATE_CACHE, if the URL is in the
cache but does not have validation headers (e.g. ETag, Last-Modified),
it will be refetched in its entirety. We don't want that.
Instead, for resource fetches, we fetch the URL first with
LOAD_ONLY_FROM_CACHE, and then confirm that either it is missing or it
has strong validators before re-requesting the URL with
LOAD_VALIDATE_CACHE.
For config and manifest fetches, we fetch the URL normally (without the
LOAD_VALIDATE_CACHE flag), as we don't benefit from revalidation.
In order to effect the above, this change introduces a small state
machine, controlled by the FetchStage enum.
In order to test the above, this change introduces a custom URLFetcherFactory.
This is because FakeURLFetcherFactory lacks a way to fake more than one
response for the same URL.
For test, each of the requests need to be customized in a different way.
Because the URLFetcherFactory API doesn't create an URLFetcher until the URL is
requested, this requires passing around a lambda specifying how to modify it at
create time.
BUG=309216
Review URL: https://codereview.chromium.org/
1289683004
Cr-Commit-Position: refs/heads/master@{#344978}