// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_ #define CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_ #include <stddef.h> #include <map> #include <memory> #include <optional> #include <set> #include <string> #include <vector> #include "base/gtest_prod_util.h" #include "base/memory/raw_ptr.h" #include "base/memory/weak_ptr.h" #include "base/scoped_observation.h" #include "base/task/cancelable_task_tracker.h" #include "base/time/time.h" #include "chrome/browser/predictors/lcp_critical_path_predictor/lcp_critical_path_predictor_util.h" #include "chrome/browser/predictors/loading_predictor_config.h" #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h" #include "components/history/core/browser/history_db_task.h" #include "components/history/core/browser/history_service.h" #include "components/history/core/browser/history_service_observer.h" #include "components/history/core/browser/history_types.h" #include "components/keyed_service/core/keyed_service.h" #include "components/optimization_guide/core/optimization_guide_decision.h" #include "components/sqlite_proto/key_value_data.h" #include "net/base/network_anonymization_key.h" #include "services/network/public/mojom/fetch_api.mojom-forward.h" #include "url/gurl.h" #include "url/origin.h" class PredictorsHandler; class Profile; namespace predictors { struct OriginRequestSummary; struct PageRequestSummary; struct LcppDataInputs; namespace internal { struct LastVisitTimeCompare { … }; } // namespace internal class TestObserver; class ResourcePrefetcherManager; // Stores all values needed to trigger a preconnect/preresolve job to a single // origin. struct PreconnectRequest { … }; struct PrefetchRequest { … }; // Stores a result of pre* prediction. The |requests| vector is the main // result for preconnects, while the |prefetch_requests| vector is the main // result for prefetches. Other fields are used for metrics reporting. struct PreconnectPrediction { … }; // Stores a result of a prediction from the optimization guide. struct OptimizationGuidePrediction { … }; // Contains logic for learning what can be prefetched and for kicking off // speculative prefetching. // - The class is a profile keyed service owned by the profile. // - All the non-static methods of this class need to be called on the UI // thread. // // The overall flow of the resource prefetching algorithm is as follows: // // * LoadingPredictorObserver - Listens for URL requests, responses and // redirects (client-side redirects are not supported) on the IO thread (via // ResourceDispatcherHostDelegate) and posts tasks to the // LoadingDataCollector on the UI thread. This is owned by the ProfileIOData // for the profile. // * ResourcePrefetchPredictorTables - Persists ResourcePrefetchPredictor data // to a sql database. Runs entirely on the DB sequence provided by the client // to the constructor of this class. Owned by the PredictorDatabase. // * ResourcePrefetchPredictor - Learns about resource requirements per URL in // the UI thread through the LoadingPredictorObserver and persists it to disk // in the DB sequence through the ResourcePrefetchPredictorTables. It // initiates resource prefetching using the ResourcePrefetcherManager. Owned // by profile. class ResourcePrefetchPredictor : public history::HistoryServiceObserver { … }; // An interface used to notify that data in the ResourcePrefetchPredictor // has changed. All methods are invoked on the UI thread. class TestObserver { … }; } // namespace predictors #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_