diff options
author | piman@chromium.org <piman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-12 21:23:06 +0000 |
---|---|---|
committer | piman@chromium.org <piman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-12 21:23:06 +0000 |
commit | 5e501de8433bd127e0a5bf40b43d7396228d14a0 (patch) | |
tree | 478e22369cc29c8cd7948a08556d7dc5c51cd42a /chrome/browser | |
parent | ea0166624be8d9f54db91cb2cbe96429ba9cbc77 (diff) | |
download | chromium_src-5e501de8433bd127e0a5bf40b43d7396228d14a0.zip chromium_src-5e501de8433bd127e0a5bf40b43d7396228d14a0.tar.gz chromium_src-5e501de8433bd127e0a5bf40b43d7396228d14a0.tar.bz2 |
Revert 269855 "Only commit cookie changes in prerenders after a ..."
This broke again - http://build.chromium.org/p/chromium.mac/buildstatus?builder=Mac%2010.7%20Tests%20%28dbg%29%281%29&number=23472
> Only commit cookie changes in prerenders after a prerender is shown
> Will create a PrerenderCookieStore for each prerender, retaining all cookie
> operations of a prerender until the prerender is shown to the user.
> Forces prerenders to be in a new render process by themselves for this to work.
> BUG=371003
>
> This is a resubmission of https://codereview.chromium.org/233353003, which had
> to be reverted due to build breaks. See LGTM's there.
>
> Review URL: https://codereview.chromium.org/278403003
TBR=tburkard@chromium.org
Review URL: https://codereview.chromium.org/280383002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@269879 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
28 files changed, 17 insertions, 960 deletions
diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc index 678948c..06b97e7 100644 --- a/chrome/browser/chrome_content_browser_client.cc +++ b/chrome/browser/chrome_content_browser_client.cc @@ -630,8 +630,7 @@ float GetDeviceScaleAdjustment() { namespace chrome { -ChromeContentBrowserClient::ChromeContentBrowserClient() - : prerender_tracker_(NULL) { +ChromeContentBrowserClient::ChromeContentBrowserClient() { #if defined(ENABLE_PLUGINS) for (size_t i = 0; i < arraysize(kPredefinedAllowedFileHandleOrigins); ++i) allowed_file_handle_origins_.insert(kPredefinedAllowedFileHandleOrigins[i]); @@ -1215,24 +1214,6 @@ bool ChromeContentBrowserClient::IsSuitableHost( privilege_required; } -bool ChromeContentBrowserClient::MayReuseHost( - content::RenderProcessHost* process_host) { - // If there is currently a prerender in progress for the host provided, - // it may not be shared. We require prerenders to be by themselves in a - // separate process, so that we can monitor their resource usage, and so that - // we can track the cookies that they change. - Profile* profile = Profile::FromBrowserContext( - process_host->GetBrowserContext()); - prerender::PrerenderManager* prerender_manager = - prerender::PrerenderManagerFactory::GetForProfile(profile); - if (prerender_manager && - prerender_manager->IsProcessPrerendering(process_host)) { - return false; - } - - return true; -} - // This function is trying to limit the amount of processes used by extensions // with background pages. It uses a globally set percentage of processes to // run such extensions and if the limit is exceeded, it returns true, to @@ -1784,13 +1765,6 @@ bool ChromeContentBrowserClient::AllowSetCookie( CookieSettings* cookie_settings = io_data->GetCookieSettings(); bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party); - if (prerender_tracker_) { - prerender_tracker_->OnCookieChangedForURL( - render_process_id, - context->GetRequestContext()->cookie_store()->GetCookieMonster(), - url); - } - BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id, @@ -2237,8 +2211,6 @@ std::string ChromeContentBrowserClient::GetWorkerProcessTitle( } void ChromeContentBrowserClient::ResourceDispatcherHostCreated() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - prerender_tracker_ = g_browser_process->prerender_tracker(); return g_browser_process->ResourceDispatcherHostCreated(); } @@ -2726,16 +2698,6 @@ bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs() { #endif } -net::CookieStore* -ChromeContentBrowserClient::OverrideCookieStoreForRenderProcess( - int render_process_id) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - if (!prerender_tracker_) - return NULL; - return prerender_tracker_-> - GetPrerenderCookieStoreForRenderProcess(render_process_id); -} - #if defined(ENABLE_WEBRTC) void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch( CommandLine* to_command_line, diff --git a/chrome/browser/chrome_content_browser_client.h b/chrome/browser/chrome_content_browser_client.h index b8b9af1..9432b5e 100644 --- a/chrome/browser/chrome_content_browser_client.h +++ b/chrome/browser/chrome_content_browser_client.h @@ -31,10 +31,6 @@ namespace extensions { class BrowserPermissionsPolicyDelegate; } -namespace prerender { -class PrerenderTracker; -} - namespace user_prefs { class PrefRegistrySyncable; } @@ -106,7 +102,6 @@ class ChromeContentBrowserClient : public content::ContentBrowserClient { const GURL& url) OVERRIDE; virtual bool IsSuitableHost(content::RenderProcessHost* process_host, const GURL& site_url) OVERRIDE; - virtual bool MayReuseHost(content::RenderProcessHost* process_host) OVERRIDE; virtual bool ShouldTryToUseExistingProcessHost( content::BrowserContext* browser_context, const GURL& url) OVERRIDE; virtual void SiteInstanceGotProcess( @@ -283,9 +278,6 @@ class ChromeContentBrowserClient : public content::ContentBrowserClient { virtual bool IsPluginAllowedToUseDevChannelAPIs() OVERRIDE; - virtual net::CookieStore* OverrideCookieStoreForRenderProcess( - int render_process_id) OVERRIDE; - private: #if defined(ENABLE_WEBRTC) // Copies disable WebRTC encryption switch depending on the channel. @@ -304,14 +296,6 @@ class ChromeContentBrowserClient : public content::ContentBrowserClient { scoped_ptr<extensions::BrowserPermissionsPolicyDelegate> permissions_policy_delegate_; - // The prerender tracker used to determine whether a render process is used - // for prerendering and an override cookie store must be provided. - // This needs to be kept as a member rather than just looked up from - // the profile due to initialization ordering, as well as due to threading. - // It is initialized on the UI thread when the ResoureDispatcherHost is - // created. It is used only the IO thread. - prerender::PrerenderTracker* prerender_tracker_; - friend class DisableWebRtcEncryptionFlagTest; DISALLOW_COPY_AND_ASSIGN(ChromeContentBrowserClient); diff --git a/chrome/browser/extensions/activity_log/activity_log_browsertest.cc b/chrome/browser/extensions/activity_log/activity_log_browsertest.cc index 32a175e..a78d30a5 100644 --- a/chrome/browser/extensions/activity_log/activity_log_browsertest.cc +++ b/chrome/browser/extensions/activity_log/activity_log_browsertest.cc @@ -12,10 +12,7 @@ #include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/common/chrome_switches.h" #include "chrome/test/base/ui_test_utils.h" -#include "content/public/browser/browser_context.h" -#include "content/public/browser/browser_thread.h" #include "content/public/browser/notification_service.h" -#include "content/public/browser/storage_partition.h" #include "content/public/test/browser_test_utils.h" #include "net/dns/mock_host_resolver.h" #include "net/test/embedded_test_server/embedded_test_server.h" @@ -102,13 +99,6 @@ IN_PROC_BROWSER_TEST_F(ActivityLogPrerenderTest, TestScriptInjected) { "http://www.google.com.bo:%d/test.html", port)); - if (!prerender_manager->cookie_store_loaded()) { - base::RunLoop loop; - prerender_manager->set_on_cookie_store_loaded_cb_for_testing( - loop.QuitClosure()); - loop.Run(); - } - const gfx::Size kSize(640, 480); scoped_ptr<prerender::PrerenderHandle> prerender_handle( prerender_manager->AddPrerenderFromLocalPredictor( diff --git a/chrome/browser/extensions/activity_log/activity_log_unittest.cc b/chrome/browser/extensions/activity_log/activity_log_unittest.cc index 5c8fda0..7f1e530 100644 --- a/chrome/browser/extensions/activity_log/activity_log_unittest.cc +++ b/chrome/browser/extensions/activity_log/activity_log_unittest.cc @@ -244,8 +244,6 @@ TEST_F(ActivityLogTest, LogPrerender) { prerender::PrerenderManagerFactory::GetForProfile( Profile::FromBrowserContext(profile())); - prerender_manager->OnCookieStoreLoaded(); - const gfx::Size kSize(640, 480); scoped_ptr<prerender::PrerenderHandle> prerender_handle( prerender_manager->AddPrerenderFromLocalPredictor( diff --git a/chrome/browser/net/chrome_network_delegate.cc b/chrome/browser/net/chrome_network_delegate.cc index bafd11f..1cab93d 100644 --- a/chrome/browser/net/chrome_network_delegate.cc +++ b/chrome/browser/net/chrome_network_delegate.cc @@ -29,7 +29,6 @@ #include "chrome/browser/net/client_hints.h" #include "chrome/browser/net/connect_interceptor.h" #include "chrome/browser/performance_monitor/performance_monitor.h" -#include "chrome/browser/prerender/prerender_tracker.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/task_manager/task_manager.h" #include "chrome/common/pref_names.h" @@ -53,7 +52,6 @@ #include "net/http/http_response_headers.h" #include "net/socket_stream/socket_stream.h" #include "net/url_request/url_request.h" -#include "net/url_request/url_request_context.h" #if defined(OS_CHROMEOS) #include "base/command_line.h" @@ -360,8 +358,7 @@ ChromeNetworkDelegate::ChromeNetworkDelegate( domain_reliability_monitor_(NULL), received_content_length_(0), original_content_length_(0), - first_request_(true), - prerender_tracker_(NULL) { + first_request_(true) { DCHECK(event_router); DCHECK(enable_referrers); } @@ -745,13 +742,6 @@ bool ChromeNetworkDelegate::OnCanSetCookie(const net::URLRequest& request, cookie_line, *options, !allow)); } - if (prerender_tracker_) { - prerender_tracker_->OnCookieChangedForURL( - render_process_id, - request.context()->cookie_store()->GetCookieMonster(), - request.url()); - } - return allow; } diff --git a/chrome/browser/net/chrome_network_delegate.h b/chrome/browser/net/chrome_network_delegate.h index 608ba05..2053180 100644 --- a/chrome/browser/net/chrome_network_delegate.h +++ b/chrome/browser/net/chrome_network_delegate.h @@ -49,10 +49,6 @@ namespace policy { class URLBlacklistManager; } -namespace prerender { -class PrerenderTracker; -} - // ChromeNetworkDelegate is the central point from within the chrome code to // add hooks into the network stack. class ChromeNetworkDelegate : public net::NetworkDelegate { @@ -110,10 +106,6 @@ class ChromeNetworkDelegate : public net::NetworkDelegate { domain_reliability_monitor_ = domain_reliability_monitor; } - void set_prerender_tracker(prerender::PrerenderTracker* prerender_tracker) { - prerender_tracker_ = prerender_tracker; - } - // Adds the Client Hints header to HTTP requests. void SetEnableClientHints(); @@ -236,8 +228,6 @@ class ChromeNetworkDelegate : public net::NetworkDelegate { bool first_request_; - prerender::PrerenderTracker* prerender_tracker_; - DISALLOW_COPY_AND_ASSIGN(ChromeNetworkDelegate); }; diff --git a/chrome/browser/net/cookie_store_util.cc b/chrome/browser/net/cookie_store_util.cc index 5e5d780..924c9b0 100644 --- a/chrome/browser/net/cookie_store_util.cc +++ b/chrome/browser/net/cookie_store_util.cc @@ -12,8 +12,6 @@ #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/net/chrome_cookie_notification_details.h" #include "chrome/browser/net/evicted_domain_cookie_counter.h" -#include "chrome/browser/prerender/prerender_manager.h" -#include "chrome/browser/prerender/prerender_manager_factory.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/common/chrome_constants.h" @@ -51,13 +49,6 @@ class ChromeCookieMonsterDelegate : public net::CookieMonsterDelegate { this, cookie, removed, cause)); } - virtual void OnLoaded() OVERRIDE { - BrowserThread::PostTask( - BrowserThread::UI, FROM_HERE, - base::Bind(&ChromeCookieMonsterDelegate::OnLoadedAsyncHelper, - this)); - } - private: virtual ~ChromeCookieMonsterDelegate() {} @@ -82,16 +73,6 @@ class ChromeCookieMonsterDelegate : public net::CookieMonsterDelegate { } } - void OnLoadedAsyncHelper() { - Profile* profile = profile_getter_.Run(); - if (profile) { - prerender::PrerenderManager* prerender_manager = - prerender::PrerenderManagerFactory::GetForProfile(profile); - if (prerender_manager) - prerender_manager->OnCookieStoreLoaded(); - } - } - const base::Callback<Profile*(void)> profile_getter_; }; diff --git a/chrome/browser/net/evicted_domain_cookie_counter.cc b/chrome/browser/net/evicted_domain_cookie_counter.cc index 71139a5..2d9590a 100644 --- a/chrome/browser/net/evicted_domain_cookie_counter.cc +++ b/chrome/browser/net/evicted_domain_cookie_counter.cc @@ -111,11 +111,6 @@ void EvictedDomainCookieCounter::OnCookieChanged( next_cookie_monster_delegate_->OnCookieChanged(cookie, removed, cause); } -void EvictedDomainCookieCounter::OnLoaded() { - if (next_cookie_monster_delegate_.get()) - next_cookie_monster_delegate_->OnLoaded(); -} - // static EvictedDomainCookieCounter::EvictedCookieKey EvictedDomainCookieCounter::GetKey(const net::CanonicalCookie& cookie) { diff --git a/chrome/browser/net/evicted_domain_cookie_counter.h b/chrome/browser/net/evicted_domain_cookie_counter.h index 5731fa9..5cf8797 100644 --- a/chrome/browser/net/evicted_domain_cookie_counter.h +++ b/chrome/browser/net/evicted_domain_cookie_counter.h @@ -90,7 +90,6 @@ class EvictedDomainCookieCounter : public net::CookieMonster::Delegate { virtual void OnCookieChanged(const net::CanonicalCookie& cookie, bool removed, ChangeCause cause) OVERRIDE; - virtual void OnLoaded() OVERRIDE; private: // Identifier of an evicted cookie. diff --git a/chrome/browser/net/evicted_domain_cookie_counter_unittest.cc b/chrome/browser/net/evicted_domain_cookie_counter_unittest.cc index 1a73589..ca2597d 100644 --- a/chrome/browser/net/evicted_domain_cookie_counter_unittest.cc +++ b/chrome/browser/net/evicted_domain_cookie_counter_unittest.cc @@ -193,8 +193,6 @@ TEST_F(EvictedDomainCookieCounterTest, TestChain) { ++(*result_); } - virtual void OnLoaded() OVERRIDE {} - private: virtual ~ChangedDelegateDummy() {} diff --git a/chrome/browser/prerender/external_prerender_handler_android.cc b/chrome/browser/prerender/external_prerender_handler_android.cc index 0be6463..013873b 100644 --- a/chrome/browser/prerender/external_prerender_handler_android.cc +++ b/chrome/browser/prerender/external_prerender_handler_android.cc @@ -89,17 +89,6 @@ static jboolean HasPrerenderedUrl(JNIEnv* env, return prerender_manager->HasPrerenderedUrl(url, web_contents); } -static jboolean HasCookieStoreLoaded(JNIEnv* env, - jclass clazz, - jobject jprofile) { - Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile); - prerender::PrerenderManager* prerender_manager = - prerender::PrerenderManagerFactory::GetForProfile(profile); - if (!prerender_manager) - return false; - return prerender_manager->cookie_store_loaded(); -} - ExternalPrerenderHandlerAndroid::ExternalPrerenderHandlerAndroid() {} ExternalPrerenderHandlerAndroid::~ExternalPrerenderHandlerAndroid() {} diff --git a/chrome/browser/prerender/external_prerender_handler_android.h b/chrome/browser/prerender/external_prerender_handler_android.h index 6009ddf..111181c 100644 --- a/chrome/browser/prerender/external_prerender_handler_android.h +++ b/chrome/browser/prerender/external_prerender_handler_android.h @@ -45,9 +45,6 @@ class ExternalPrerenderHandlerAndroid { GURL url, content::WebContents* web_contents); - // Whether the cookie store associated with this profile has been loaded. - static bool HasCookieStoreLoaded(Profile* profile); - static bool RegisterExternalPrerenderHandlerAndroid(JNIEnv* env); private: diff --git a/chrome/browser/prerender/prerender_browsertest.cc b/chrome/browser/prerender/prerender_browsertest.cc index 7e492738..bbfba0d 100644 --- a/chrome/browser/prerender/prerender_browsertest.cc +++ b/chrome/browser/prerender/prerender_browsertest.cc @@ -1124,12 +1124,6 @@ class PrerenderBrowserTest : virtual public InProcessBrowserTest { return scoped_ptr<TestPrerender>(prerenders[0]); } - // Navigates to a URL, unrelated to prerendering - void NavigateStraightToURL(const std::string dest_html_file) { - ui_test_utils::NavigateToURL(current_browser(), - test_server()->GetURL(dest_html_file)); - } - void NavigateToDestURL() const { NavigateToDestURLWithDisposition(CURRENT_TAB, true); } @@ -1490,22 +1484,6 @@ class PrerenderBrowserTest : virtual public InProcessBrowserTest { base::ASCIIToUTF16(page_title)); } - void RunJSReturningString(const char* js, std::string* result) { - ASSERT_TRUE( - content::ExecuteScriptAndExtractString( - GetActiveWebContents(), - base::StringPrintf("window.domAutomationController.send(%s)", - js).c_str(), - result)); - } - - void RunJS(const char* js) { - ASSERT_TRUE(content::ExecuteScript( - GetActiveWebContents(), - base::StringPrintf("window.domAutomationController.send(%s)", - js).c_str())); - } - protected: bool autostart_test_server_; @@ -4175,103 +4153,6 @@ IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPPLTNormalNavigation) { histograms.ExpectTotalCount("Prerender.none_PerceivedPLTMatchedComplete", 0); } -IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, - PrerenderCookieChangeConflictTest) { - NavigateStraightToURL( - "files/prerender/prerender_cookie.html?set=1&key=c&value=1"); - - GURL url = test_server()->GetURL( - "files/prerender/prerender_cookie.html?set=1&key=c&value=2"); - - scoped_ptr<TestPrerender> prerender = - ExpectPrerender(FINAL_STATUS_COOKIE_CONFLICT); - AddPrerender(url, 1); - prerender->WaitForStart(); - prerender->WaitForLoads(1); - // Ensure that in the prerendered page, querying the cookie again - // via javascript yields the same value that was set during load. - EXPECT_TRUE(DidPrerenderPass(prerender->contents()->prerender_contents())); - - // The prerender has loaded. Ensure that the change is not visible - // to visible tabs. - std::string value; - RunJSReturningString("GetCookie('c')", &value); - ASSERT_EQ(value, "1"); - - // Make a conflicting cookie change, which should cancel the prerender. - RunJS("SetCookie('c', '3')"); - prerender->WaitForStop(); -} - -IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderCookieChangeUseTest) { - // Permit 2 concurrent prerenders. - GetPrerenderManager()->mutable_config().max_link_concurrency = 2; - GetPrerenderManager()->mutable_config().max_link_concurrency_per_launcher = 2; - - // Go to a first URL setting the cookie to value "1". - NavigateStraightToURL( - "files/prerender/prerender_cookie.html?set=1&key=c&value=1"); - - // Prerender a URL setting the cookie to value "2". - GURL url = test_server()->GetURL( - "files/prerender/prerender_cookie.html?set=1&key=c&value=2"); - - scoped_ptr<TestPrerender> prerender1 = ExpectPrerender(FINAL_STATUS_USED); - AddPrerender(url, 1); - prerender1->WaitForStart(); - prerender1->WaitForLoads(1); - - // Launch a second prerender, setting the cookie to value "3". - scoped_ptr<TestPrerender> prerender2 = - ExpectPrerender(FINAL_STATUS_COOKIE_CONFLICT); - AddPrerender(test_server()->GetURL( - "files/prerender/prerender_cookie.html?set=1&key=c&value=3"), 1); - prerender2->WaitForStart(); - prerender2->WaitForLoads(1); - - // Both prerenders have loaded. Ensure that the visible tab is still - // unchanged and cannot see their changes. - // to visible tabs. - std::string value; - RunJSReturningString("GetCookie('c')", &value); - ASSERT_EQ(value, "1"); - - // Navigate to the prerendered URL. The first prerender should be swapped in, - // and the changes should now be visible. The second prerender should - // be cancelled due to the conflict. - ui_test_utils::NavigateToURLWithDisposition( - current_browser(), - url, - CURRENT_TAB, - ui_test_utils::BROWSER_TEST_NONE); - RunJSReturningString("GetCookie('c')", &value); - ASSERT_EQ(value, "2"); - prerender2->WaitForStop(); -} - -IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, - PrerenderCookieChangeConflictHTTPHeaderTest) { - NavigateStraightToURL( - "files/prerender/prerender_cookie.html?set=1&key=c&value=1"); - - GURL url = test_server()->GetURL("set-cookie?c=2"); - scoped_ptr<TestPrerender> prerender = - ExpectPrerender(FINAL_STATUS_COOKIE_CONFLICT); - AddPrerender(url, 1); - prerender->WaitForStart(); - prerender->WaitForLoads(1); - - // The prerender has loaded. Ensure that the change is not visible - // to visible tabs. - std::string value; - RunJSReturningString("GetCookie('c')", &value); - ASSERT_EQ(value, "1"); - - // Make a conflicting cookie change, which should cancel the prerender. - RunJS("SetCookie('c', '3')"); - prerender->WaitForStop(); -} - // Checks that a prerender which calls window.close() on itself is aborted. IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderWindowClose) { DisableLoadEventCheck(); @@ -4349,11 +4230,6 @@ class PrerenderOmniboxBrowserTest : public PrerenderBrowserTest { // Checks that closing the omnibox popup cancels an omnibox prerender. IN_PROC_BROWSER_TEST_F(PrerenderOmniboxBrowserTest, PrerenderOmniboxCancel) { - // Ensure the cookie store has been loaded. - ui_test_utils::NavigateToURL( - current_browser(), - test_server()->GetURL("files/empty.html?loadcookies")); - // Fake an omnibox prerender. scoped_ptr<TestPrerender> prerender = StartOmniboxPrerender( test_server()->GetURL("files/empty.html"), @@ -4371,11 +4247,6 @@ IN_PROC_BROWSER_TEST_F(PrerenderOmniboxBrowserTest, PrerenderOmniboxAbandon) { GetPrerenderManager()->mutable_config().abandon_time_to_live = base::TimeDelta::FromDays(999); - // Ensure the cookie store has been loaded. - ui_test_utils::NavigateToURL( - current_browser(), - test_server()->GetURL("files/empty.html?loadcookies")); - // Enter a URL into the Omnibox. OmniboxView* omnibox_view = GetOmniboxView(); omnibox_view->OnBeforePossibleChange(); diff --git a/chrome/browser/prerender/prerender_contents.cc b/chrome/browser/prerender/prerender_contents.cc index 8e209e1..35f45a4 100644 --- a/chrome/browser/prerender/prerender_contents.cc +++ b/chrome/browser/prerender/prerender_contents.cc @@ -39,10 +39,8 @@ #include "content/public/browser/web_contents_delegate.h" #include "content/public/common/frame_navigate_params.h" #include "content/public/common/page_transition_types.h" -#include "net/url_request/url_request_context_getter.h" #include "ui/gfx/rect.h" -using content::BrowserThread; using content::DownloadItem; using content::OpenURLParams; using content::RenderViewHost; @@ -293,8 +291,7 @@ PrerenderContents* PrerenderContents::FromWebContents( void PrerenderContents::StartPrerendering( int creator_child_id, const gfx::Size& size, - SessionStorageNamespace* session_storage_namespace, - net::URLRequestContextGetter* request_context) { + SessionStorageNamespace* session_storage_namespace) { DCHECK(profile_ != NULL); DCHECK(!size.IsEmpty()); DCHECK(!prerendering_has_started_); @@ -342,24 +339,6 @@ void PrerenderContents::StartPrerendering( // the event of a mismatch. alias_session_storage_namespace->AddTransactionLogProcessId(child_id_); - // Add the RenderProcessHost to the Prerender Manager. - prerender_manager()->AddPrerenderProcessHost( - GetRenderViewHost()->GetProcess()); - - // In the prerender tracker, create a Prerender Cookie Store to keep track of - // cookie changes performed by the prerender. Once the prerender is shown, - // the cookie changes will be committed to the actual cookie store, - // otherwise, they will be discarded. - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - base::Bind(&PrerenderTracker::AddPrerenderCookieStoreOnIOThread, - base::Unretained(prerender_manager()->prerender_tracker()), - GetRenderViewHost()->GetProcess()->GetID(), - make_scoped_refptr(request_context), - base::Bind(&PrerenderContents::Destroy, - AsWeakPtr(), - FINAL_STATUS_COOKIE_CONFLICT))); - NotifyPrerenderStart(); // Close ourselves when the application is shutting down. @@ -817,8 +796,8 @@ void PrerenderContents::PrepareForUse() { NotifyPrerenderStop(); - BrowserThread::PostTask( - BrowserThread::IO, + content::BrowserThread::PostTask( + content::BrowserThread::IO, FROM_HERE, base::Bind(&ResumeThrottles, resource_throttles_)); resource_throttles_.clear(); diff --git a/chrome/browser/prerender/prerender_contents.h b/chrome/browser/prerender/prerender_contents.h index 3b8ba1d..d60602f 100644 --- a/chrome/browser/prerender/prerender_contents.h +++ b/chrome/browser/prerender/prerender_contents.h @@ -39,10 +39,6 @@ namespace history { struct HistoryAddPageArgs; } -namespace net { -class URLRequestContextGetter; -} - namespace prerender { class PrerenderHandle; @@ -50,8 +46,7 @@ class PrerenderManager; class PrerenderResourceThrottle; class PrerenderContents : public content::NotificationObserver, - public content::WebContentsObserver, - public base::SupportsWeakPtr<PrerenderContents> { + public content::WebContentsObserver { public: // PrerenderContents::Create uses the currently registered Factory to create // the PrerenderContents. Factory is intended for testing. @@ -156,8 +151,7 @@ class PrerenderContents : public content::NotificationObserver, virtual void StartPrerendering( int creator_child_id, const gfx::Size& size, - content::SessionStorageNamespace* session_storage_namespace, - net::URLRequestContextGetter* request_context); + content::SessionStorageNamespace* session_storage_namespace); // Verifies that the prerendering is not using too many resources, and kills // it if not. diff --git a/chrome/browser/prerender/prerender_cookie_store.cc b/chrome/browser/prerender/prerender_cookie_store.cc deleted file mode 100644 index 3f94efc..0000000 --- a/chrome/browser/prerender/prerender_cookie_store.cc +++ /dev/null @@ -1,241 +0,0 @@ -// Copyright (c) 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/prerender/prerender_cookie_store.h" - -#include "base/logging.h" -#include "base/stl_util.h" -#include "content/public/browser/browser_thread.h" - -using content::BrowserThread; - -namespace prerender { - -PrerenderCookieStore::PrerenderCookieStore( - scoped_refptr<net::CookieMonster> default_cookie_monster, - const base::Closure& cookie_conflict_cb) - : in_forwarding_mode_(false), - default_cookie_monster_(default_cookie_monster), - changes_cookie_monster_(new net::CookieMonster(NULL, NULL)), - cookie_conflict_cb_(cookie_conflict_cb), - cookie_conflict_(false) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - DCHECK(default_cookie_monster_ != NULL); - DCHECK(default_cookie_monster_->loaded()); -} - -PrerenderCookieStore::~PrerenderCookieStore() { -} - -void PrerenderCookieStore::SetCookieWithOptionsAsync( - const GURL& url, - const std::string& cookie_line, - const net::CookieOptions& options, - const SetCookiesCallback& callback) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - - CookieOperation op; - op.op = COOKIE_OP_SET_COOKIE_WITH_OPTIONS_ASYNC; - op.url = url; - op.cookie_line = cookie_line; - op.options = options; - - GetCookieStoreForCookieOpAndLog(op)-> - SetCookieWithOptionsAsync(url, cookie_line, options, callback); -} - -void PrerenderCookieStore::GetCookiesWithOptionsAsync( - const GURL& url, - const net::CookieOptions& options, - const GetCookiesCallback& callback) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - CookieOperation op; - op.op = COOKIE_OP_GET_COOKIES_WITH_OPTIONS_ASYNC; - op.url = url; - op.options = options; - - GetCookieStoreForCookieOpAndLog(op)-> - GetCookiesWithOptionsAsync(url, options, callback); -} - -void PrerenderCookieStore::GetAllCookiesForURLAsync( - const GURL& url, - const GetCookieListCallback& callback) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - - CookieOperation op; - op.op = COOKIE_OP_GET_ALL_COOKIES_FOR_URL_ASYNC; - op.url = url; - - GetCookieStoreForCookieOpAndLog(op)->GetAllCookiesForURLAsync(url, callback); -} - - -void PrerenderCookieStore::DeleteCookieAsync(const GURL& url, - const std::string& cookie_name, - const base::Closure& callback) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - - CookieOperation op; - op.op = COOKIE_OP_DELETE_COOKIE_ASYNC; - op.url = url; - op.cookie_name = cookie_name; - - GetCookieStoreForCookieOpAndLog(op)->DeleteCookieAsync(url, cookie_name, - callback); -} - -void PrerenderCookieStore::DeleteAllCreatedBetweenAsync( - const base::Time& delete_begin, - const base::Time& delete_end, - const DeleteCallback& callback) { - NOTREACHED(); -} - -void PrerenderCookieStore::DeleteAllCreatedBetweenForHostAsync( - const base::Time delete_begin, - const base::Time delete_end, - const GURL& url, - const DeleteCallback& callback) { - NOTREACHED(); -} - -void PrerenderCookieStore::DeleteSessionCookiesAsync(const DeleteCallback&) { - NOTREACHED(); -} - -net::CookieMonster* PrerenderCookieStore::GetCookieMonster() { - NOTREACHED(); - return NULL; -} - -net::CookieStore* PrerenderCookieStore::GetCookieStoreForCookieOpAndLog( - const CookieOperation& op) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - - std::string key = default_cookie_monster_->GetKey(op.url.host()); - bool is_read_only = (op.op == COOKIE_OP_GET_COOKIES_WITH_OPTIONS_ASYNC || - op.op == COOKIE_OP_GET_ALL_COOKIES_FOR_URL_ASYNC); - - if (in_forwarding_mode_) - return default_cookie_monster_; - - DCHECK(changes_cookie_monster_ != NULL); - - cookie_ops_.push_back(op); - - bool key_copied = ContainsKey(copied_keys_, key); - - if (key_copied) - return changes_cookie_monster_; - - if (is_read_only) { - // Insert this key into the set of read keys, if it doesn't exist yet. - if (!ContainsKey(read_keys_, key)) - read_keys_.insert(key); - return default_cookie_monster_; - } - - // If this method hasn't returned yet, the key has not been copied yet, - // and we must copy it due to the requested write operation. - - bool copy_success = default_cookie_monster_-> - CopyCookiesForKeyToOtherCookieMonster(key, changes_cookie_monster_); - - // The copy must succeed. - DCHECK(copy_success); - - copied_keys_.insert(key); - - return changes_cookie_monster_; -} - -void PrerenderCookieStore::ApplyChanges(std::vector<GURL>* cookie_change_urls) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - - if (in_forwarding_mode_) - return; - - // Apply all changes to the underlying cookie store. - for (std::vector<CookieOperation>::const_iterator it = cookie_ops_.begin(); - it != cookie_ops_.end(); - ++it) { - switch (it->op) { - case COOKIE_OP_SET_COOKIE_WITH_OPTIONS_ASYNC: - cookie_change_urls->push_back(it->url); - default_cookie_monster_->SetCookieWithOptionsAsync( - it->url, it->cookie_line, it->options, SetCookiesCallback()); - break; - case COOKIE_OP_GET_COOKIES_WITH_OPTIONS_ASYNC: - default_cookie_monster_->GetCookiesWithOptionsAsync( - it->url, it->options, GetCookiesCallback()); - break; - case COOKIE_OP_GET_ALL_COOKIES_FOR_URL_ASYNC: - default_cookie_monster_->GetAllCookiesForURLAsync( - it->url, GetCookieListCallback()); - break; - case COOKIE_OP_DELETE_COOKIE_ASYNC: - cookie_change_urls->push_back(it->url); - default_cookie_monster_->DeleteCookieAsync( - it->url, it->cookie_name, base::Closure()); - break; - case COOKIE_OP_MAX: - NOTREACHED(); - } - } - - in_forwarding_mode_ = true; - copied_keys_.clear(); - cookie_ops_.clear(); - changes_cookie_monster_ = NULL; -} - -void PrerenderCookieStore::OnCookieChangedForURL( - net::CookieMonster* cookie_monster, - const GURL& url) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - - // If the cookie was changed in a different cookie monster than the one - // being decorated, there is nothing to do). - if (cookie_monster != default_cookie_monster_) - return; - - if (in_forwarding_mode_) - return; - - // If we have encountered a conflict before, it has already been recorded - // and the cb has been issued, so nothing to do. - if (cookie_conflict_) - return; - - std::string key = default_cookie_monster_->GetKey(url.host()); - - // If the key for the cookie which was modified was neither read nor written, - // nothing to do. - if ((!ContainsKey(read_keys_, key)) && (!ContainsKey(copied_keys_, key))) - return; - - // There was a conflict in cookies. Call the conflict callback, which should - // cancel the prerender if necessary (i.e. if it hasn't already been - // cancelled for some other reason). - // Notice that there is a race here with swapping in the prerender, but this - // is the same issue that occurs when two tabs modify cookies for the - // same domain concurrently. Therefore, there is no need to do anything - // special to prevent this race condition. - cookie_conflict_ = true; - if (!cookie_conflict_cb_.is_null()) { - BrowserThread::PostTask( - BrowserThread::UI, - FROM_HERE, - cookie_conflict_cb_); - } -} - -PrerenderCookieStore::CookieOperation::CookieOperation() { -} - -PrerenderCookieStore::CookieOperation::~CookieOperation() { -} - -} // namespace prerender diff --git a/chrome/browser/prerender/prerender_cookie_store.h b/chrome/browser/prerender/prerender_cookie_store.h deleted file mode 100644 index 2290486..0000000 --- a/chrome/browser/prerender/prerender_cookie_store.h +++ /dev/null @@ -1,164 +0,0 @@ -// Copyright (c) 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_PRERENDER_PRERENDER_COOKIE_STORE_H_ -#define CHROME_BROWSER_PRERENDER_PRERENDER_COOKIE_STORE_H_ - -#include <set> -#include <string> -#include <vector> - -#include "base/callback.h" -#include "base/compiler_specific.h" -#include "base/macros.h" -#include "base/memory/ref_counted.h" -#include "net/cookies/cookie_monster.h" -#include "net/cookies/cookie_store.h" -#include "url/gurl.h" - -namespace prerender { - -// A cookie store which keeps track of provisional changes to the cookie monster -// of an underlying request context (called the default cookie monster). -// Initially, it will proxy read requests to the default cookie monster, and -// copy on write keys that are being modified into a private cookie monster. -// Reads for these will then happen from the private cookie monster. -// Should keys be modified in the default cookie store, the corresponding -// prerender should be aborted. -// This class also keeps a log of all cookie transactions. Once ApplyChanges -// is called, the changes will be applied to the default cookie monster, -// and any future requests to this object will simply be forwarded to the -// default cookie monster. After ApplyChanges is called, the prerender tracker, -// which "owns" the PrerenderCookieStore reference, will remove its entry for -// the PrerenderCookieStore. Therefore, after ApplyChanges is called, the -// object will only stick around (and exhibit forwarding mode) as long as -// eg pending requests hold on to its reference. -class PrerenderCookieStore : public net::CookieStore { - public: - // Creates a PrerenderCookieStore using the default cookie monster provided - // by the URLRequestContext. The underlying cookie store must be loaded, - // ie it's call to loaded() must return true. - // Otherwise, copying cookie data between the prerender cookie store - // (used to only commit cookie changes once a prerender is shown) would - // not work synchronously, which would complicate the code. - // |cookie_conflict_cb| will be called when a cookie conflict is detected. - // The callback will be run on the UI thread. - PrerenderCookieStore(scoped_refptr<net::CookieMonster> default_cookie_store_, - const base::Closure& cookie_conflict_cb); - - // CookieStore implementation - virtual void SetCookieWithOptionsAsync( - const GURL& url, - const std::string& cookie_line, - const net::CookieOptions& options, - const SetCookiesCallback& callback) OVERRIDE; - - virtual void GetCookiesWithOptionsAsync( - const GURL& url, - const net::CookieOptions& options, - const GetCookiesCallback& callback) OVERRIDE; - - virtual void GetAllCookiesForURLAsync( - const GURL& url, - const GetCookieListCallback& callback) OVERRIDE; - - virtual void DeleteCookieAsync(const GURL& url, - const std::string& cookie_name, - const base::Closure& callback) OVERRIDE; - - // All the following methods should not be used in the scenarios where - // a PrerenderCookieStore is used. This will be checked via NOTREACHED(). - // Should PrerenderCookieStore used in contexts requiring these, they will - // need to be implemented first. They are only intended to be called on the - // IO thread. - - virtual void DeleteAllCreatedBetweenAsync( - const base::Time& delete_begin, - const base::Time& delete_end, - const DeleteCallback& callback) OVERRIDE; - - virtual void DeleteAllCreatedBetweenForHostAsync( - const base::Time delete_begin, - const base::Time delete_end, - const GURL& url, - const DeleteCallback& callback) OVERRIDE; - - virtual void DeleteSessionCookiesAsync(const DeleteCallback&) OVERRIDE; - - virtual net::CookieMonster* GetCookieMonster() OVERRIDE; - - // Commits the changes made to the underlying cookie store, and switches - // into forwarding mode. To be called on the IO thread. - // |cookie_change_urls| will be populated with all URLs for which cookies - // were updated. - void ApplyChanges(std::vector<GURL>* cookie_change_urls); - - // Called when a cookie for a URL is changed in the underlying default cookie - // store. To be called on the IO thread. If the key corresponding to the URL - // was copied or read, the prerender will be cancelled. - void OnCookieChangedForURL(net::CookieMonster* cookie_monster, - const GURL& url); - - net::CookieMonster* default_cookie_monster() { - return default_cookie_monster_; - } - - private: - enum CookieOperationType { - COOKIE_OP_SET_COOKIE_WITH_OPTIONS_ASYNC, - COOKIE_OP_GET_COOKIES_WITH_OPTIONS_ASYNC, - COOKIE_OP_GET_ALL_COOKIES_FOR_URL_ASYNC, - COOKIE_OP_DELETE_COOKIE_ASYNC, - COOKIE_OP_MAX - }; - - struct CookieOperation { - CookieOperationType op; - GURL url; - net::CookieOptions options; - std::string cookie_line; - std::string cookie_name; - CookieOperation(); - ~CookieOperation(); - }; - - virtual ~PrerenderCookieStore(); - - // Gets the appropriate cookie store for the operation provided, and pushes - // it back on the log of cookie operations performed. - net::CookieStore* GetCookieStoreForCookieOpAndLog(const CookieOperation& op); - - // Indicates whether the changes have already been applied (ie the prerender - // has been shown), and we are merely in forwarding mode; - bool in_forwarding_mode_; - - // The default cookie monster. - scoped_refptr<net::CookieMonster> default_cookie_monster_; - - // A cookie monster storing changes made by the prerender. - // Entire keys are copied from default_cookie_monster_ on change, and then - // modified. - scoped_refptr<net::CookieMonster> changes_cookie_monster_; - - // Log of cookie operations performed - std::vector<CookieOperation> cookie_ops_; - - // The keys which have been copied on write to |changes_cookie_monster_|. - std::set<std::string> copied_keys_; - - // Keys which have been read (but not necessarily been modified). - std::set<std::string> read_keys_; - - // Callback when a cookie conflict was detected - base::Closure cookie_conflict_cb_; - - // Indicates whether a cookie conflict has been detected yet. - bool cookie_conflict_; - - DISALLOW_COPY_AND_ASSIGN(PrerenderCookieStore); -}; - -} // namespace prerender - -#endif // CHROME_BROWSER_PRERENDER_PRERENDER_COOKIE_STORE_H_ diff --git a/chrome/browser/prerender/prerender_final_status.cc b/chrome/browser/prerender/prerender_final_status.cc index adeaf49..ac0526d 100644 --- a/chrome/browser/prerender/prerender_final_status.cc +++ b/chrome/browser/prerender/prerender_final_status.cc @@ -59,8 +59,6 @@ const char* kFinalStatusNames[] = { "Bad Deferred Redirect", "Navigation Uncommitted", "New Navigation Entry", - "Cookie Store Not Loaded", - "Cookie Conflict", "Max", }; COMPILE_ASSERT(arraysize(kFinalStatusNames) == FINAL_STATUS_MAX + 1, diff --git a/chrome/browser/prerender/prerender_final_status.h b/chrome/browser/prerender/prerender_final_status.h index 412be21..8551c10 100644 --- a/chrome/browser/prerender/prerender_final_status.h +++ b/chrome/browser/prerender/prerender_final_status.h @@ -60,8 +60,6 @@ enum FinalStatus { FINAL_STATUS_BAD_DEFERRED_REDIRECT = 45, FINAL_STATUS_NAVIGATION_UNCOMMITTED = 46, FINAL_STATUS_NEW_NAVIGATION_ENTRY = 47, - FINAL_STATUS_COOKIE_STORE_NOT_LOADED = 48, - FINAL_STATUS_COOKIE_CONFLICT = 49, FINAL_STATUS_MAX, }; diff --git a/chrome/browser/prerender/prerender_manager.cc b/chrome/browser/prerender/prerender_manager.cc index e834471..d36a502 100644 --- a/chrome/browser/prerender/prerender_manager.cc +++ b/chrome/browser/prerender/prerender_manager.cc @@ -58,7 +58,6 @@ #include "content/public/browser/render_process_host.h" #include "content/public/browser/render_view_host.h" #include "content/public/browser/session_storage_namespace.h" -#include "content/public/browser/storage_partition.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_delegate.h" #include "content/public/common/url_constants.h" @@ -246,8 +245,7 @@ PrerenderManager::PrerenderManager(Profile* profile, prerender_history_(new PrerenderHistory(kHistoryLength)), histograms_(new PrerenderHistograms()), profile_network_bytes_(0), - last_recorded_profile_network_bytes_(0), - cookie_store_loaded_(false) { + last_recorded_profile_network_bytes_(0) { // There are some assumptions that the PrerenderManager is on the UI thread. // Any other checks simply make sure that the PrerenderManager is accessed on // the same thread that it was created on. @@ -305,13 +303,6 @@ PrerenderManager::~PrerenderManager() { // emptied these vectors already. DCHECK(active_prerenders_.empty()); DCHECK(to_delete_prerenders_.empty()); - - for (PrerenderProcessSet::const_iterator it = - prerender_process_hosts_.begin(); - it != prerender_process_hosts_.end(); - ++it) { - (*it)->RemoveObserver(this); - } } void PrerenderManager::Shutdown() { @@ -586,14 +577,6 @@ WebContents* PrerenderManager::SwapInternal( } // At this point, we've determined that we will use the prerender. - content::RenderProcessHost* process_host = - prerender_data->contents()->GetRenderViewHost()->GetProcess(); - prerender_process_hosts_.erase(process_host); - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - base::Bind(&PrerenderTracker::RemovePrerenderCookieStoreOnIOThread, - base::Unretained(prerender_tracker()), process_host->GetID(), - true)); if (!prerender_data->contents()->load_start_time().is_null()) { histograms_->RecordTimeUntilUsed( prerender_data->contents()->origin(), @@ -765,7 +748,7 @@ const char* PrerenderManager::GetModeString() { default: NOTREACHED() << "Invalid PrerenderManager mode."; break; - } + }; return ""; } @@ -1233,12 +1216,6 @@ void PrerenderManager::SourceNavigatedAway(PrerenderData* prerender_data) { SortActivePrerenders(); } -net::URLRequestContextGetter* PrerenderManager::GetURLRequestContext() { - return content::BrowserContext::GetDefaultStoragePartition(profile_)-> - GetURLRequestContext(); -} - - // private PrerenderHandle* PrerenderManager::AddPrerender( Origin origin, @@ -1303,13 +1280,6 @@ PrerenderHandle* PrerenderManager::AddPrerender( return NULL; } - if (!cookie_store_loaded()) { - // Only prerender if the cookie store for this profile has been loaded. - // This is required by PrerenderCookieMonster. - RecordFinalStatus(origin, experiment, FINAL_STATUS_COOKIE_STORE_NOT_LOADED); - return NULL; - } - PrerenderContents* prerender_contents = CreatePrerenderContents( url, referrer, origin, experiment); DCHECK(prerender_contents); @@ -1334,16 +1304,11 @@ PrerenderHandle* PrerenderManager::AddPrerender( gfx::Size contents_size = size.IsEmpty() ? config_.default_tab_bounds.size() : size; - net::URLRequestContextGetter* request_context = GetURLRequestContext(); - prerender_contents->StartPrerendering(process_id, contents_size, - session_storage_namespace, - request_context); + session_storage_namespace); DCHECK(IsControlGroup(experiment) || - prerender_contents->prerendering_has_started() || - (origin == ORIGIN_LOCAL_PREDICTOR && - IsLocalPredictorPrerenderAlwaysControlEnabled())); + prerender_contents->prerendering_has_started()); if (GetMode() == PRERENDER_MODE_EXPERIMENT_MULTI_PRERENDER_GROUP) histograms_->RecordConcurrency(active_prerenders_.size()); @@ -1861,36 +1826,4 @@ void PrerenderManager::AddProfileNetworkBytesIfEnabled(int64 bytes) { profile_network_bytes_ += bytes; } -void PrerenderManager::OnCookieStoreLoaded() { - cookie_store_loaded_ = true; - if (!on_cookie_store_loaded_cb_for_testing_.is_null()) - on_cookie_store_loaded_cb_for_testing_.Run(); -} - -void PrerenderManager::AddPrerenderProcessHost( - content::RenderProcessHost* process_host) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - DCHECK(prerender_process_hosts_.find(process_host) == - prerender_process_hosts_.end()); - prerender_process_hosts_.insert(process_host); - process_host->AddObserver(this); -} - -bool PrerenderManager::IsProcessPrerendering( - content::RenderProcessHost* process_host) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - return (prerender_process_hosts_.find(process_host) != - prerender_process_hosts_.end()); -} - -void PrerenderManager::RenderProcessHostDestroyed( - content::RenderProcessHost* host) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - prerender_process_hosts_.erase(host); - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - base::Bind(&PrerenderTracker::RemovePrerenderCookieStoreOnIOThread, - base::Unretained(prerender_tracker()), host->GetID(), false)); -} - } // namespace prerender diff --git a/chrome/browser/prerender/prerender_manager.h b/chrome/browser/prerender/prerender_manager.h index c91322d..6861b7b 100644 --- a/chrome/browser/prerender/prerender_manager.h +++ b/chrome/browser/prerender/prerender_manager.h @@ -31,7 +31,6 @@ #include "components/keyed_service/core/keyed_service.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" -#include "content/public/browser/render_process_host_observer.h" #include "content/public/browser/session_storage_namespace.h" #include "content/public/browser/web_contents_observer.h" #include "net/cookies/canonical_cookie.h" @@ -75,7 +74,6 @@ class PrerenderLocalPredictor; class PrerenderManager : public base::SupportsWeakPtr<PrerenderManager>, public base::NonThreadSafe, public content::NotificationObserver, - public content::RenderProcessHostObserver, public KeyedService, public MediaCaptureDevicesDispatcher::Observer { public: @@ -297,8 +295,6 @@ class PrerenderManager : public base::SupportsWeakPtr<PrerenderManager>, PrerenderTracker* prerender_tracker() { return prerender_tracker_; } - bool cookie_store_loaded() { return cookie_store_loaded_; } - // Adds a condition. This is owned by the PrerenderManager. void AddCondition(const PrerenderCondition* condition); @@ -364,25 +360,6 @@ class PrerenderManager : public base::SupportsWeakPtr<PrerenderManager>, // profile if prerendering is currently enabled. void AddProfileNetworkBytesIfEnabled(int64 bytes); - // Registers a new ProcessHost performing a prerender. Called by - // PrerenderContents. - void AddPrerenderProcessHost(content::RenderProcessHost* process_host); - - bool IsProcessPrerendering(content::RenderProcessHost* process_host); - - // content::RenderProcessHostObserver implementation. - virtual void RenderProcessHostDestroyed( - content::RenderProcessHost* host) OVERRIDE; - - // To be called once the cookie store for this profile has been loaded. - void OnCookieStoreLoaded(); - - // For testing purposes. Issues a callback once the cookie store has been - // loaded. - void set_on_cookie_store_loaded_cb_for_testing(base::Closure cb) { - on_cookie_store_loaded_cb_for_testing_ = cb; - } - protected: class PendingSwap; class PrerenderData : public base::SupportsWeakPtr<PrerenderData> { @@ -533,11 +510,6 @@ class PrerenderManager : public base::SupportsWeakPtr<PrerenderManager>, // shorten the TTL of the prerendered page. void SourceNavigatedAway(PrerenderData* prerender_data); - // Gets the request context for the profile. - // For unit tests, this will be overriden to return NULL, since it is not - // needed. - virtual net::URLRequestContextGetter* GetURLRequestContext(); - private: friend class ::InstantSearchPrerendererTest; friend class PrerenderBrowserTest; @@ -747,15 +719,6 @@ class PrerenderManager : public base::SupportsWeakPtr<PrerenderManager>, // The value of profile_network_bytes_ that was last recorded. int64 last_recorded_profile_network_bytes_; - // Set of process hosts being prerendered. - typedef std::set<content::RenderProcessHost*> PrerenderProcessSet; - PrerenderProcessSet prerender_process_hosts_; - - // Indicates whether the cookie store for this profile has fully loaded yet. - bool cookie_store_loaded_; - - base::Closure on_cookie_store_loaded_cb_for_testing_; - DISALLOW_COPY_AND_ASSIGN(PrerenderManager); }; diff --git a/chrome/browser/prerender/prerender_tracker.cc b/chrome/browser/prerender/prerender_tracker.cc index cabb35b..b44c8d3 100644 --- a/chrome/browser/prerender/prerender_tracker.cc +++ b/chrome/browser/prerender/prerender_tracker.cc @@ -8,9 +8,6 @@ #include "base/logging.h" #include "chrome/browser/prerender/prerender_pending_swap_throttle.h" #include "content/public/browser/browser_thread.h" -#include "content/public/browser/render_process_host.h" -#include "net/url_request/url_request_context.h" -#include "net/url_request/url_request_context_getter.h" using content::BrowserThread; @@ -106,88 +103,4 @@ PrerenderTracker::PendingSwapThrottleData::PendingSwapThrottleData( PrerenderTracker::PendingSwapThrottleData::~PendingSwapThrottleData() { } -scoped_refptr<PrerenderCookieStore> -PrerenderTracker::GetPrerenderCookieStoreForRenderProcess( - int process_id) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - PrerenderCookieStoreMap::const_iterator it = - prerender_cookie_store_map_.find(process_id); - - if (it == prerender_cookie_store_map_.end()) - return NULL; - - return it->second; -} - -void PrerenderTracker::OnCookieChangedForURL( - int process_id, - net::CookieMonster* cookie_monster, - const GURL& url) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - - // We only care about cookie changes by non-prerender tabs, since only those - // get applied to the underlying cookie store. Therefore, if a cookie change - // originated from a prerender, there is nothing to do. - if (ContainsKey(prerender_cookie_store_map_, process_id)) - return; - - // Since the cookie change did not come from a prerender, broadcast it too - // all prerenders so that they can be cancelled if there is a conflict. - for (PrerenderCookieStoreMap::iterator it = - prerender_cookie_store_map_.begin(); - it != prerender_cookie_store_map_.end(); - ++it) { - it->second->OnCookieChangedForURL(cookie_monster, url); - } -} - -void PrerenderTracker::RemovePrerenderCookieStoreOnIOThread(int process_id, - bool was_swapped) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - - PrerenderCookieStoreMap::iterator it = - prerender_cookie_store_map_.find(process_id); - - if (it == prerender_cookie_store_map_.end()) - return; - - std::vector<GURL> cookie_change_urls; - if (was_swapped) - it->second->ApplyChanges(&cookie_change_urls); - - scoped_refptr<net::CookieMonster> cookie_monster( - it->second->default_cookie_monster()); - - prerender_cookie_store_map_.erase(it); - - // For each cookie updated by ApplyChanges, we need to call - // OnCookieChangedForURL so that any potentially conflicting prerenders - // will be aborted. - for (std::vector<GURL>::const_iterator url_it = cookie_change_urls.begin(); - url_it != cookie_change_urls.end(); - ++url_it) { - OnCookieChangedForURL(process_id, cookie_monster, *url_it); - } -} - -void PrerenderTracker::AddPrerenderCookieStoreOnIOThread( - int process_id, - scoped_refptr<net::URLRequestContextGetter> request_context, - const base::Closure& cookie_conflict_cb) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - DCHECK(request_context != NULL); - net::CookieMonster* cookie_monster = - request_context->GetURLRequestContext()->cookie_store()-> - GetCookieMonster(); - DCHECK(cookie_monster != NULL); - bool exists = (prerender_cookie_store_map_.find(process_id) != - prerender_cookie_store_map_.end()); - DCHECK(!exists); - if (exists) - return; - prerender_cookie_store_map_[process_id] = - new PrerenderCookieStore(make_scoped_refptr(cookie_monster), - cookie_conflict_cb); -} - } // namespace prerender diff --git a/chrome/browser/prerender/prerender_tracker.h b/chrome/browser/prerender/prerender_tracker.h index 6020658..f9dd17b 100644 --- a/chrome/browser/prerender/prerender_tracker.h +++ b/chrome/browser/prerender/prerender_tracker.h @@ -6,26 +6,16 @@ #define CHROME_BROWSER_PRERENDER_PRERENDER_TRACKER_H_ #include <map> -#include <set> #include <utility> -#include "base/containers/hash_tables.h" -#include "base/memory/ref_counted.h" #include "base/memory/weak_ptr.h" -#include "base/synchronization/lock.h" -#include "chrome/browser/prerender/prerender_cookie_store.h" -#include "content/public/browser/render_process_host_observer.h" #include "url/gurl.h" -namespace net { -class URLRequestContextGetter; -} - namespace prerender { class PrerenderPendingSwapThrottle; -// Global object for maintaining various prerender state on the IO thread. +// Global object for maintaining prerender state on the IO thread. class PrerenderTracker { public: typedef std::pair<int, int> ChildRouteIdPair; @@ -56,25 +46,6 @@ class PrerenderTracker { const ChildRouteIdPair& render_frame_route_id_pair, bool swap_successful); - // Gets the Prerender Cookie Store for a specific render process, if it - // is a prerender. Only to be called from the IO thread. - scoped_refptr<PrerenderCookieStore> GetPrerenderCookieStoreForRenderProcess( - int process_id); - - // Called when a given render process has changed a cookie for |url|, - // in |cookie_monster|. - // Only to be called from the IO thread. - void OnCookieChangedForURL(int process_id, - net::CookieMonster* cookie_monster, - const GURL& url); - - void AddPrerenderCookieStoreOnIOThread( - int process_id, - scoped_refptr<net::URLRequestContextGetter> request_context, - const base::Closure& cookie_conflict_cb); - - void RemovePrerenderCookieStoreOnIOThread(int process_id, bool was_swapped); - private: // Add/remove prerenders pending swap on the IO Thread. void AddPrerenderPendingSwapOnIOThread( @@ -97,12 +68,6 @@ class PrerenderTracker { PendingSwapThrottleMap; PendingSwapThrottleMap pending_swap_throttle_map_; - // Map of prerendering render process ids to PrerenderCookieStore used for - // the prerender. Only to be used on the IO thread. - typedef base::hash_map<int, scoped_refptr<PrerenderCookieStore> > - PrerenderCookieStoreMap; - PrerenderCookieStoreMap prerender_cookie_store_map_; - DISALLOW_COPY_AND_ASSIGN(PrerenderTracker); }; diff --git a/chrome/browser/prerender/prerender_unittest.cc b/chrome/browser/prerender/prerender_unittest.cc index 6a8a16d..1af24ea 100644 --- a/chrome/browser/prerender/prerender_unittest.cc +++ b/chrome/browser/prerender/prerender_unittest.cc @@ -52,8 +52,7 @@ class DummyPrerenderContents : public PrerenderContents { virtual void StartPrerendering( int ALLOW_UNUSED creator_child_id, const gfx::Size& ALLOW_UNUSED size, - content::SessionStorageNamespace* ALLOW_UNUSED session_storage_namespace, - net::URLRequestContextGetter* ALLOW_UNUSED request_context) + content::SessionStorageNamespace* ALLOW_UNUSED session_storage_namespace) OVERRIDE; virtual bool GetChildId(int* child_id) const OVERRIDE { @@ -102,7 +101,6 @@ class UnitTestPrerenderManager : public PrerenderManager { time_ticks_(TimeTicks::Now()), prerender_tracker_(prerender_tracker) { set_rate_limit_enabled(false); - OnCookieStoreLoaded(); } virtual ~UnitTestPrerenderManager() { @@ -231,11 +229,6 @@ class UnitTestPrerenderManager : public PrerenderManager { prerender_contents_map_.erase(std::make_pair(child_id, route_id)); } - protected: - virtual net::URLRequestContextGetter* GetURLRequestContext() OVERRIDE { - return NULL; - } - private: void SetNextPrerenderContents(DummyPrerenderContents* prerender_contents) { CHECK(!next_prerender_contents_.get()); @@ -303,8 +296,7 @@ DummyPrerenderContents::~DummyPrerenderContents() { void DummyPrerenderContents::StartPrerendering( int ALLOW_UNUSED creator_child_id, const gfx::Size& ALLOW_UNUSED size, - content::SessionStorageNamespace* ALLOW_UNUSED session_storage_namespace, - net::URLRequestContextGetter* ALLOW_UNUSED request_context) { + content::SessionStorageNamespace* ALLOW_UNUSED session_storage_namespace) { // In the base PrerenderContents implementation, StartPrerendering will // be called even when the PrerenderManager is part of the control group, // but it will early exit before actually creating a new RenderView if diff --git a/chrome/browser/profiles/profile_io_data.cc b/chrome/browser/profiles/profile_io_data.cc index 9a4234f..ba8b91e 100644 --- a/chrome/browser/profiles/profile_io_data.cc +++ b/chrome/browser/profiles/profile_io_data.cc @@ -366,7 +366,6 @@ void ProfileIOData::InitializeOnUIThread(Profile* profile) { #endif params->profile = profile; - params->prerender_tracker = g_browser_process->prerender_tracker(); profile_params_.reset(params.release()); ChromeNetworkDelegate::InitializePrefsOnUIThread( @@ -949,7 +948,6 @@ void ProfileIOData::Init( network_delegate->set_cookie_settings(profile_params_->cookie_settings.get()); network_delegate->set_enable_do_not_track(&enable_do_not_track_); network_delegate->set_force_google_safe_search(&force_safesearch_); - network_delegate->set_prerender_tracker(profile_params_->prerender_tracker); network_delegate_.reset(network_delegate); fraudulent_certificate_reporter_.reset( diff --git a/chrome/browser/profiles/profile_io_data.h b/chrome/browser/profiles/profile_io_data.h index aee3ea0..43b46d5 100644 --- a/chrome/browser/profiles/profile_io_data.h +++ b/chrome/browser/profiles/profile_io_data.h @@ -61,10 +61,6 @@ class PolicyHeaderIOHelper; class URLBlacklistManager; } // namespace policy -namespace prerender { -class PrerenderTracker; -} - // Conceptually speaking, the ProfileIOData represents data that lives on the IO // thread that is owned by a Profile, such as, but not limited to, network // objects like CookieMonster, HttpTransactionFactory, etc. Profile owns @@ -302,8 +298,6 @@ class ProfileIOData { // ensure it's not accidently used on the IO thread. Before using it on the // UI thread, call ProfileManager::IsValidProfile to ensure it's alive. void* profile; - - prerender::PrerenderTracker* prerender_tracker; }; explicit ProfileIOData(Profile::ProfileType profile_type); diff --git a/chrome/browser/ui/search/instant_search_prerenderer_unittest.cc b/chrome/browser/ui/search/instant_search_prerenderer_unittest.cc index cc8ca49..f4ba748 100644 --- a/chrome/browser/ui/search/instant_search_prerenderer_unittest.cc +++ b/chrome/browser/ui/search/instant_search_prerenderer_unittest.cc @@ -59,8 +59,7 @@ class DummyPrerenderContents : public PrerenderContents { virtual void StartPrerendering( int ALLOW_UNUSED creator_child_id, const gfx::Size& ALLOW_UNUSED size, - content::SessionStorageNamespace* session_storage_namespace, - net::URLRequestContextGetter* request_context) OVERRIDE; + content::SessionStorageNamespace* session_storage_namespace) OVERRIDE; virtual bool GetChildId(int* child_id) const OVERRIDE; virtual bool GetRouteId(int* route_id) const OVERRIDE; @@ -116,8 +115,7 @@ DummyPrerenderContents::DummyPrerenderContents( void DummyPrerenderContents::StartPrerendering( int ALLOW_UNUSED creator_child_id, const gfx::Size& ALLOW_UNUSED size, - content::SessionStorageNamespace* session_storage_namespace, - net::URLRequestContextGetter* request_context) { + content::SessionStorageNamespace* session_storage_namespace) { prerender_contents_.reset(content::WebContents::CreateWithSessionStorage( content::WebContents::CreateParams(profile_), session_storage_namespace_map_)); @@ -183,8 +181,7 @@ class InstantSearchPrerendererTest : public InstantUnitTestBase { SetPrerenderContentsFactory( new DummyPrerenderContentsFactory(call_did_finish_load, session_storage_namespace_map)); - PrerenderManagerFactory::GetForProfile(browser()->profile())-> - OnCookieStoreLoaded(); + if (prerender_search_results_base_page) { InstantSearchPrerenderer* prerenderer = GetInstantSearchPrerenderer(); prerenderer->Init(session_storage_namespace_map, gfx::Size(640, 480)); diff --git a/chrome/browser/ui/webui/net_internals/net_internals_ui_browsertest.cc b/chrome/browser/ui/webui/net_internals/net_internals_ui_browsertest.cc index 3d60cc0..6f62e8d 100644 --- a/chrome/browser/ui/webui/net_internals/net_internals_ui_browsertest.cc +++ b/chrome/browser/ui/webui/net_internals/net_internals_ui_browsertest.cc @@ -398,12 +398,6 @@ void NetInternalsTest::SetUpOnMainThread() { prerender::PrerenderManager* prerender_manager = prerender::PrerenderManagerFactory::GetForProfile(profile); prerender_manager->mutable_config().max_bytes = 1000 * 1024 * 1024; - if (!prerender_manager->cookie_store_loaded()) { - base::RunLoop loop; - prerender_manager->set_on_cookie_store_loaded_cb_for_testing( - loop.QuitClosure()); - loop.Run(); - } } content::WebUIMessageHandler* NetInternalsTest::GetMockMessageHandler() { |