| Index: chrome/browser/predictors/loading_predictor.h
|
| diff --git a/chrome/browser/predictors/loading_predictor.h b/chrome/browser/predictors/loading_predictor.h
|
| index 9bcdd81fec861b45e1897c201c14f70d8aaced53..4588febb7875effa49ae3b11be25447fee945cb9 100644
|
| --- a/chrome/browser/predictors/loading_predictor.h
|
| +++ b/chrome/browser/predictors/loading_predictor.h
|
| @@ -5,12 +5,17 @@
|
| #ifndef CHROME_BROWSER_PREDICTORS_LOADING_PREDICTOR_H_
|
| #define CHROME_BROWSER_PREDICTORS_LOADING_PREDICTOR_H_
|
|
|
| +#include <map>
|
| #include <memory>
|
| +#include <utility>
|
|
|
| +#include "base/gtest_prod_util.h"
|
| #include "base/memory/weak_ptr.h"
|
| +#include "base/time/time.h"
|
| #include "chrome/browser/predictors/resource_prefetch_common.h"
|
| #include "chrome/browser/predictors/resource_prefetch_predictor.h"
|
| #include "components/keyed_service/core/keyed_service.h"
|
| +#include "url/gurl.h"
|
|
|
| class Profile;
|
|
|
| @@ -22,6 +27,9 @@ class ResourcePrefetchPredictor;
|
| // From a high-level request (GURL and motivation) and a database of historical
|
| // data, initiates predictive actions to speed up page loads.
|
| //
|
| +// Also listens to main frame requests/redirects/responses to initiate and
|
| +// cancel page load hints.
|
| +//
|
| // See ResourcePrefetchPredictor for a description of the resource prefetch
|
| // predictor.
|
| //
|
| @@ -48,8 +56,45 @@ class LoadingPredictor : public KeyedService,
|
| // KeyedService:
|
| void Shutdown() override;
|
|
|
| + void OnMainFrameRequest(
|
| + const ResourcePrefetchPredictor::URLRequestSummary& summary);
|
| + void OnMainFrameRedirect(
|
| + const ResourcePrefetchPredictor::URLRequestSummary& summary);
|
| + void OnMainFrameResponse(
|
| + const ResourcePrefetchPredictor::URLRequestSummary& summary);
|
| +
|
| private:
|
| + // Cancels an active hint, from its iterator inside |active_hints_|. If the
|
| + // iterator is .end(), does nothing. Returns the iterator after deletion of
|
| + // the entry.
|
| + std::map<GURL, base::TimeTicks>::iterator CancelActiveHint(
|
| + std::map<GURL, base::TimeTicks>::iterator hint_it);
|
| + void CleanupAbandonedHintsAndNavigations(const NavigationID& navigation_id);
|
| +
|
| + // For testing.
|
| + void set_mock_resource_prefetch_predictor(
|
| + std::unique_ptr<ResourcePrefetchPredictor> predictor) {
|
| + resource_prefetch_predictor_ = std::move(predictor);
|
| + }
|
| +
|
| + LoadingPredictorConfig config_;
|
| + Profile* profile_;
|
| std::unique_ptr<ResourcePrefetchPredictor> resource_prefetch_predictor_;
|
| + std::map<GURL, base::TimeTicks> active_hints_;
|
| + // Initial URL.
|
| + std::map<NavigationID, GURL> active_navigations_;
|
| +
|
| + friend class LoadingPredictorTest;
|
| + FRIEND_TEST_ALL_PREFIXES(LoadingPredictorTest,
|
| + TestMainFrameResponseCancelsHint);
|
| + FRIEND_TEST_ALL_PREFIXES(LoadingPredictorTest,
|
| + TestMainFrameRequestCancelsStaleNavigations);
|
| + FRIEND_TEST_ALL_PREFIXES(LoadingPredictorTest,
|
| + TestMainFrameResponseClearsNavigations);
|
| + FRIEND_TEST_ALL_PREFIXES(LoadingPredictorTest,
|
| + TestMainFrameRequestDoesntCancelExternalHint);
|
| + FRIEND_TEST_ALL_PREFIXES(LoadingPredictorTest,
|
| + TestDontTrackNonPrefetchableUrls);
|
|
|
| DISALLOW_COPY_AND_ASSIGN(LoadingPredictor);
|
| };
|
|
|