| OLD | NEW |
| 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 #include "chrome/browser/predictors/resource_prefetch_common.h" | 5 #include "chrome/browser/predictors/resource_prefetch_common.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <tuple> | 8 #include <tuple> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "chrome/browser/net/prediction_options.h" | 11 #include "chrome/browser/net/prediction_options.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/sessions/session_tab_helper.h" |
| 13 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
| 14 #include "components/prefs/pref_service.h" | 15 #include "components/prefs/pref_service.h" |
| 15 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/browser/render_frame_host.h" | |
| 17 #include "content/public/browser/render_process_host.h" | |
| 18 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 19 | 18 |
| 20 namespace predictors { | 19 namespace predictors { |
| 21 | 20 |
| 22 namespace { | 21 namespace { |
| 23 | 22 |
| 24 bool IsPrefetchingEnabledInternal(Profile* profile, int mode, int mask) { | 23 bool IsPrefetchingEnabledInternal(Profile* profile, int mode, int mask) { |
| 25 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 24 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 26 if ((mode & mask) == 0) | 25 if ((mode & mask) == 0) |
| 27 return false; | 26 return false; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 ResourcePrefetchPredictorConfig::LEARNING | | 68 ResourcePrefetchPredictorConfig::LEARNING | |
| 70 ResourcePrefetchPredictorConfig::PREFETCHING_FOR_NAVIGATION | | 69 ResourcePrefetchPredictorConfig::PREFETCHING_FOR_NAVIGATION | |
| 71 ResourcePrefetchPredictorConfig::PREFETCHING_FOR_EXTERNAL; | 70 ResourcePrefetchPredictorConfig::PREFETCHING_FOR_EXTERNAL; |
| 72 return true; | 71 return true; |
| 73 } | 72 } |
| 74 } | 73 } |
| 75 | 74 |
| 76 return false; | 75 return false; |
| 77 } | 76 } |
| 78 | 77 |
| 79 NavigationID::NavigationID() | 78 NavigationID::NavigationID() : tab_id(-1) {} |
| 80 : render_process_id(-1), | |
| 81 render_frame_id(-1) { | |
| 82 } | |
| 83 | 79 |
| 84 NavigationID::NavigationID(const NavigationID& other) | 80 NavigationID::NavigationID(const NavigationID& other) |
| 85 : render_process_id(other.render_process_id), | 81 : tab_id(other.tab_id), |
| 86 render_frame_id(other.render_frame_id), | |
| 87 main_frame_url(other.main_frame_url), | 82 main_frame_url(other.main_frame_url), |
| 88 creation_time(other.creation_time) { | 83 creation_time(other.creation_time) {} |
| 89 } | |
| 90 | 84 |
| 91 NavigationID::NavigationID(content::WebContents* web_contents) | 85 NavigationID::NavigationID(content::WebContents* web_contents) |
| 92 : render_process_id(web_contents->GetRenderProcessHost()->GetID()), | 86 : tab_id(SessionTabHelper::IdForTab(web_contents)), |
| 93 render_frame_id(web_contents->GetMainFrame()->GetRoutingID()), | 87 main_frame_url(web_contents->GetURL()), |
| 94 main_frame_url(web_contents->GetURL()) { | 88 creation_time(base::TimeTicks::Now()) {} |
| 95 } | |
| 96 | 89 |
| 97 NavigationID::NavigationID(content::WebContents* web_contents, | 90 NavigationID::NavigationID(content::WebContents* web_contents, |
| 98 const GURL& main_frame_url, | 91 const GURL& main_frame_url, |
| 99 const base::TimeTicks& creation_time) | 92 const base::TimeTicks& creation_time) |
| 100 : render_process_id(web_contents->GetRenderProcessHost()->GetID()), | 93 : tab_id(SessionTabHelper::IdForTab(web_contents)), |
| 101 render_frame_id(web_contents->GetMainFrame()->GetRoutingID()), | |
| 102 main_frame_url(main_frame_url), | 94 main_frame_url(main_frame_url), |
| 103 creation_time(creation_time) {} | 95 creation_time(creation_time) {} |
| 104 | 96 |
| 105 bool NavigationID::is_valid() const { | 97 bool NavigationID::is_valid() const { |
| 106 return render_process_id != -1 && render_frame_id != -1 && | 98 return tab_id != -1 && !main_frame_url.is_empty(); |
| 107 !main_frame_url.is_empty(); | |
| 108 } | 99 } |
| 109 | 100 |
| 110 bool NavigationID::operator<(const NavigationID& rhs) const { | 101 bool NavigationID::operator<(const NavigationID& rhs) const { |
| 111 DCHECK(is_valid() && rhs.is_valid()); | 102 DCHECK(is_valid() && rhs.is_valid()); |
| 112 return std::tie(render_process_id, render_frame_id, main_frame_url) < | 103 return std::tie(tab_id, main_frame_url) < |
| 113 std::tie(rhs.render_process_id, rhs.render_frame_id, rhs.main_frame_url); | 104 std::tie(rhs.tab_id, rhs.main_frame_url); |
| 114 } | 105 } |
| 115 | 106 |
| 116 bool NavigationID::operator==(const NavigationID& rhs) const { | 107 bool NavigationID::operator==(const NavigationID& rhs) const { |
| 117 DCHECK(is_valid() && rhs.is_valid()); | 108 DCHECK(is_valid() && rhs.is_valid()); |
| 118 return IsSameRenderer(rhs) && main_frame_url == rhs.main_frame_url; | 109 return tab_id == rhs.tab_id && main_frame_url == rhs.main_frame_url; |
| 119 } | |
| 120 | |
| 121 bool NavigationID::IsSameRenderer(const NavigationID& other) const { | |
| 122 DCHECK(is_valid() && other.is_valid()); | |
| 123 return render_process_id == other.render_process_id && | |
| 124 render_frame_id == other.render_frame_id; | |
| 125 } | 110 } |
| 126 | 111 |
| 127 ResourcePrefetchPredictorConfig::ResourcePrefetchPredictorConfig() | 112 ResourcePrefetchPredictorConfig::ResourcePrefetchPredictorConfig() |
| 128 : mode(0), | 113 : mode(0), |
| 129 max_navigation_lifetime_seconds(60), | 114 max_navigation_lifetime_seconds(60), |
| 130 max_urls_to_track(500), | 115 max_urls_to_track(500), |
| 131 max_hosts_to_track(200), | 116 max_hosts_to_track(200), |
| 132 min_url_visit_count(2), | 117 min_url_visit_count(2), |
| 133 max_resources_per_entry(50), | 118 max_resources_per_entry(50), |
| 134 max_consecutive_misses(3), | 119 max_consecutive_misses(3), |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 | 168 |
| 184 bool ResourcePrefetchPredictorConfig::IsMoreResourcesEnabledForTest() const { | 169 bool ResourcePrefetchPredictorConfig::IsMoreResourcesEnabledForTest() const { |
| 185 return max_resources_per_entry == 100; | 170 return max_resources_per_entry == 100; |
| 186 } | 171 } |
| 187 | 172 |
| 188 bool ResourcePrefetchPredictorConfig::IsSmallDBEnabledForTest() const { | 173 bool ResourcePrefetchPredictorConfig::IsSmallDBEnabledForTest() const { |
| 189 return max_urls_to_track == 200 && max_hosts_to_track == 100; | 174 return max_urls_to_track == 200 && max_hosts_to_track == 100; |
| 190 } | 175 } |
| 191 | 176 |
| 192 } // namespace predictors | 177 } // namespace predictors |
| OLD | NEW |