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

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

Issue 2545943003: Accessing navigation information via webcontents (Closed)
Patch Set: Post-Review Modifications Created 4 years 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 #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/common/chrome_switches.h" 13 #include "chrome/common/chrome_switches.h"
14 #include "components/prefs/pref_service.h" 14 #include "components/prefs/pref_service.h"
15 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
16 #include "content/public/browser/render_frame_host.h" 16 #include "content/public/browser/render_frame_host.h"
17 #include "content/public/browser/render_process_host.h" 17 #include "content/public/browser/render_process_host.h"
18 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
19 #include "net/url_request/url_request.h"
ahemery 2016/12/06 14:59:17 Relic from try&error
19 20
20 namespace predictors { 21 namespace predictors {
21 22
22 namespace { 23 namespace {
23 24
24 bool IsPrefetchingEnabledInternal(Profile* profile, int mode, int mask) { 25 bool IsPrefetchingEnabledInternal(Profile* profile, int mode, int mask) {
25 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 26 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
26 if ((mode & mask) == 0) 27 if ((mode & mask) == 0)
27 return false; 28 return false;
28 29
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 } 75 }
75 76
76 return false; 77 return false;
77 } 78 }
78 79
79 NavigationID::NavigationID() 80 NavigationID::NavigationID()
80 : render_process_id(-1), 81 : render_process_id(-1),
81 render_frame_id(-1) { 82 render_frame_id(-1) {
82 } 83 }
83 84
84 NavigationID::NavigationID(int render_process_id,
85 int render_frame_id,
86 const GURL& main_frame_url)
87 : render_process_id(render_process_id),
88 render_frame_id(render_frame_id),
89 main_frame_url(main_frame_url) {}
90
91 NavigationID::NavigationID(const NavigationID& other) 85 NavigationID::NavigationID(const NavigationID& other)
92 : render_process_id(other.render_process_id), 86 : render_process_id(other.render_process_id),
93 render_frame_id(other.render_frame_id), 87 render_frame_id(other.render_frame_id),
94 main_frame_url(other.main_frame_url), 88 main_frame_url(other.main_frame_url),
95 creation_time(other.creation_time) { 89 creation_time(other.creation_time) {
96 } 90 }
97 91
98 NavigationID::NavigationID(content::WebContents* web_contents) 92 NavigationID::NavigationID(content::WebContents* web_contents)
99 : render_process_id(web_contents->GetRenderProcessHost()->GetID()), 93 : render_process_id(web_contents->GetRenderProcessHost()->GetID()),
100 render_frame_id(web_contents->GetMainFrame()->GetRoutingID()), 94 render_frame_id(web_contents->GetMainFrame()->GetRoutingID()),
101 main_frame_url(web_contents->GetURL()) { 95 main_frame_url(web_contents->GetURL()) {
102 } 96 }
103 97
98 NavigationID::NavigationID(content::WebContents* web_contents,
99 const GURL& main_frame_url,
100 const base::TimeTicks& creation_time)
101 : render_process_id(web_contents->GetRenderProcessHost()->GetID()),
102 render_frame_id(web_contents->GetMainFrame()->GetRoutingID()),
103 main_frame_url(main_frame_url),
104 creation_time(creation_time) {
105 }
106
104 bool NavigationID::is_valid() const { 107 bool NavigationID::is_valid() const {
105 return render_process_id != -1 && render_frame_id != -1 && 108 return render_process_id != -1 && render_frame_id != -1 &&
106 !main_frame_url.is_empty(); 109 !main_frame_url.is_empty();
107 } 110 }
108 111
109 bool NavigationID::operator<(const NavigationID& rhs) const { 112 bool NavigationID::operator<(const NavigationID& rhs) const {
110 DCHECK(is_valid() && rhs.is_valid()); 113 DCHECK(is_valid() && rhs.is_valid());
111 return std::tie(render_process_id, render_frame_id, main_frame_url) < 114 return std::tie(render_process_id, render_frame_id, main_frame_url) <
112 std::tie(rhs.render_process_id, rhs.render_frame_id, rhs.main_frame_url); 115 std::tie(rhs.render_process_id, rhs.render_frame_id, rhs.main_frame_url);
113 } 116 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 185
183 bool ResourcePrefetchPredictorConfig::IsMoreResourcesEnabledForTest() const { 186 bool ResourcePrefetchPredictorConfig::IsMoreResourcesEnabledForTest() const {
184 return max_resources_per_entry == 100; 187 return max_resources_per_entry == 100;
185 } 188 }
186 189
187 bool ResourcePrefetchPredictorConfig::IsSmallDBEnabledForTest() const { 190 bool ResourcePrefetchPredictorConfig::IsSmallDBEnabledForTest() const {
188 return max_urls_to_track == 200 && max_hosts_to_track == 100; 191 return max_urls_to_track == 200 && max_hosts_to_track == 100;
189 } 192 }
190 193
191 } // namespace predictors 194 } // namespace predictors
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698