OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_GLOWPLUG_CONFIG_H_ |
6 #define CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_COMMON_H_ | 6 #define CHROME_BROWSER_PREDICTORS_GLOWPLUG_CONFIG_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <cstddef> |
9 | |
10 #include "base/feature_list.h" | |
11 #include "base/time/time.h" | |
12 #include "components/sessions/core/session_id.h" | |
13 #include "url/gurl.h" | |
14 | 9 |
15 class Profile; | 10 class Profile; |
16 | 11 |
17 namespace content { | |
18 class WebContents; | |
19 } | |
20 | |
21 namespace predictors { | 12 namespace predictors { |
22 | 13 |
23 extern const char kSpeculativeResourcePrefetchingFeatureName[]; | 14 struct GlowplugPredictorConfig; |
24 extern const char kModeParamName[]; | |
25 extern const char kLearningMode[]; | |
26 extern const char kExternalPrefetchingMode[]; | |
27 extern const char kPrefetchingMode[]; | |
28 extern const char kEnableUrlLearningParamName[]; | |
29 extern const char kEnableManifestsParamName[]; | |
30 extern const char kEnableOriginLearningParamName[]; | |
31 extern const base::Feature kSpeculativeResourcePrefetchingFeature; | |
32 | 15 |
33 struct ResourcePrefetchPredictorConfig; | 16 // Returns whether glowplug is enabled, and populate |config|, if not nullptr. |
34 | 17 bool IsGlowplugEnabled(Profile* profile, GlowplugPredictorConfig* config); |
35 // Returns true if prefetching is enabled. And will initilize the |config| | |
36 // fields to the appropritate values. | |
37 bool IsSpeculativeResourcePrefetchingEnabled( | |
38 Profile* profile, | |
39 ResourcePrefetchPredictorConfig* config); | |
40 | |
41 // Represents the type of key based on which prefetch data is stored. | |
42 enum PrefetchKeyType { | |
43 PREFETCH_KEY_TYPE_HOST, | |
44 PREFETCH_KEY_TYPE_URL | |
45 }; | |
46 | 18 |
47 // Indicates what caused the prefetch request. | 19 // Indicates what caused the prefetch request. |
48 enum class PrefetchOrigin { NAVIGATION, EXTERNAL }; | 20 enum class PrefetchOrigin { NAVIGATION, EXTERNAL }; |
49 | 21 |
50 // Represents a single navigation for a render frame. | 22 // Represents the config for the Glowplug predictor. |
51 struct NavigationID { | 23 struct GlowplugPredictorConfig { |
alexilin
2017/05/11 16:53:12
I don't see clear benefits of moving it outside of
Benoit L
2017/05/12 12:12:52
The goal is to have a global object to configure g
alexilin
2017/05/12 14:26:45
Cool, makes sense. Thanks!
| |
52 NavigationID(); | |
53 explicit NavigationID(content::WebContents* web_contents); | |
54 NavigationID(content::WebContents* web_contents, | |
55 const GURL& main_frame_url, | |
56 const base::TimeTicks& creation_time); | |
57 NavigationID(const NavigationID& other); | |
58 | |
59 bool operator<(const NavigationID& rhs) const; | |
60 bool operator==(const NavigationID& rhs) const; | |
61 | |
62 // Returns true iff the tab_id is valid and the Main frame URL is set. | |
63 bool is_valid() const; | |
64 | |
65 SessionID::id_type tab_id; | |
66 GURL main_frame_url; | |
67 | |
68 // 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 | |
70 // correctly. | |
71 base::TimeTicks creation_time; | |
72 }; | |
73 | |
74 // Represents the config for the resource prefetch prediction algorithm. | |
75 struct ResourcePrefetchPredictorConfig { | |
76 // Initializes the config with default values. | 24 // Initializes the config with default values. |
77 ResourcePrefetchPredictorConfig(); | 25 GlowplugPredictorConfig(); |
78 ResourcePrefetchPredictorConfig(const ResourcePrefetchPredictorConfig& other); | 26 GlowplugPredictorConfig(const GlowplugPredictorConfig& other); |
79 ~ResourcePrefetchPredictorConfig(); | 27 ~GlowplugPredictorConfig(); |
80 | 28 |
81 // The mode the prefetcher is running in. Forms a bit map. | 29 // The mode the prefetcher is running in. Forms a bit map. |
82 enum Mode { | 30 enum Mode { |
83 LEARNING = 1 << 0, | 31 LEARNING = 1 << 0, |
84 PREFETCHING_FOR_NAVIGATION = 1 << 2, // Should also turn on LEARNING. | 32 PREFETCHING_FOR_NAVIGATION = 1 << 2, // Should also turn on LEARNING. |
85 PREFETCHING_FOR_EXTERNAL = 1 << 3 // Should also turn on LEARNING. | 33 PREFETCHING_FOR_EXTERNAL = 1 << 3 // Should also turn on LEARNING. |
86 }; | 34 }; |
87 int mode; | 35 int mode; |
88 | 36 |
89 // Helpers to deal with mode. | 37 // Helpers to deal with mode. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
135 // True iff the predictor could use a url-based database. | 83 // True iff the predictor could use a url-based database. |
136 bool is_url_learning_enabled; | 84 bool is_url_learning_enabled; |
137 // True iff the predictor could use manifests. | 85 // True iff the predictor could use manifests. |
138 bool is_manifests_enabled; | 86 bool is_manifests_enabled; |
139 // True iff origin-based learning is enabled. | 87 // True iff origin-based learning is enabled. |
140 bool is_origin_learning_enabled; | 88 bool is_origin_learning_enabled; |
141 }; | 89 }; |
142 | 90 |
143 } // namespace predictors | 91 } // namespace predictors |
144 | 92 |
145 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_COMMON_H_ | 93 #endif // CHROME_BROWSER_PREDICTORS_GLOWPLUG_CONFIG_H_ |
OLD | NEW |