Index: chrome/browser/prerender/prerender_tracker.cc |
=================================================================== |
--- chrome/browser/prerender/prerender_tracker.cc (revision 265252) |
+++ chrome/browser/prerender/prerender_tracker.cc (working copy) |
@@ -8,6 +8,9 @@ |
#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; |
@@ -18,6 +21,12 @@ |
} |
PrerenderTracker::~PrerenderTracker() { |
+ for (PrerenderProcessSet::const_iterator it = |
+ prerender_process_hosts_.begin(); |
+ it != prerender_process_hosts_.end(); |
+ ++it) { |
+ (*it)->RemoveObserver(this); |
+ } |
} |
bool PrerenderTracker::IsPendingSwapRequestOnIOThread( |
@@ -103,4 +112,110 @@ |
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; |
+} |
+ |
+bool PrerenderTracker::IsProcessPrerendering( |
+ content::RenderProcessHost* process_host) { |
+ return (prerender_process_hosts_.find(process_host) != |
+ prerender_process_hosts_.end()); |
+} |
+ |
+void PrerenderTracker::OnCookieChangedForURL(int process_id, const GURL& url) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
+ |
+ for (PrerenderCookieStoreMap::iterator it = |
+ prerender_cookie_store_map_.begin(); |
+ it != prerender_cookie_store_map_.end(); |
+ ++it) { |
+ // Report the change to all prerender cookie stores which may be affected. |
+ // This does not include the one for the render process originating the |
+ // change. |
+ if (it->first != process_id) |
+ it->second->OnCookieChangedForURL(url); |
+ } |
+} |
+ |
+void PrerenderTracker::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(this), host->GetID(), false)); |
+} |
+ |
+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; |
+ |
+ if (was_swapped) |
+ it->second->ApplyChanges(); |
+ |
+ prerender_cookie_store_map_.erase(it); |
+} |
+ |
+void PrerenderTracker::OnPrerenderSwapped(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(this), host->GetID(), true)); |
+} |
+ |
+void PrerenderTracker::AddPrerender( |
+ content::RenderProcessHost* host, |
+ net::URLRequestContextGetter* request_context, |
+ const base::Closure& cookie_conflict_cb) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ DCHECK(request_context != NULL); |
+ DCHECK(prerender_process_hosts_.find(host)== prerender_process_hosts_.end()); |
+ prerender_process_hosts_.insert(host); |
+ host->AddObserver(this); |
+ BrowserThread::PostTask( |
+ BrowserThread::IO, FROM_HERE, |
+ base::Bind(&PrerenderTracker::AddPrerenderCookieStoreOnIOThread, |
+ base::Unretained(this), host->GetID(), |
+ make_scoped_refptr(request_context), |
+ cookie_conflict_cb)); |
+} |
+ |
+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 |