Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(319)

Unified Diff: chrome/browser/predictors/loading_predictor.h

Issue 2887133003: predictors: Refactor resource_prefetch_predictor triggering. (Closed)
Patch Set: . Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..de746f5cee09d0eabc345c2640c3cd524a75d1d7 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,34 @@ 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);
+
+ LoadingPredictorConfig config_;
+ Profile* profile_;
std::unique_ptr<ResourcePrefetchPredictor> resource_prefetch_predictor_;
+ std::map<GURL, base::TimeTicks> active_hints_;
+ // Initial URL, start time.
+ std::map<NavigationID, std::pair<GURL, base::TimeTicks>> active_navigations_;
+
+ FRIEND_TEST_ALL_PREFIXES(LoadingPredictorTest,
+ TestMainFrameResponseCancelHint);
+ FRIEND_TEST_ALL_PREFIXES(LoadingPredictorTest,
+ TestMainFrameRequestCancelStaleNavigations);
+ FRIEND_TEST_ALL_PREFIXES(LoadingPredictorTest,
+ TestMainFrameResponseClearsNavigation);
DISALLOW_COPY_AND_ASSIGN(LoadingPredictor);
};

Powered by Google App Engine
This is Rietveld 408576698