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

Side by Side Diff: chrome/browser/predictors/resource_prefetch_common.h

Issue 2847183002: predictors: Introduce GlowplugPredictor. (Closed)
Patch Set: GlowplugPredictor -> LoadingPredictor 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_COMMON_H_ 5 #ifndef CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_COMMON_H_
6 #define CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_COMMON_H_ 6 #define CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_COMMON_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include "base/feature_list.h" 10 #include "base/feature_list.h"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "components/sessions/core/session_id.h" 12 #include "components/sessions/core/session_id.h"
13 #include "url/gurl.h" 13 #include "url/gurl.h"
14 14
15 class Profile; 15 class Profile;
16 16
17 namespace content { 17 namespace content {
18 class WebContents; 18 class WebContents;
19 } 19 }
20 20
21 namespace predictors { 21 namespace predictors {
22 22
23 namespace internal {
24
25 bool IsPrefetchingEnabledInternal(Profile* profile, int mode, int mask);
26
27 } // namespace internal
28
23 extern const char kSpeculativeResourcePrefetchingFeatureName[]; 29 extern const char kSpeculativeResourcePrefetchingFeatureName[];
24 extern const char kModeParamName[]; 30 extern const char kModeParamName[];
25 extern const char kLearningMode[]; 31 extern const char kLearningMode[];
26 extern const char kExternalPrefetchingMode[]; 32 extern const char kExternalPrefetchingMode[];
27 extern const char kPrefetchingMode[]; 33 extern const char kPrefetchingMode[];
28 extern const char kEnableUrlLearningParamName[]; 34 extern const char kEnableUrlLearningParamName[];
29 extern const char kEnableManifestsParamName[]; 35 extern const char kEnableManifestsParamName[];
30 extern const char kEnableOriginLearningParamName[]; 36 extern const char kEnableOriginLearningParamName[];
31 extern const base::Feature kSpeculativeResourcePrefetchingFeature; 37 extern const base::Feature kSpeculativeResourcePrefetchingFeature;
32 38
33 struct ResourcePrefetchPredictorConfig; 39 struct LoadingPredictorConfig;
34 40
35 // Returns true if prefetching is enabled. And will initilize the |config| 41 // Returns true if prefetching is enabled, and initializes |config|, if not
36 // fields to the appropritate values. 42 // nullptr.
37 bool IsSpeculativeResourcePrefetchingEnabled( 43 bool IsSpeculativeResourcePrefetchingEnabled(Profile* profile,
38 Profile* profile, 44 LoadingPredictorConfig* config);
39 ResourcePrefetchPredictorConfig* config);
40 45
41 // Represents the type of key based on which prefetch data is stored. 46 // Represents the type of key based on which prefetch data is stored.
42 enum PrefetchKeyType { 47 enum PrefetchKeyType {
43 PREFETCH_KEY_TYPE_HOST, 48 PREFETCH_KEY_TYPE_HOST,
44 PREFETCH_KEY_TYPE_URL 49 PREFETCH_KEY_TYPE_URL
45 }; 50 };
46 51
47 // Indicates what caused the prefetch request.
48 enum class PrefetchOrigin { NAVIGATION, EXTERNAL };
49
50 // Represents a single navigation for a render frame. 52 // Represents a single navigation for a render frame.
51 struct NavigationID { 53 struct NavigationID {
52 NavigationID(); 54 NavigationID();
53 explicit NavigationID(content::WebContents* web_contents); 55 explicit NavigationID(content::WebContents* web_contents);
54 NavigationID(content::WebContents* web_contents, 56 NavigationID(content::WebContents* web_contents,
55 const GURL& main_frame_url, 57 const GURL& main_frame_url,
56 const base::TimeTicks& creation_time); 58 const base::TimeTicks& creation_time);
57 NavigationID(const NavigationID& other); 59 NavigationID(const NavigationID& other);
58 60
59 bool operator<(const NavigationID& rhs) const; 61 bool operator<(const NavigationID& rhs) const;
60 bool operator==(const NavigationID& rhs) const; 62 bool operator==(const NavigationID& rhs) const;
61 63
62 // Returns true iff the tab_id is valid and the Main frame URL is set. 64 // Returns true iff the tab_id is valid and the Main frame URL is set.
63 bool is_valid() const; 65 bool is_valid() const;
64 66
65 SessionID::id_type tab_id; 67 SessionID::id_type tab_id;
66 GURL main_frame_url; 68 GURL main_frame_url;
67 69
68 // NOTE: Even though we store the creation time here, it is not used during 70 // NOTE: Even though we store the creation time here, it is not used during
69 // comparison of two NavigationIDs because it cannot always be determined 71 // comparison of two NavigationIDs because it cannot always be determined
70 // correctly. 72 // correctly.
71 base::TimeTicks creation_time; 73 base::TimeTicks creation_time;
72 }; 74 };
73 75
74 // Represents the config for the resource prefetch prediction algorithm.
75 struct ResourcePrefetchPredictorConfig {
76 // Initializes the config with default values.
77 ResourcePrefetchPredictorConfig();
78 ResourcePrefetchPredictorConfig(const ResourcePrefetchPredictorConfig& other);
79 ~ResourcePrefetchPredictorConfig();
80
81 // The mode the prefetcher is running in. Forms a bit map.
82 enum Mode {
83 LEARNING = 1 << 0,
84 PREFETCHING_FOR_NAVIGATION = 1 << 2, // Should also turn on LEARNING.
85 PREFETCHING_FOR_EXTERNAL = 1 << 3 // Should also turn on LEARNING.
86 };
87 int mode;
88
89 // Helpers to deal with mode.
90 bool IsLearningEnabled() const;
91 bool IsPrefetchingEnabledForSomeOrigin(Profile* profile) const;
92 bool IsPrefetchingEnabledForOrigin(Profile* profile,
93 PrefetchOrigin origin) const;
94
95 bool IsLowConfidenceForTest() const;
96 bool IsHighConfidenceForTest() const;
97 bool IsMoreResourcesEnabledForTest() const;
98 bool IsSmallDBEnabledForTest() const;
99
100 // If a navigation hasn't seen a load complete event in this much time, it
101 // is considered abandoned.
102 size_t max_navigation_lifetime_seconds;
103
104 // Size of LRU caches for the URL and host data.
105 size_t max_urls_to_track;
106 size_t max_hosts_to_track;
107
108 // The number of times we should have seen a visit to this URL in history
109 // to start tracking it. This is to ensure we don't bother with oneoff
110 // entries. For hosts we track each one.
111 size_t min_url_visit_count;
112
113 // The maximum number of resources to store per entry.
114 size_t max_resources_per_entry;
115 // The maximum number of origins to store per entry.
116 size_t max_origins_per_entry;
117 // The number of consecutive misses after which we stop tracking a resource
118 // URL.
119 size_t max_consecutive_misses;
120 // The number of consecutive misses after which we stop tracking a redirect
121 // endpoint.
122 size_t max_redirect_consecutive_misses;
123
124 // The minimum confidence (accuracy of hits) required for a resource to be
125 // prefetched.
126 float min_resource_confidence_to_trigger_prefetch;
127 // The minimum number of times we must have a URL on record to prefetch it.
128 size_t min_resource_hits_to_trigger_prefetch;
129
130 // Maximum number of prefetches that can be inflight for a single navigation.
131 size_t max_prefetches_inflight_per_navigation;
132 // Maximum number of prefetches that can be inflight for a host for a single
133 // navigation.
134 size_t max_prefetches_inflight_per_host_per_navigation;
135 // True iff the predictor could use a url-based database.
136 bool is_url_learning_enabled;
137 // True iff the predictor could use manifests.
138 bool is_manifests_enabled;
139 // True iff origin-based learning is enabled.
140 bool is_origin_learning_enabled;
141 };
142
143 } // namespace predictors 76 } // namespace predictors
144 77
145 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_COMMON_H_ 78 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_COMMON_H_
OLDNEW
« no previous file with comments | « chrome/browser/predictors/predictor_database.cc ('k') | chrome/browser/predictors/resource_prefetch_common.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698