Add ICU message format support
[chromium-blink-merge.git] / chrome / browser / predictors / resource_prefetch_common.h
blob9525b2bea482df577d16c444744e85bc5c2a2acb
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_COMMON_H_
6 #define CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_COMMON_H_
8 #include "base/time/time.h"
9 #include "url/gurl.h"
11 class Profile;
13 namespace content {
14 class WebContents;
17 namespace predictors {
19 struct ResourcePrefetchPredictorConfig;
21 // Returns true if prefetching is enabled. And will initilize the |config|
22 // fields to the appropritate values.
23 bool IsSpeculativeResourcePrefetchingEnabled(
24 Profile* profile,
25 ResourcePrefetchPredictorConfig* config);
27 // Represents the type of key based on which prefetch data is stored.
28 enum PrefetchKeyType {
29 PREFETCH_KEY_TYPE_HOST,
30 PREFETCH_KEY_TYPE_URL
33 // Represents a single navigation for a render frame.
34 struct NavigationID {
35 // TODO(shishir): Maybe take process_id, frame_id and url as input in
36 // constructor.
37 NavigationID();
38 NavigationID(const NavigationID& other);
39 explicit NavigationID(content::WebContents* web_contents);
40 bool operator<(const NavigationID& rhs) const;
41 bool operator==(const NavigationID& rhs) const;
43 bool IsSameRenderer(const NavigationID& other) const;
45 // Returns true iff the render_process_id_, render_frame_id_ and
46 // frame_url_ has been set correctly.
47 bool is_valid() const;
49 int render_process_id;
50 int render_frame_id;
51 GURL main_frame_url;
53 // NOTE: Even though we store the creation time here, it is not used during
54 // comparison of two NavigationIDs because it cannot always be determined
55 // correctly.
56 base::TimeTicks creation_time;
59 // Represents the config for the resource prefetch prediction algorithm. It is
60 // useful for running experiments.
61 struct ResourcePrefetchPredictorConfig {
62 // Initializes the config with default values.
63 ResourcePrefetchPredictorConfig();
64 ~ResourcePrefetchPredictorConfig();
66 // The mode the prefetcher is running in. Forms a bit map.
67 enum Mode {
68 URL_LEARNING = 1 << 0,
69 HOST_LEARNING = 1 << 1,
70 URL_PREFETCHING = 1 << 2, // Should also turn on URL_LEARNING.
71 HOST_PRFETCHING = 1 << 3 // Should also turn on HOST_LEARNING.
73 int mode;
75 // Helpers to deal with mode.
76 bool IsLearningEnabled() const;
77 bool IsPrefetchingEnabled(Profile* profile) const;
78 bool IsURLLearningEnabled() const;
79 bool IsHostLearningEnabled() const;
80 bool IsURLPrefetchingEnabled(Profile* profile) const;
81 bool IsHostPrefetchingEnabled(Profile* profile) const;
83 bool IsLowConfidenceForTest() const;
84 bool IsHighConfidenceForTest() const;
85 bool IsMoreResourcesEnabledForTest() const;
86 bool IsSmallDBEnabledForTest() const;
88 // If a navigation hasn't seen a load complete event in this much time, it
89 // is considered abandoned.
90 size_t max_navigation_lifetime_seconds;
92 // Size of LRU caches for the URL and host data.
93 size_t max_urls_to_track;
94 size_t max_hosts_to_track;
96 // The number of times we should have seen a visit to this URL in history
97 // to start tracking it. This is to ensure we don't bother with oneoff
98 // entries. For hosts we track each one.
99 size_t min_url_visit_count;
101 // The maximum number of resources to store per entry.
102 size_t max_resources_per_entry;
103 // The number of consecutive misses after we stop tracking a resource URL.
104 size_t max_consecutive_misses;
106 // The minimum confidence (accuracy of hits) required for a resource to be
107 // prefetched.
108 float min_resource_confidence_to_trigger_prefetch;
109 // The minimum number of times we must have a URL on record to prefetch it.
110 size_t min_resource_hits_to_trigger_prefetch;
112 // Maximum number of prefetches that can be inflight for a single navigation.
113 size_t max_prefetches_inflight_per_navigation;
114 // Maximum number of prefetches that can be inflight for a host for a single
115 // navigation.
116 size_t max_prefetches_inflight_per_host_per_navigation;
119 } // namespace predictors
121 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_COMMON_H_