Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" | 15 #include "base/memory/weak_ptr.h" |
|
mmenke
2015/04/09 16:29:05
Not needed (In header)
davidben
2015/04/09 20:43:00
Done.
| |
| 16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
| 17 #include "base/prefs/pref_service.h" | 17 #include "base/prefs/pref_service.h" |
|
mmenke
2015/04/09 16:29:05
Not needed? (Actually wasn't needed before, eithe
davidben
2015/04/09 20:43:00
Done.
| |
| 18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
|
mmenke
2015/04/09 16:29:05
Is this used anywhere?
davidben
2015/04/09 20:43:00
Done.
| |
| 19 #include "base/time/time.h" | 19 #include "base/time/time.h" |
| 20 #include "base/timer/elapsed_timer.h" | 20 #include "base/timer/elapsed_timer.h" |
| 21 #include "base/values.h" | 21 #include "base/values.h" |
| 22 #include "chrome/browser/browser_process.h" | 22 #include "chrome/browser/browser_process.h" |
| 23 #include "chrome/browser/chrome_notification_types.h" | 23 #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" | 24 #include "chrome/browser/net/prediction_options.h" |
| 26 #include "chrome/browser/predictors/predictor_database.h" | 25 #include "chrome/browser/predictors/predictor_database.h" |
| 27 #include "chrome/browser/predictors/predictor_database_factory.h" | 26 #include "chrome/browser/predictors/predictor_database_factory.h" |
|
mmenke
2015/04/09 16:29:04
I don't think we need these three any more.
davidben
2015/04/09 20:43:00
Looks like prediction_options is still used. Other
| |
| 28 #include "chrome/browser/prerender/prerender_contents.h" | 27 #include "chrome/browser/prerender/prerender_contents.h" |
| 29 #include "chrome/browser/prerender/prerender_field_trial.h" | 28 #include "chrome/browser/prerender/prerender_field_trial.h" |
| 30 #include "chrome/browser/prerender/prerender_final_status.h" | 29 #include "chrome/browser/prerender/prerender_final_status.h" |
| 31 #include "chrome/browser/prerender/prerender_handle.h" | 30 #include "chrome/browser/prerender/prerender_handle.h" |
| 32 #include "chrome/browser/prerender/prerender_histograms.h" | 31 #include "chrome/browser/prerender/prerender_histograms.h" |
| 33 #include "chrome/browser/prerender/prerender_history.h" | 32 #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" | 33 #include "chrome/browser/prerender/prerender_manager_factory.h" |
| 36 #include "chrome/browser/prerender/prerender_tab_helper.h" | 34 #include "chrome/browser/prerender/prerender_tab_helper.h" |
| 37 #include "chrome/browser/prerender/prerender_util.h" | 35 #include "chrome/browser/prerender/prerender_util.h" |
| 38 #include "chrome/browser/profiles/profile.h" | 36 #include "chrome/browser/profiles/profile.h" |
| 39 #include "chrome/browser/search/search.h" | 37 #include "chrome/browser/search/search.h" |
| 40 #include "chrome/browser/tab_contents/tab_util.h" | 38 #include "chrome/browser/tab_contents/tab_util.h" |
| 41 #include "chrome/browser/ui/browser_navigator.h" | 39 #include "chrome/browser/ui/browser_navigator.h" |
| 42 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" | 40 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" |
| 43 #include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h" | 41 #include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h" |
| 44 #include "chrome/common/chrome_switches.h" | 42 #include "chrome/common/chrome_switches.h" |
| 45 #include "chrome/common/prerender_messages.h" | 43 #include "chrome/common/prerender_messages.h" |
|
mmenke
2015/04/09 16:29:05
Don't think this has been used in this file for a
davidben
2015/04/09 20:43:00
Done.
| |
| 46 #include "chrome/common/prerender_types.h" | 44 #include "chrome/common/prerender_types.h" |
| 47 #include "content/public/browser/browser_thread.h" | 45 #include "content/public/browser/browser_thread.h" |
| 48 #include "content/public/browser/devtools_agent_host.h" | 46 #include "content/public/browser/devtools_agent_host.h" |
| 49 #include "content/public/browser/navigation_controller.h" | 47 #include "content/public/browser/navigation_controller.h" |
| 50 #include "content/public/browser/notification_service.h" | 48 #include "content/public/browser/notification_service.h" |
| 51 #include "content/public/browser/notification_source.h" | 49 #include "content/public/browser/notification_source.h" |
| 52 #include "content/public/browser/render_frame_host.h" | 50 #include "content/public/browser/render_frame_host.h" |
| 53 #include "content/public/browser/render_process_host.h" | 51 #include "content/public/browser/render_process_host.h" |
| 54 #include "content/public/browser/render_view_host.h" | 52 #include "content/public/browser/render_view_host.h" |
| 55 #include "content/public/browser/resource_request_details.h" | 53 #include "content/public/browser/resource_request_details.h" |
| 56 #include "content/public/browser/session_storage_namespace.h" | 54 #include "content/public/browser/session_storage_namespace.h" |
| 57 #include "content/public/browser/site_instance.h" | 55 #include "content/public/browser/site_instance.h" |
| 58 #include "content/public/browser/web_contents.h" | 56 #include "content/public/browser/web_contents.h" |
| 59 #include "content/public/browser/web_contents_delegate.h" | 57 #include "content/public/browser/web_contents_delegate.h" |
| 60 #include "content/public/common/url_constants.h" | 58 #include "content/public/common/url_constants.h" |
| 61 #include "extensions/common/constants.h" | 59 #include "extensions/common/constants.h" |
| 62 #include "net/url_request/url_request_context.h" | 60 #include "net/url_request/url_request_context.h" |
| 63 #include "net/url_request/url_request_context_getter.h" | 61 #include "net/url_request/url_request_context_getter.h" |
|
mmenke
2015/04/09 16:29:05
I don't think we need these two any more.
davidben
2015/04/09 20:43:00
Done.
| |
| 64 | 62 |
| 65 using content::BrowserThread; | 63 using content::BrowserThread; |
| 66 using content::RenderViewHost; | 64 using content::RenderViewHost; |
| 67 using content::SessionStorageNamespace; | 65 using content::SessionStorageNamespace; |
| 68 using content::WebContents; | 66 using content::WebContents; |
| 69 using predictors::LoggedInPredictorTable; | |
| 70 | 67 |
| 71 namespace prerender { | 68 namespace prerender { |
| 72 | 69 |
| 73 namespace { | 70 namespace { |
| 74 | 71 |
| 75 // Time interval at which periodic cleanups are performed. | 72 // Time interval at which periodic cleanups are performed. |
| 76 const int kPeriodicCleanupIntervalMs = 1000; | 73 const int kPeriodicCleanupIntervalMs = 1000; |
| 77 | 74 |
| 78 // Valid HTTP methods for prerendering. | 75 // Valid HTTP methods for prerendering. |
| 79 const char* const kValidHttpMethods[] = { | 76 const char* const kValidHttpMethods[] = { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 final_status != FINAL_STATUS_WINDOW_OPENER && | 110 final_status != FINAL_STATUS_WINDOW_OPENER && |
| 114 final_status != FINAL_STATUS_CACHE_OR_HISTORY_CLEARED && | 111 final_status != FINAL_STATUS_CACHE_OR_HISTORY_CLEARED && |
| 115 final_status != FINAL_STATUS_CANCELLED && | 112 final_status != FINAL_STATUS_CANCELLED && |
| 116 final_status != FINAL_STATUS_DEVTOOLS_ATTACHED && | 113 final_status != FINAL_STATUS_DEVTOOLS_ATTACHED && |
| 117 final_status != FINAL_STATUS_CROSS_SITE_NAVIGATION_PENDING && | 114 final_status != FINAL_STATUS_CROSS_SITE_NAVIGATION_PENDING && |
| 118 final_status != FINAL_STATUS_PAGE_BEING_CAPTURED && | 115 final_status != FINAL_STATUS_PAGE_BEING_CAPTURED && |
| 119 final_status != FINAL_STATUS_NAVIGATION_UNCOMMITTED && | 116 final_status != FINAL_STATUS_NAVIGATION_UNCOMMITTED && |
| 120 final_status != FINAL_STATUS_NON_EMPTY_BROWSING_INSTANCE; | 117 final_status != FINAL_STATUS_NON_EMPTY_BROWSING_INSTANCE; |
| 121 } | 118 } |
| 122 | 119 |
| 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 | 120 } // namespace |
| 155 | 121 |
| 156 class PrerenderManager::OnCloseWebContentsDeleter | 122 class PrerenderManager::OnCloseWebContentsDeleter |
| 157 : public content::WebContentsDelegate, | 123 : public content::WebContentsDelegate, |
| 158 public base::SupportsWeakPtr< | 124 public base::SupportsWeakPtr< |
| 159 PrerenderManager::OnCloseWebContentsDeleter> { | 125 PrerenderManager::OnCloseWebContentsDeleter> { |
| 160 public: | 126 public: |
| 161 OnCloseWebContentsDeleter(PrerenderManager* manager, | 127 OnCloseWebContentsDeleter(PrerenderManager* manager, |
| 162 WebContents* tab) | 128 WebContents* tab) |
| 163 : manager_(manager), | 129 : manager_(manager), |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 231 base::TimeDelta::FromMilliseconds(kMinTimeBetweenPrerendersMs)), | 197 base::TimeDelta::FromMilliseconds(kMinTimeBetweenPrerendersMs)), |
| 232 prerender_history_(new PrerenderHistory(kHistoryLength)), | 198 prerender_history_(new PrerenderHistory(kHistoryLength)), |
| 233 histograms_(new PrerenderHistograms()), | 199 histograms_(new PrerenderHistograms()), |
| 234 profile_network_bytes_(0), | 200 profile_network_bytes_(0), |
| 235 last_recorded_profile_network_bytes_(0) { | 201 last_recorded_profile_network_bytes_(0) { |
| 236 // There are some assumptions that the PrerenderManager is on the UI thread. | 202 // 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 | 203 // Any other checks simply make sure that the PrerenderManager is accessed on |
| 238 // the same thread that it was created on. | 204 // the same thread that it was created on. |
| 239 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 205 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 240 | 206 |
| 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. | 207 // Certain experiments override our default config_ values. |
| 263 switch (PrerenderManager::GetMode()) { | 208 switch (PrerenderManager::GetMode()) { |
| 264 case PrerenderManager::PRERENDER_MODE_EXPERIMENT_MULTI_PRERENDER_GROUP: | 209 case PrerenderManager::PRERENDER_MODE_EXPERIMENT_MULTI_PRERENDER_GROUP: |
| 265 config_.max_link_concurrency = 4; | 210 config_.max_link_concurrency = 4; |
| 266 config_.max_link_concurrency_per_launcher = 2; | 211 config_.max_link_concurrency_per_launcher = 2; |
| 267 break; | 212 break; |
| 268 case PrerenderManager::PRERENDER_MODE_EXPERIMENT_15MIN_TTL_GROUP: | 213 case PrerenderManager::PRERENDER_MODE_EXPERIMENT_15MIN_TTL_GROUP: |
| 269 config_.time_to_live = base::TimeDelta::FromMinutes(15); | 214 config_.time_to_live = base::TimeDelta::FromMinutes(15); |
| 270 break; | 215 break; |
| 271 default: | 216 default: |
| 272 break; | 217 break; |
| 273 } | 218 } |
| 274 | 219 |
| 275 notification_registrar_.Add( | 220 notification_registrar_.Add( |
| 276 this, chrome::NOTIFICATION_COOKIE_CHANGED, | |
| 277 content::NotificationService::AllBrowserContextsAndSources()); | |
| 278 | |
| 279 notification_registrar_.Add( | |
| 280 this, chrome::NOTIFICATION_PROFILE_DESTROYED, | 221 this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
| 281 content::Source<Profile>(profile_)); | 222 content::Source<Profile>(profile_)); |
| 282 | 223 |
| 283 MediaCaptureDevicesDispatcher::GetInstance()->AddObserver(this); | 224 MediaCaptureDevicesDispatcher::GetInstance()->AddObserver(this); |
| 284 } | 225 } |
| 285 | 226 |
| 286 PrerenderManager::~PrerenderManager() { | 227 PrerenderManager::~PrerenderManager() { |
| 287 MediaCaptureDevicesDispatcher::GetInstance()->RemoveObserver(this); | 228 MediaCaptureDevicesDispatcher::GetInstance()->RemoveObserver(this); |
| 288 | 229 |
| 289 // The earlier call to KeyedService::Shutdown() should have | 230 // The earlier call to KeyedService::Shutdown() should have |
| 290 // emptied these vectors already. | 231 // emptied these vectors already. |
| 291 DCHECK(active_prerenders_.empty()); | 232 DCHECK(active_prerenders_.empty()); |
| 292 DCHECK(to_delete_prerenders_.empty()); | 233 DCHECK(to_delete_prerenders_.empty()); |
| 293 | 234 |
| 294 for (PrerenderProcessSet::const_iterator it = | 235 for (PrerenderProcessSet::const_iterator it = |
| 295 prerender_process_hosts_.begin(); | 236 prerender_process_hosts_.begin(); |
| 296 it != prerender_process_hosts_.end(); | 237 it != prerender_process_hosts_.end(); |
| 297 ++it) { | 238 ++it) { |
| 298 (*it)->RemoveObserver(this); | 239 (*it)->RemoveObserver(this); |
| 299 } | 240 } |
| 300 } | 241 } |
| 301 | 242 |
| 302 void PrerenderManager::Shutdown() { | 243 void PrerenderManager::Shutdown() { |
| 303 DestroyAllContents(FINAL_STATUS_MANAGER_SHUTDOWN); | 244 DestroyAllContents(FINAL_STATUS_MANAGER_SHUTDOWN); |
| 304 on_close_web_contents_deleters_.clear(); | 245 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; | 246 profile_ = NULL; |
| 310 | 247 |
| 311 DCHECK(active_prerenders_.empty()); | 248 DCHECK(active_prerenders_.empty()); |
| 312 } | 249 } |
| 313 | 250 |
| 314 PrerenderHandle* PrerenderManager::AddPrerenderFromLinkRelPrerender( | 251 PrerenderHandle* PrerenderManager::AddPrerenderFromLinkRelPrerender( |
| 315 int process_id, | 252 int process_id, |
| 316 int route_id, | 253 int route_id, |
| 317 const GURL& url, | 254 const GURL& url, |
| 318 const uint32 rel_types, | 255 const uint32 rel_types, |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 348 PrerenderHandle* PrerenderManager::AddPrerenderFromOmnibox( | 285 PrerenderHandle* PrerenderManager::AddPrerenderFromOmnibox( |
| 349 const GURL& url, | 286 const GURL& url, |
| 350 SessionStorageNamespace* session_storage_namespace, | 287 SessionStorageNamespace* session_storage_namespace, |
| 351 const gfx::Size& size) { | 288 const gfx::Size& size) { |
| 352 if (!IsOmniboxEnabled(profile_)) | 289 if (!IsOmniboxEnabled(profile_)) |
| 353 return NULL; | 290 return NULL; |
| 354 return AddPrerender(ORIGIN_OMNIBOX, url, content::Referrer(), size, | 291 return AddPrerender(ORIGIN_OMNIBOX, url, content::Referrer(), size, |
| 355 session_storage_namespace); | 292 session_storage_namespace); |
| 356 } | 293 } |
| 357 | 294 |
| 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( | 295 PrerenderHandle* PrerenderManager::AddPrerenderFromExternalRequest( |
| 367 const GURL& url, | 296 const GURL& url, |
| 368 const content::Referrer& referrer, | 297 const content::Referrer& referrer, |
| 369 SessionStorageNamespace* session_storage_namespace, | 298 SessionStorageNamespace* session_storage_namespace, |
| 370 const gfx::Size& size) { | 299 const gfx::Size& size) { |
| 371 return AddPrerender(ORIGIN_EXTERNAL_REQUEST, url, referrer, size, | 300 return AddPrerender(ORIGIN_EXTERNAL_REQUEST, url, referrer, size, |
| 372 session_storage_namespace); | 301 session_storage_namespace); |
| 373 } | 302 } |
| 374 | 303 |
| 375 PrerenderHandle* PrerenderManager::AddPrerenderForInstant( | 304 PrerenderHandle* PrerenderManager::AddPrerenderForInstant( |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 651 if (!IsEnabled()) | 580 if (!IsEnabled()) |
| 652 return; | 581 return; |
| 653 | 582 |
| 654 histograms_->RecordPerceivedPageLoadTime( | 583 histograms_->RecordPerceivedPageLoadTime( |
| 655 origin, perceived_page_load_time, navigation_type, url); | 584 origin, perceived_page_load_time, navigation_type, url); |
| 656 | 585 |
| 657 if (navigation_type == NAVIGATION_TYPE_PRERENDERED) { | 586 if (navigation_type == NAVIGATION_TYPE_PRERENDERED) { |
| 658 histograms_->RecordPercentLoadDoneAtSwapin( | 587 histograms_->RecordPercentLoadDoneAtSwapin( |
| 659 origin, fraction_plt_elapsed_at_swap_in); | 588 origin, fraction_plt_elapsed_at_swap_in); |
| 660 } | 589 } |
| 661 if (local_predictor_) { | |
| 662 local_predictor_->OnPLTEventForURL(url, perceived_page_load_time); | |
| 663 } | |
| 664 } | 590 } |
| 665 | 591 |
| 666 // static | 592 // static |
| 667 PrerenderManager::PrerenderManagerMode PrerenderManager::GetMode() { | 593 PrerenderManager::PrerenderManagerMode PrerenderManager::GetMode() { |
| 668 return mode_; | 594 return mode_; |
| 669 } | 595 } |
| 670 | 596 |
| 671 // static | 597 // static |
| 672 void PrerenderManager::SetMode(PrerenderManagerMode mode) { | 598 void PrerenderManager::SetMode(PrerenderManagerMode mode) { |
| 673 mode_ = mode; | 599 mode_ = mode; |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1065 | 991 |
| 1066 last_prerender_start_time_ = GetCurrentTimeTicks(); | 992 last_prerender_start_time_ = GetCurrentTimeTicks(); |
| 1067 | 993 |
| 1068 gfx::Size contents_size = | 994 gfx::Size contents_size = |
| 1069 size.IsEmpty() ? config_.default_tab_bounds.size() : size; | 995 size.IsEmpty() ? config_.default_tab_bounds.size() : size; |
| 1070 | 996 |
| 1071 prerender_contents->StartPrerendering(contents_size, | 997 prerender_contents->StartPrerendering(contents_size, |
| 1072 session_storage_namespace); | 998 session_storage_namespace); |
| 1073 | 999 |
| 1074 DCHECK(IsControlGroup(experiment) || | 1000 DCHECK(IsControlGroup(experiment) || |
| 1075 prerender_contents->prerendering_has_started() || | 1001 prerender_contents->prerendering_has_started()); |
| 1076 (origin == ORIGIN_LOCAL_PREDICTOR && | |
| 1077 IsLocalPredictorPrerenderAlwaysControlEnabled())); | |
| 1078 | 1002 |
| 1079 if (GetMode() == PRERENDER_MODE_EXPERIMENT_MULTI_PRERENDER_GROUP) | 1003 if (GetMode() == PRERENDER_MODE_EXPERIMENT_MULTI_PRERENDER_GROUP) |
| 1080 histograms_->RecordConcurrency(active_prerenders_.size()); | 1004 histograms_->RecordConcurrency(active_prerenders_.size()); |
| 1081 | 1005 |
| 1082 StartSchedulingPeriodicCleanups(); | 1006 StartSchedulingPeriodicCleanups(); |
| 1083 return prerender_handle; | 1007 return prerender_handle; |
| 1084 } | 1008 } |
| 1085 | 1009 |
| 1086 void PrerenderManager::StartSchedulingPeriodicCleanups() { | 1010 void PrerenderManager::StartSchedulingPeriodicCleanups() { |
| 1087 DCHECK(CalledOnValidThread()); | 1011 DCHECK(CalledOnValidThread()); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1137 | 1061 |
| 1138 void PrerenderManager::PostCleanupTask() { | 1062 void PrerenderManager::PostCleanupTask() { |
| 1139 DCHECK(CalledOnValidThread()); | 1063 DCHECK(CalledOnValidThread()); |
| 1140 base::MessageLoop::current()->PostTask( | 1064 base::MessageLoop::current()->PostTask( |
| 1141 FROM_HERE, | 1065 FROM_HERE, |
| 1142 base::Bind(&PrerenderManager::PeriodicCleanup, AsWeakPtr())); | 1066 base::Bind(&PrerenderManager::PeriodicCleanup, AsWeakPtr())); |
| 1143 } | 1067 } |
| 1144 | 1068 |
| 1145 base::TimeTicks PrerenderManager::GetExpiryTimeForNewPrerender( | 1069 base::TimeTicks PrerenderManager::GetExpiryTimeForNewPrerender( |
| 1146 Origin origin) const { | 1070 Origin origin) const { |
| 1147 base::TimeDelta ttl = config_.time_to_live; | 1071 return GetCurrentTimeTicks() + config_.time_to_live; |
| 1148 if (origin == ORIGIN_LOCAL_PREDICTOR) | |
| 1149 ttl = base::TimeDelta::FromSeconds(GetLocalPredictorTTLSeconds()); | |
| 1150 return GetCurrentTimeTicks() + ttl; | |
| 1151 } | 1072 } |
| 1152 | 1073 |
| 1153 base::TimeTicks PrerenderManager::GetExpiryTimeForNavigatedAwayPrerender() | 1074 base::TimeTicks PrerenderManager::GetExpiryTimeForNavigatedAwayPrerender() |
| 1154 const { | 1075 const { |
| 1155 return GetCurrentTimeTicks() + config_.abandon_time_to_live; | 1076 return GetCurrentTimeTicks() + config_.abandon_time_to_live; |
| 1156 } | 1077 } |
| 1157 | 1078 |
| 1158 void PrerenderManager::DeleteOldEntries() { | 1079 void PrerenderManager::DeleteOldEntries() { |
| 1159 DCHECK(CalledOnValidThread()); | 1080 DCHECK(CalledOnValidThread()); |
| 1160 while (!active_prerenders_.empty()) { | 1081 while (!active_prerenders_.empty()) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1213 return active_prerenders_.end(); | 1134 return active_prerenders_.end(); |
| 1214 } | 1135 } |
| 1215 | 1136 |
| 1216 bool PrerenderManager::DoesRateLimitAllowPrerender(Origin origin) const { | 1137 bool PrerenderManager::DoesRateLimitAllowPrerender(Origin origin) const { |
| 1217 DCHECK(CalledOnValidThread()); | 1138 DCHECK(CalledOnValidThread()); |
| 1218 base::TimeDelta elapsed_time = | 1139 base::TimeDelta elapsed_time = |
| 1219 GetCurrentTimeTicks() - last_prerender_start_time_; | 1140 GetCurrentTimeTicks() - last_prerender_start_time_; |
| 1220 histograms_->RecordTimeBetweenPrerenderRequests(origin, elapsed_time); | 1141 histograms_->RecordTimeBetweenPrerenderRequests(origin, elapsed_time); |
| 1221 if (!config_.rate_limit_enabled) | 1142 if (!config_.rate_limit_enabled) |
| 1222 return true; | 1143 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 >= | 1144 return elapsed_time >= |
| 1228 base::TimeDelta::FromMilliseconds(kMinTimeBetweenPrerendersMs); | 1145 base::TimeDelta::FromMilliseconds(kMinTimeBetweenPrerendersMs); |
| 1229 } | 1146 } |
| 1230 | 1147 |
| 1231 void PrerenderManager::DeleteOldWebContents() { | 1148 void PrerenderManager::DeleteOldWebContents() { |
| 1232 while (!old_web_contents_list_.empty()) { | 1149 while (!old_web_contents_list_.empty()) { |
| 1233 WebContents* web_contents = old_web_contents_list_.front(); | 1150 WebContents* web_contents = old_web_contents_list_.front(); |
| 1234 old_web_contents_list_.pop_front(); | 1151 old_web_contents_list_.pop_front(); |
| 1235 // TODO(dominich): should we use Instant Unload Handler here? | 1152 // TODO(dominich): should we use Instant Unload Handler here? |
| 1236 delete web_contents; | 1153 delete web_contents; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1314 RecordFinalStatusWithMatchCompleteStatus( | 1231 RecordFinalStatusWithMatchCompleteStatus( |
| 1315 origin, experiment_id, | 1232 origin, experiment_id, |
| 1316 PrerenderContents::MATCH_COMPLETE_DEFAULT, | 1233 PrerenderContents::MATCH_COMPLETE_DEFAULT, |
| 1317 final_status); | 1234 final_status); |
| 1318 } | 1235 } |
| 1319 | 1236 |
| 1320 void PrerenderManager::Observe(int type, | 1237 void PrerenderManager::Observe(int type, |
| 1321 const content::NotificationSource& source, | 1238 const content::NotificationSource& source, |
| 1322 const content::NotificationDetails& details) { | 1239 const content::NotificationDetails& details) { |
| 1323 switch (type) { | 1240 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: | 1241 case chrome::NOTIFICATION_PROFILE_DESTROYED: |
| 1334 DestroyAllContents(FINAL_STATUS_PROFILE_DESTROYED); | 1242 DestroyAllContents(FINAL_STATUS_PROFILE_DESTROYED); |
| 1335 on_close_web_contents_deleters_.clear(); | 1243 on_close_web_contents_deleters_.clear(); |
| 1336 break; | 1244 break; |
| 1337 default: | 1245 default: |
| 1338 NOTREACHED() << "Unexpected notification sent."; | 1246 NOTREACHED() << "Unexpected notification sent."; |
| 1339 break; | 1247 break; |
| 1340 } | 1248 } |
| 1341 } | 1249 } |
| 1342 | 1250 |
| 1343 void PrerenderManager::OnCreatingAudioStream(int render_process_id, | 1251 void PrerenderManager::OnCreatingAudioStream(int render_process_id, |
| 1344 int render_frame_id) { | 1252 int render_frame_id) { |
| 1345 content::RenderFrameHost* render_frame_host = | 1253 content::RenderFrameHost* render_frame_host = |
| 1346 content::RenderFrameHost::FromID(render_process_id, render_frame_id); | 1254 content::RenderFrameHost::FromID(render_process_id, render_frame_id); |
| 1347 WebContents* tab = WebContents::FromRenderFrameHost(render_frame_host); | 1255 WebContents* tab = WebContents::FromRenderFrameHost(render_frame_host); |
| 1348 if (!tab) | 1256 if (!tab) |
| 1349 return; | 1257 return; |
| 1350 | 1258 |
| 1351 PrerenderContents* prerender_contents = GetPrerenderContents(tab); | 1259 PrerenderContents* prerender_contents = GetPrerenderContents(tab); |
| 1352 if (!prerender_contents) | 1260 if (!prerender_contents) |
| 1353 return; | 1261 return; |
| 1354 | 1262 |
| 1355 prerender_contents->Destroy(prerender::FINAL_STATUS_CREATING_AUDIO_STREAM); | 1263 prerender_contents->Destroy(prerender::FINAL_STATUS_CREATING_AUDIO_STREAM); |
| 1356 } | 1264 } |
| 1357 | 1265 |
| 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, | 1266 void PrerenderManager::RecordNetworkBytes(Origin origin, |
| 1462 bool used, | 1267 bool used, |
| 1463 int64 prerender_bytes) { | 1268 int64 prerender_bytes) { |
| 1464 if (!ActuallyPrerendering()) | 1269 if (!ActuallyPrerendering()) |
| 1465 return; | 1270 return; |
| 1466 int64 recent_profile_bytes = | 1271 int64 recent_profile_bytes = |
| 1467 profile_network_bytes_ - last_recorded_profile_network_bytes_; | 1272 profile_network_bytes_ - last_recorded_profile_network_bytes_; |
| 1468 last_recorded_profile_network_bytes_ = profile_network_bytes_; | 1273 last_recorded_profile_network_bytes_ = profile_network_bytes_; |
| 1469 DCHECK_GE(recent_profile_bytes, 0); | 1274 DCHECK_GE(recent_profile_bytes, 0); |
| 1470 histograms_->RecordNetworkBytes( | 1275 histograms_->RecordNetworkBytes( |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1502 } | 1307 } |
| 1503 | 1308 |
| 1504 void PrerenderManager::RenderProcessHostDestroyed( | 1309 void PrerenderManager::RenderProcessHostDestroyed( |
| 1505 content::RenderProcessHost* host) { | 1310 content::RenderProcessHost* host) { |
| 1506 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1311 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1507 size_t erased = prerender_process_hosts_.erase(host); | 1312 size_t erased = prerender_process_hosts_.erase(host); |
| 1508 DCHECK_EQ(1u, erased); | 1313 DCHECK_EQ(1u, erased); |
| 1509 } | 1314 } |
| 1510 | 1315 |
| 1511 } // namespace prerender | 1316 } // namespace prerender |
| OLD | NEW |