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

Side by Side Diff: chrome/browser/prerender/prerender_manager.cc

Issue 1077433002: Remove PrerenderLocalPredictor, part 1. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 8 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/prerender/prerender_manager.h" 5 #include "chrome/browser/prerender/prerender_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/memory/weak_ptr.h"
16 #include "base/metrics/histogram.h" 15 #include "base/metrics/histogram.h"
17 #include "base/prefs/pref_service.h"
18 #include "base/strings/utf_string_conversions.h"
19 #include "base/time/time.h" 16 #include "base/time/time.h"
20 #include "base/timer/elapsed_timer.h" 17 #include "base/timer/elapsed_timer.h"
21 #include "base/values.h" 18 #include "base/values.h"
22 #include "chrome/browser/browser_process.h" 19 #include "chrome/browser/browser_process.h"
23 #include "chrome/browser/chrome_notification_types.h" 20 #include "chrome/browser/chrome_notification_types.h"
24 #include "chrome/browser/net/chrome_cookie_notification_details.h"
25 #include "chrome/browser/net/prediction_options.h" 21 #include "chrome/browser/net/prediction_options.h"
26 #include "chrome/browser/predictors/predictor_database.h"
27 #include "chrome/browser/predictors/predictor_database_factory.h"
28 #include "chrome/browser/prerender/prerender_contents.h" 22 #include "chrome/browser/prerender/prerender_contents.h"
29 #include "chrome/browser/prerender/prerender_field_trial.h" 23 #include "chrome/browser/prerender/prerender_field_trial.h"
30 #include "chrome/browser/prerender/prerender_final_status.h" 24 #include "chrome/browser/prerender/prerender_final_status.h"
31 #include "chrome/browser/prerender/prerender_handle.h" 25 #include "chrome/browser/prerender/prerender_handle.h"
32 #include "chrome/browser/prerender/prerender_histograms.h" 26 #include "chrome/browser/prerender/prerender_histograms.h"
33 #include "chrome/browser/prerender/prerender_history.h" 27 #include "chrome/browser/prerender/prerender_history.h"
34 #include "chrome/browser/prerender/prerender_local_predictor.h"
35 #include "chrome/browser/prerender/prerender_manager_factory.h" 28 #include "chrome/browser/prerender/prerender_manager_factory.h"
36 #include "chrome/browser/prerender/prerender_tab_helper.h" 29 #include "chrome/browser/prerender/prerender_tab_helper.h"
37 #include "chrome/browser/prerender/prerender_util.h" 30 #include "chrome/browser/prerender/prerender_util.h"
38 #include "chrome/browser/profiles/profile.h" 31 #include "chrome/browser/profiles/profile.h"
39 #include "chrome/browser/search/search.h" 32 #include "chrome/browser/search/search.h"
40 #include "chrome/browser/tab_contents/tab_util.h" 33 #include "chrome/browser/tab_contents/tab_util.h"
41 #include "chrome/browser/ui/browser_navigator.h" 34 #include "chrome/browser/ui/browser_navigator.h"
42 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" 35 #include "chrome/browser/ui/tab_contents/core_tab_helper.h"
43 #include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h" 36 #include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h"
44 #include "chrome/common/chrome_switches.h" 37 #include "chrome/common/chrome_switches.h"
45 #include "chrome/common/prerender_messages.h"
46 #include "chrome/common/prerender_types.h" 38 #include "chrome/common/prerender_types.h"
47 #include "content/public/browser/browser_thread.h" 39 #include "content/public/browser/browser_thread.h"
48 #include "content/public/browser/devtools_agent_host.h" 40 #include "content/public/browser/devtools_agent_host.h"
49 #include "content/public/browser/navigation_controller.h" 41 #include "content/public/browser/navigation_controller.h"
50 #include "content/public/browser/notification_service.h" 42 #include "content/public/browser/notification_service.h"
51 #include "content/public/browser/notification_source.h" 43 #include "content/public/browser/notification_source.h"
52 #include "content/public/browser/render_frame_host.h" 44 #include "content/public/browser/render_frame_host.h"
53 #include "content/public/browser/render_process_host.h" 45 #include "content/public/browser/render_process_host.h"
54 #include "content/public/browser/render_view_host.h" 46 #include "content/public/browser/render_view_host.h"
55 #include "content/public/browser/resource_request_details.h" 47 #include "content/public/browser/resource_request_details.h"
56 #include "content/public/browser/session_storage_namespace.h" 48 #include "content/public/browser/session_storage_namespace.h"
57 #include "content/public/browser/site_instance.h" 49 #include "content/public/browser/site_instance.h"
58 #include "content/public/browser/web_contents.h" 50 #include "content/public/browser/web_contents.h"
59 #include "content/public/browser/web_contents_delegate.h" 51 #include "content/public/browser/web_contents_delegate.h"
60 #include "content/public/common/url_constants.h" 52 #include "content/public/common/url_constants.h"
61 #include "extensions/common/constants.h" 53 #include "extensions/common/constants.h"
62 #include "net/url_request/url_request_context.h"
63 #include "net/url_request/url_request_context_getter.h"
64 54
65 using content::BrowserThread; 55 using content::BrowserThread;
66 using content::RenderViewHost; 56 using content::RenderViewHost;
67 using content::SessionStorageNamespace; 57 using content::SessionStorageNamespace;
68 using content::WebContents; 58 using content::WebContents;
69 using predictors::LoggedInPredictorTable;
70 59
71 namespace prerender { 60 namespace prerender {
72 61
73 namespace { 62 namespace {
74 63
75 // Time interval at which periodic cleanups are performed. 64 // Time interval at which periodic cleanups are performed.
76 const int kPeriodicCleanupIntervalMs = 1000; 65 const int kPeriodicCleanupIntervalMs = 1000;
77 66
78 // Valid HTTP methods for prerendering. 67 // Valid HTTP methods for prerendering.
79 const char* const kValidHttpMethods[] = { 68 const char* const kValidHttpMethods[] = {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 final_status != FINAL_STATUS_WINDOW_OPENER && 102 final_status != FINAL_STATUS_WINDOW_OPENER &&
114 final_status != FINAL_STATUS_CACHE_OR_HISTORY_CLEARED && 103 final_status != FINAL_STATUS_CACHE_OR_HISTORY_CLEARED &&
115 final_status != FINAL_STATUS_CANCELLED && 104 final_status != FINAL_STATUS_CANCELLED &&
116 final_status != FINAL_STATUS_DEVTOOLS_ATTACHED && 105 final_status != FINAL_STATUS_DEVTOOLS_ATTACHED &&
117 final_status != FINAL_STATUS_CROSS_SITE_NAVIGATION_PENDING && 106 final_status != FINAL_STATUS_CROSS_SITE_NAVIGATION_PENDING &&
118 final_status != FINAL_STATUS_PAGE_BEING_CAPTURED && 107 final_status != FINAL_STATUS_PAGE_BEING_CAPTURED &&
119 final_status != FINAL_STATUS_NAVIGATION_UNCOMMITTED && 108 final_status != FINAL_STATUS_NAVIGATION_UNCOMMITTED &&
120 final_status != FINAL_STATUS_NON_EMPTY_BROWSING_INSTANCE; 109 final_status != FINAL_STATUS_NON_EMPTY_BROWSING_INSTANCE;
121 } 110 }
122 111
123 void CheckIfCookiesExistForDomainResultOnUIThread(
124 const net::CookieMonster::HasCookiesForETLDP1Callback& callback,
125 bool cookies_exist) {
126 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
127 callback.Run(cookies_exist);
128 }
129
130 void CheckIfCookiesExistForDomainResultOnIOThread(
131 const net::CookieMonster::HasCookiesForETLDP1Callback& callback,
132 bool cookies_exist) {
133 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
134 BrowserThread::PostTask(
135 BrowserThread::UI,
136 FROM_HERE,
137 base::Bind(&CheckIfCookiesExistForDomainResultOnUIThread,
138 callback,
139 cookies_exist));
140 }
141
142 void CheckIfCookiesExistForDomainOnIOThread(
143 net::URLRequestContextGetter* rq_context,
144 const std::string& domain_key,
145 const net::CookieMonster::HasCookiesForETLDP1Callback& callback) {
146 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
147 net::CookieStore* cookie_store =
148 rq_context->GetURLRequestContext()->cookie_store();
149 cookie_store->GetCookieMonster()->HasCookiesForETLDP1Async(
150 domain_key,
151 base::Bind(&CheckIfCookiesExistForDomainResultOnIOThread, callback));
152 }
153
154 } // namespace 112 } // namespace
155 113
156 class PrerenderManager::OnCloseWebContentsDeleter 114 class PrerenderManager::OnCloseWebContentsDeleter
157 : public content::WebContentsDelegate, 115 : public content::WebContentsDelegate,
158 public base::SupportsWeakPtr< 116 public base::SupportsWeakPtr<
159 PrerenderManager::OnCloseWebContentsDeleter> { 117 PrerenderManager::OnCloseWebContentsDeleter> {
160 public: 118 public:
161 OnCloseWebContentsDeleter(PrerenderManager* manager, 119 OnCloseWebContentsDeleter(PrerenderManager* manager,
162 WebContents* tab) 120 WebContents* tab)
163 : manager_(manager), 121 : manager_(manager),
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 base::TimeDelta::FromMilliseconds(kMinTimeBetweenPrerendersMs)), 189 base::TimeDelta::FromMilliseconds(kMinTimeBetweenPrerendersMs)),
232 prerender_history_(new PrerenderHistory(kHistoryLength)), 190 prerender_history_(new PrerenderHistory(kHistoryLength)),
233 histograms_(new PrerenderHistograms()), 191 histograms_(new PrerenderHistograms()),
234 profile_network_bytes_(0), 192 profile_network_bytes_(0),
235 last_recorded_profile_network_bytes_(0) { 193 last_recorded_profile_network_bytes_(0) {
236 // There are some assumptions that the PrerenderManager is on the UI thread. 194 // There are some assumptions that the PrerenderManager is on the UI thread.
237 // Any other checks simply make sure that the PrerenderManager is accessed on 195 // Any other checks simply make sure that the PrerenderManager is accessed on
238 // the same thread that it was created on. 196 // the same thread that it was created on.
239 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 197 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
240 198
241 if (IsLocalPredictorEnabled())
242 local_predictor_.reset(new PrerenderLocalPredictor(this));
243
244 if (IsLoggedInPredictorEnabled() && !profile_->IsOffTheRecord()) {
245 predictors::PredictorDatabase* predictor_db =
246 predictors::PredictorDatabaseFactory::GetForProfile(profile);
247 if (predictor_db) {
248 logged_in_predictor_table_ = predictor_db->logged_in_table();
249 scoped_ptr<LoggedInStateMap> new_state_map(new LoggedInStateMap);
250 LoggedInStateMap* new_state_map_ptr = new_state_map.get();
251 BrowserThread::PostTaskAndReply(
252 BrowserThread::DB, FROM_HERE,
253 base::Bind(&LoggedInPredictorTable::GetAllData,
254 logged_in_predictor_table_,
255 new_state_map_ptr),
256 base::Bind(&PrerenderManager::LoggedInPredictorDataReceived,
257 AsWeakPtr(),
258 base::Passed(&new_state_map)));
259 }
260 }
261
262 // Certain experiments override our default config_ values. 199 // Certain experiments override our default config_ values.
263 switch (PrerenderManager::GetMode()) { 200 switch (PrerenderManager::GetMode()) {
264 case PrerenderManager::PRERENDER_MODE_EXPERIMENT_MULTI_PRERENDER_GROUP: 201 case PrerenderManager::PRERENDER_MODE_EXPERIMENT_MULTI_PRERENDER_GROUP:
265 config_.max_link_concurrency = 4; 202 config_.max_link_concurrency = 4;
266 config_.max_link_concurrency_per_launcher = 2; 203 config_.max_link_concurrency_per_launcher = 2;
267 break; 204 break;
268 case PrerenderManager::PRERENDER_MODE_EXPERIMENT_15MIN_TTL_GROUP: 205 case PrerenderManager::PRERENDER_MODE_EXPERIMENT_15MIN_TTL_GROUP:
269 config_.time_to_live = base::TimeDelta::FromMinutes(15); 206 config_.time_to_live = base::TimeDelta::FromMinutes(15);
270 break; 207 break;
271 default: 208 default:
272 break; 209 break;
273 } 210 }
274 211
275 notification_registrar_.Add( 212 notification_registrar_.Add(
276 this, chrome::NOTIFICATION_COOKIE_CHANGED,
277 content::NotificationService::AllBrowserContextsAndSources());
278
279 notification_registrar_.Add(
280 this, chrome::NOTIFICATION_PROFILE_DESTROYED, 213 this, chrome::NOTIFICATION_PROFILE_DESTROYED,
281 content::Source<Profile>(profile_)); 214 content::Source<Profile>(profile_));
282 215
283 MediaCaptureDevicesDispatcher::GetInstance()->AddObserver(this); 216 MediaCaptureDevicesDispatcher::GetInstance()->AddObserver(this);
284 } 217 }
285 218
286 PrerenderManager::~PrerenderManager() { 219 PrerenderManager::~PrerenderManager() {
287 MediaCaptureDevicesDispatcher::GetInstance()->RemoveObserver(this); 220 MediaCaptureDevicesDispatcher::GetInstance()->RemoveObserver(this);
288 221
289 // The earlier call to KeyedService::Shutdown() should have 222 // The earlier call to KeyedService::Shutdown() should have
290 // emptied these vectors already. 223 // emptied these vectors already.
291 DCHECK(active_prerenders_.empty()); 224 DCHECK(active_prerenders_.empty());
292 DCHECK(to_delete_prerenders_.empty()); 225 DCHECK(to_delete_prerenders_.empty());
293 226
294 for (PrerenderProcessSet::const_iterator it = 227 for (PrerenderProcessSet::const_iterator it =
295 prerender_process_hosts_.begin(); 228 prerender_process_hosts_.begin();
296 it != prerender_process_hosts_.end(); 229 it != prerender_process_hosts_.end();
297 ++it) { 230 ++it) {
298 (*it)->RemoveObserver(this); 231 (*it)->RemoveObserver(this);
299 } 232 }
300 } 233 }
301 234
302 void PrerenderManager::Shutdown() { 235 void PrerenderManager::Shutdown() {
303 DestroyAllContents(FINAL_STATUS_MANAGER_SHUTDOWN); 236 DestroyAllContents(FINAL_STATUS_MANAGER_SHUTDOWN);
304 on_close_web_contents_deleters_.clear(); 237 on_close_web_contents_deleters_.clear();
305 // Must happen before |profile_| is set to NULL as
306 // |local_predictor_| accesses it.
307 if (local_predictor_)
308 local_predictor_->Shutdown();
309 profile_ = NULL; 238 profile_ = NULL;
310 239
311 DCHECK(active_prerenders_.empty()); 240 DCHECK(active_prerenders_.empty());
312 } 241 }
313 242
314 PrerenderHandle* PrerenderManager::AddPrerenderFromLinkRelPrerender( 243 PrerenderHandle* PrerenderManager::AddPrerenderFromLinkRelPrerender(
315 int process_id, 244 int process_id,
316 int route_id, 245 int route_id,
317 const GURL& url, 246 const GURL& url,
318 const uint32 rel_types, 247 const uint32 rel_types,
(...skipping 29 matching lines...) Expand all
348 PrerenderHandle* PrerenderManager::AddPrerenderFromOmnibox( 277 PrerenderHandle* PrerenderManager::AddPrerenderFromOmnibox(
349 const GURL& url, 278 const GURL& url,
350 SessionStorageNamespace* session_storage_namespace, 279 SessionStorageNamespace* session_storage_namespace,
351 const gfx::Size& size) { 280 const gfx::Size& size) {
352 if (!IsOmniboxEnabled(profile_)) 281 if (!IsOmniboxEnabled(profile_))
353 return NULL; 282 return NULL;
354 return AddPrerender(ORIGIN_OMNIBOX, url, content::Referrer(), size, 283 return AddPrerender(ORIGIN_OMNIBOX, url, content::Referrer(), size,
355 session_storage_namespace); 284 session_storage_namespace);
356 } 285 }
357 286
358 PrerenderHandle* PrerenderManager::AddPrerenderFromLocalPredictor(
359 const GURL& url,
360 SessionStorageNamespace* session_storage_namespace,
361 const gfx::Size& size) {
362 return AddPrerender(ORIGIN_LOCAL_PREDICTOR, url, content::Referrer(),
363 size, session_storage_namespace);
364 }
365
366 PrerenderHandle* PrerenderManager::AddPrerenderFromExternalRequest( 287 PrerenderHandle* PrerenderManager::AddPrerenderFromExternalRequest(
367 const GURL& url, 288 const GURL& url,
368 const content::Referrer& referrer, 289 const content::Referrer& referrer,
369 SessionStorageNamespace* session_storage_namespace, 290 SessionStorageNamespace* session_storage_namespace,
370 const gfx::Size& size) { 291 const gfx::Size& size) {
371 return AddPrerender(ORIGIN_EXTERNAL_REQUEST, url, referrer, size, 292 return AddPrerender(ORIGIN_EXTERNAL_REQUEST, url, referrer, size,
372 session_storage_namespace); 293 session_storage_namespace);
373 } 294 }
374 295
375 PrerenderHandle* PrerenderManager::AddPrerenderForInstant( 296 PrerenderHandle* PrerenderManager::AddPrerenderForInstant(
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 if (!IsEnabled()) 572 if (!IsEnabled())
652 return; 573 return;
653 574
654 histograms_->RecordPerceivedPageLoadTime( 575 histograms_->RecordPerceivedPageLoadTime(
655 origin, perceived_page_load_time, navigation_type, url); 576 origin, perceived_page_load_time, navigation_type, url);
656 577
657 if (navigation_type == NAVIGATION_TYPE_PRERENDERED) { 578 if (navigation_type == NAVIGATION_TYPE_PRERENDERED) {
658 histograms_->RecordPercentLoadDoneAtSwapin( 579 histograms_->RecordPercentLoadDoneAtSwapin(
659 origin, fraction_plt_elapsed_at_swap_in); 580 origin, fraction_plt_elapsed_at_swap_in);
660 } 581 }
661 if (local_predictor_) {
662 local_predictor_->OnPLTEventForURL(url, perceived_page_load_time);
663 }
664 } 582 }
665 583
666 // static 584 // static
667 PrerenderManager::PrerenderManagerMode PrerenderManager::GetMode() { 585 PrerenderManager::PrerenderManagerMode PrerenderManager::GetMode() {
668 return mode_; 586 return mode_;
669 } 587 }
670 588
671 // static 589 // static
672 void PrerenderManager::SetMode(PrerenderManagerMode mode) { 590 void PrerenderManager::SetMode(PrerenderManagerMode mode) {
673 mode_ = mode; 591 mode_ = mode;
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
1065 983
1066 last_prerender_start_time_ = GetCurrentTimeTicks(); 984 last_prerender_start_time_ = GetCurrentTimeTicks();
1067 985
1068 gfx::Size contents_size = 986 gfx::Size contents_size =
1069 size.IsEmpty() ? config_.default_tab_bounds.size() : size; 987 size.IsEmpty() ? config_.default_tab_bounds.size() : size;
1070 988
1071 prerender_contents->StartPrerendering(contents_size, 989 prerender_contents->StartPrerendering(contents_size,
1072 session_storage_namespace); 990 session_storage_namespace);
1073 991
1074 DCHECK(IsControlGroup(experiment) || 992 DCHECK(IsControlGroup(experiment) ||
1075 prerender_contents->prerendering_has_started() || 993 prerender_contents->prerendering_has_started());
1076 (origin == ORIGIN_LOCAL_PREDICTOR &&
1077 IsLocalPredictorPrerenderAlwaysControlEnabled()));
1078 994
1079 if (GetMode() == PRERENDER_MODE_EXPERIMENT_MULTI_PRERENDER_GROUP) 995 if (GetMode() == PRERENDER_MODE_EXPERIMENT_MULTI_PRERENDER_GROUP)
1080 histograms_->RecordConcurrency(active_prerenders_.size()); 996 histograms_->RecordConcurrency(active_prerenders_.size());
1081 997
1082 StartSchedulingPeriodicCleanups(); 998 StartSchedulingPeriodicCleanups();
1083 return prerender_handle; 999 return prerender_handle;
1084 } 1000 }
1085 1001
1086 void PrerenderManager::StartSchedulingPeriodicCleanups() { 1002 void PrerenderManager::StartSchedulingPeriodicCleanups() {
1087 DCHECK(CalledOnValidThread()); 1003 DCHECK(CalledOnValidThread());
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1137 1053
1138 void PrerenderManager::PostCleanupTask() { 1054 void PrerenderManager::PostCleanupTask() {
1139 DCHECK(CalledOnValidThread()); 1055 DCHECK(CalledOnValidThread());
1140 base::MessageLoop::current()->PostTask( 1056 base::MessageLoop::current()->PostTask(
1141 FROM_HERE, 1057 FROM_HERE,
1142 base::Bind(&PrerenderManager::PeriodicCleanup, AsWeakPtr())); 1058 base::Bind(&PrerenderManager::PeriodicCleanup, AsWeakPtr()));
1143 } 1059 }
1144 1060
1145 base::TimeTicks PrerenderManager::GetExpiryTimeForNewPrerender( 1061 base::TimeTicks PrerenderManager::GetExpiryTimeForNewPrerender(
1146 Origin origin) const { 1062 Origin origin) const {
1147 base::TimeDelta ttl = config_.time_to_live; 1063 return GetCurrentTimeTicks() + config_.time_to_live;
1148 if (origin == ORIGIN_LOCAL_PREDICTOR)
1149 ttl = base::TimeDelta::FromSeconds(GetLocalPredictorTTLSeconds());
1150 return GetCurrentTimeTicks() + ttl;
1151 } 1064 }
1152 1065
1153 base::TimeTicks PrerenderManager::GetExpiryTimeForNavigatedAwayPrerender() 1066 base::TimeTicks PrerenderManager::GetExpiryTimeForNavigatedAwayPrerender()
1154 const { 1067 const {
1155 return GetCurrentTimeTicks() + config_.abandon_time_to_live; 1068 return GetCurrentTimeTicks() + config_.abandon_time_to_live;
1156 } 1069 }
1157 1070
1158 void PrerenderManager::DeleteOldEntries() { 1071 void PrerenderManager::DeleteOldEntries() {
1159 DCHECK(CalledOnValidThread()); 1072 DCHECK(CalledOnValidThread());
1160 while (!active_prerenders_.empty()) { 1073 while (!active_prerenders_.empty()) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1213 return active_prerenders_.end(); 1126 return active_prerenders_.end();
1214 } 1127 }
1215 1128
1216 bool PrerenderManager::DoesRateLimitAllowPrerender(Origin origin) const { 1129 bool PrerenderManager::DoesRateLimitAllowPrerender(Origin origin) const {
1217 DCHECK(CalledOnValidThread()); 1130 DCHECK(CalledOnValidThread());
1218 base::TimeDelta elapsed_time = 1131 base::TimeDelta elapsed_time =
1219 GetCurrentTimeTicks() - last_prerender_start_time_; 1132 GetCurrentTimeTicks() - last_prerender_start_time_;
1220 histograms_->RecordTimeBetweenPrerenderRequests(origin, elapsed_time); 1133 histograms_->RecordTimeBetweenPrerenderRequests(origin, elapsed_time);
1221 if (!config_.rate_limit_enabled) 1134 if (!config_.rate_limit_enabled)
1222 return true; 1135 return true;
1223 // The LocalPredictor may issue multiple prerenders simultaneously (if so
1224 // configured), so no throttling.
1225 if (origin == ORIGIN_LOCAL_PREDICTOR)
1226 return true;
1227 return elapsed_time >= 1136 return elapsed_time >=
1228 base::TimeDelta::FromMilliseconds(kMinTimeBetweenPrerendersMs); 1137 base::TimeDelta::FromMilliseconds(kMinTimeBetweenPrerendersMs);
1229 } 1138 }
1230 1139
1231 void PrerenderManager::DeleteOldWebContents() { 1140 void PrerenderManager::DeleteOldWebContents() {
1232 while (!old_web_contents_list_.empty()) { 1141 while (!old_web_contents_list_.empty()) {
1233 WebContents* web_contents = old_web_contents_list_.front(); 1142 WebContents* web_contents = old_web_contents_list_.front();
1234 old_web_contents_list_.pop_front(); 1143 old_web_contents_list_.pop_front();
1235 // TODO(dominich): should we use Instant Unload Handler here? 1144 // TODO(dominich): should we use Instant Unload Handler here?
1236 delete web_contents; 1145 delete web_contents;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1314 RecordFinalStatusWithMatchCompleteStatus( 1223 RecordFinalStatusWithMatchCompleteStatus(
1315 origin, experiment_id, 1224 origin, experiment_id,
1316 PrerenderContents::MATCH_COMPLETE_DEFAULT, 1225 PrerenderContents::MATCH_COMPLETE_DEFAULT,
1317 final_status); 1226 final_status);
1318 } 1227 }
1319 1228
1320 void PrerenderManager::Observe(int type, 1229 void PrerenderManager::Observe(int type,
1321 const content::NotificationSource& source, 1230 const content::NotificationSource& source,
1322 const content::NotificationDetails& details) { 1231 const content::NotificationDetails& details) {
1323 switch (type) { 1232 switch (type) {
1324 case chrome::NOTIFICATION_COOKIE_CHANGED: {
1325 Profile* profile = content::Source<Profile>(source).ptr();
1326 if (!profile || !profile_->IsSameProfile(profile) ||
1327 profile->IsOffTheRecord()) {
1328 return;
1329 }
1330 CookieChanged(content::Details<ChromeCookieDetails>(details).ptr());
1331 break;
1332 }
1333 case chrome::NOTIFICATION_PROFILE_DESTROYED: 1233 case chrome::NOTIFICATION_PROFILE_DESTROYED:
1334 DestroyAllContents(FINAL_STATUS_PROFILE_DESTROYED); 1234 DestroyAllContents(FINAL_STATUS_PROFILE_DESTROYED);
1335 on_close_web_contents_deleters_.clear(); 1235 on_close_web_contents_deleters_.clear();
1336 break; 1236 break;
1337 default: 1237 default:
1338 NOTREACHED() << "Unexpected notification sent."; 1238 NOTREACHED() << "Unexpected notification sent.";
1339 break; 1239 break;
1340 } 1240 }
1341 } 1241 }
1342 1242
1343 void PrerenderManager::OnCreatingAudioStream(int render_process_id, 1243 void PrerenderManager::OnCreatingAudioStream(int render_process_id,
1344 int render_frame_id) { 1244 int render_frame_id) {
1345 content::RenderFrameHost* render_frame_host = 1245 content::RenderFrameHost* render_frame_host =
1346 content::RenderFrameHost::FromID(render_process_id, render_frame_id); 1246 content::RenderFrameHost::FromID(render_process_id, render_frame_id);
1347 WebContents* tab = WebContents::FromRenderFrameHost(render_frame_host); 1247 WebContents* tab = WebContents::FromRenderFrameHost(render_frame_host);
1348 if (!tab) 1248 if (!tab)
1349 return; 1249 return;
1350 1250
1351 PrerenderContents* prerender_contents = GetPrerenderContents(tab); 1251 PrerenderContents* prerender_contents = GetPrerenderContents(tab);
1352 if (!prerender_contents) 1252 if (!prerender_contents)
1353 return; 1253 return;
1354 1254
1355 prerender_contents->Destroy(prerender::FINAL_STATUS_CREATING_AUDIO_STREAM); 1255 prerender_contents->Destroy(prerender::FINAL_STATUS_CREATING_AUDIO_STREAM);
1356 } 1256 }
1357 1257
1358 void PrerenderManager::RecordLikelyLoginOnURL(const GURL& url) {
1359 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1360 if (!url.SchemeIsHTTPOrHTTPS())
1361 return;
1362 if (logged_in_predictor_table_.get()) {
1363 BrowserThread::PostTask(
1364 BrowserThread::DB,
1365 FROM_HERE,
1366 base::Bind(&LoggedInPredictorTable::AddDomainFromURL,
1367 logged_in_predictor_table_,
1368 url));
1369 }
1370 std::string key = LoggedInPredictorTable::GetKey(url);
1371 if (!logged_in_state_.get())
1372 return;
1373 if (logged_in_state_->count(key))
1374 return;
1375 (*logged_in_state_)[key] = base::Time::Now().ToInternalValue();
1376 }
1377
1378 void PrerenderManager::CheckIfLikelyLoggedInOnURL(
1379 const GURL& url,
1380 bool* lookup_result,
1381 bool* database_was_present,
1382 const base::Closure& result_cb) {
1383 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1384 if (!logged_in_predictor_table_.get()) {
1385 *database_was_present = false;
1386 *lookup_result = false;
1387 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, result_cb);
1388 return;
1389 }
1390 BrowserThread::PostTaskAndReply(
1391 BrowserThread::DB, FROM_HERE,
1392 base::Bind(&LoggedInPredictorTable::HasUserLoggedIn,
1393 logged_in_predictor_table_,
1394 url,
1395 lookup_result,
1396 database_was_present),
1397 result_cb);
1398 }
1399
1400
1401 void PrerenderManager::CookieChanged(ChromeCookieDetails* details) {
1402 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1403
1404 if (!logged_in_predictor_table_.get())
1405 return;
1406
1407 // We only care when a cookie has been removed.
1408 if (!details->removed)
1409 return;
1410
1411 std::string domain_key =
1412 LoggedInPredictorTable::GetKeyFromDomain(details->cookie->Domain());
1413
1414 // If we have no record of this domain as a potentially logged in domain,
1415 // nothing to do here.
1416 if (logged_in_state_.get() && logged_in_state_->count(domain_key) < 1)
1417 return;
1418
1419 net::URLRequestContextGetter* rq_context = profile_->GetRequestContext();
1420 if (!rq_context)
1421 return;
1422
1423 BrowserThread::PostTask(
1424 BrowserThread::IO, FROM_HERE,
1425 base::Bind(&CheckIfCookiesExistForDomainOnIOThread,
1426 base::Unretained(rq_context),
1427 domain_key,
1428 base::Bind(
1429 &PrerenderManager::CookieChangedAnyCookiesLeftLookupResult,
1430 AsWeakPtr(),
1431 domain_key)
1432 ));
1433 }
1434
1435 void PrerenderManager::CookieChangedAnyCookiesLeftLookupResult(
1436 const std::string& domain_key,
1437 bool cookies_exist) {
1438 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1439
1440 if (cookies_exist)
1441 return;
1442
1443 if (logged_in_predictor_table_.get()) {
1444 BrowserThread::PostTask(BrowserThread::DB,
1445 FROM_HERE,
1446 base::Bind(&LoggedInPredictorTable::DeleteDomain,
1447 logged_in_predictor_table_,
1448 domain_key));
1449 }
1450
1451 if (logged_in_state_.get())
1452 logged_in_state_->erase(domain_key);
1453 }
1454
1455 void PrerenderManager::LoggedInPredictorDataReceived(
1456 scoped_ptr<LoggedInStateMap> new_map) {
1457 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1458 logged_in_state_.swap(new_map);
1459 }
1460
1461 void PrerenderManager::RecordNetworkBytes(Origin origin, 1258 void PrerenderManager::RecordNetworkBytes(Origin origin,
1462 bool used, 1259 bool used,
1463 int64 prerender_bytes) { 1260 int64 prerender_bytes) {
1464 if (!ActuallyPrerendering()) 1261 if (!ActuallyPrerendering())
1465 return; 1262 return;
1466 int64 recent_profile_bytes = 1263 int64 recent_profile_bytes =
1467 profile_network_bytes_ - last_recorded_profile_network_bytes_; 1264 profile_network_bytes_ - last_recorded_profile_network_bytes_;
1468 last_recorded_profile_network_bytes_ = profile_network_bytes_; 1265 last_recorded_profile_network_bytes_ = profile_network_bytes_;
1469 DCHECK_GE(recent_profile_bytes, 0); 1266 DCHECK_GE(recent_profile_bytes, 0);
1470 histograms_->RecordNetworkBytes( 1267 histograms_->RecordNetworkBytes(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1502 } 1299 }
1503 1300
1504 void PrerenderManager::RenderProcessHostDestroyed( 1301 void PrerenderManager::RenderProcessHostDestroyed(
1505 content::RenderProcessHost* host) { 1302 content::RenderProcessHost* host) {
1506 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1303 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1507 size_t erased = prerender_process_hosts_.erase(host); 1304 size_t erased = prerender_process_hosts_.erase(host);
1508 DCHECK_EQ(1u, erased); 1305 DCHECK_EQ(1u, erased);
1509 } 1306 }
1510 1307
1511 } // namespace prerender 1308 } // namespace prerender
OLDNEW
« no previous file with comments | « chrome/browser/prerender/prerender_manager.h ('k') | chrome/browser/prerender/prerender_origin.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698