summaryrefslogtreecommitdiffstats
path: root/chrome/browser/prerender/prerender_tracker.cc
diff options
context:
space:
mode:
authortburkard@chromium.org <tburkard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-26 00:53:33 +0000
committertburkard@chromium.org <tburkard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-26 00:53:33 +0000
commitf4892bdad475bf8902396feb5118273acbb58237 (patch)
tree5245c8d7950245a468e1a316992925a35f5a3831 /chrome/browser/prerender/prerender_tracker.cc
parent2cc701697811ec8be880549c6e84443672fac8d7 (diff)
downloadchromium_src-f4892bdad475bf8902396feb5118273acbb58237.zip
chromium_src-f4892bdad475bf8902396feb5118273acbb58237.tar.gz
chromium_src-f4892bdad475bf8902396feb5118273acbb58237.tar.bz2
When there is a session storage namespace mismatch during prerender swap-in, attempt merging namespaces.
Re-submission of https://codereview.chromium.org/59823003/ see other lgtm's there Review URL: https://codereview.chromium.org/86593004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@237203 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/prerender/prerender_tracker.cc')
-rw-r--r--chrome/browser/prerender/prerender_tracker.cc99
1 files changed, 97 insertions, 2 deletions
diff --git a/chrome/browser/prerender/prerender_tracker.cc b/chrome/browser/prerender/prerender_tracker.cc
index 8a80802..6588f9d 100644
--- a/chrome/browser/prerender/prerender_tracker.cc
+++ b/chrome/browser/prerender/prerender_tracker.cc
@@ -8,14 +8,13 @@
#include "base/logging.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/prerender/prerender_manager.h"
+#include "chrome/browser/prerender/prerender_pending_swap_throttle.h"
#include "chrome/browser/prerender/prerender_resource_throttle.h"
#include "content/public/browser/browser_thread.h"
-#include "content/public/browser/render_view_host.h"
#include "content/public/browser/resource_context.h"
#include "net/base/load_flags.h"
using content::BrowserThread;
-using content::RenderViewHost;
namespace prerender {
@@ -192,6 +191,16 @@ bool PrerenderTracker::IsPrerenderingOnIOThread(int child_id,
return resource_throttle_io_thread_map_.count(child_route_id_pair) > 0;
}
+bool PrerenderTracker::IsPendingSwapRequestOnIOThread(
+ int child_id, int route_id, const GURL& url) const {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+
+ ChildRouteIdPair child_route_id_pair(child_id, route_id);
+ PendingSwapThrottleMap::const_iterator it =
+ pending_swap_throttle_map_.find(child_route_id_pair);
+ return (it != pending_swap_throttle_map_.end() && it->second.url == url);
+}
+
void PrerenderTracker::AddResourceThrottleOnIOThread(
int child_id,
int route_id,
@@ -205,6 +214,22 @@ void PrerenderTracker::AddResourceThrottleOnIOThread(
resource_throttle_map_it->second.push_back(throttle);
}
+void PrerenderTracker::AddPendingSwapThrottleOnIOThread(
+ int child_id,
+ int route_id,
+ const GURL& url,
+ const base::WeakPtr<PrerenderPendingSwapThrottle>& throttle) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+
+ ChildRouteIdPair child_route_id_pair(child_id, route_id);
+ PendingSwapThrottleMap::iterator it =
+ pending_swap_throttle_map_.find(child_route_id_pair);
+ DCHECK(it != pending_swap_throttle_map_.end());
+ if (it == pending_swap_throttle_map_.end())
+ return;
+ it->second.throttles.push_back(throttle);
+}
+
void PrerenderTracker::AddPrerenderOnIOThread(
const ChildRouteIdPair& child_route_id_pair) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
@@ -239,6 +264,61 @@ void PrerenderTracker::RemovePrerenderOnIOThread(
resource_throttle_io_thread_map_.erase(resource_throttle_map_it);
}
+void PrerenderTracker::AddPrerenderPendingSwapOnIOThread(
+ const ChildRouteIdPair& child_route_id_pair,
+ const GURL& url) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ std::pair<PendingSwapThrottleMap::iterator, bool> insert_result =
+ pending_swap_throttle_map_.insert(std::make_pair(
+ child_route_id_pair, PendingSwapThrottleData(url)));
+ DCHECK(insert_result.second);
+}
+
+void PrerenderTracker::RemovePrerenderPendingSwapOnIOThread(
+ const ChildRouteIdPair& child_route_id_pair,
+ bool swap_successful) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ PendingSwapThrottleMap::iterator it =
+ pending_swap_throttle_map_.find(child_route_id_pair);
+ DCHECK(it != pending_swap_throttle_map_.end());
+ // Cancel or resume all throttled resources.
+ for (size_t i = 0; i < it->second.throttles.size(); i++) {
+ if (!it->second.throttles[i])
+ continue;
+ if (swap_successful)
+ it->second.throttles[i]->Cancel();
+ else
+ it->second.throttles[i]->Resume();
+ }
+ pending_swap_throttle_map_.erase(child_route_id_pair);
+}
+
+void PrerenderTracker::AddPrerenderPendingSwap(
+ const ChildRouteIdPair& child_route_id_pair,
+ const GURL& url) {
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&AddPrerenderPendingSwapOnIOThreadTask,
+ child_route_id_pair, url));
+}
+
+void PrerenderTracker::RemovePrerenderPendingSwap(
+ const ChildRouteIdPair& child_route_id_pair,
+ bool swap_successful) {
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&RemovePrerenderPendingSwapOnIOThreadTask,
+ child_route_id_pair, swap_successful));
+}
+
+PrerenderTracker::PendingSwapThrottleData::PendingSwapThrottleData(
+ const GURL& swap_url)
+ : url(swap_url) {
+}
+
+PrerenderTracker::PendingSwapThrottleData::~PendingSwapThrottleData() {
+}
+
// static
PrerenderTracker* PrerenderTracker::GetDefault() {
return g_browser_process->prerender_tracker();
@@ -257,4 +337,19 @@ void PrerenderTracker::RemovePrerenderOnIOThreadTask(
GetDefault()->RemovePrerenderOnIOThread(child_route_id_pair, final_status);
}
+// static
+void PrerenderTracker::AddPrerenderPendingSwapOnIOThreadTask(
+ const ChildRouteIdPair& child_route_id_pair,
+ const GURL& url) {
+ GetDefault()->AddPrerenderPendingSwapOnIOThread(child_route_id_pair, url);
+}
+
+// static
+void PrerenderTracker::RemovePrerenderPendingSwapOnIOThreadTask(
+ const ChildRouteIdPair& child_route_id_pair,
+ bool swap_successful) {
+ GetDefault()->RemovePrerenderPendingSwapOnIOThread(child_route_id_pair,
+ swap_successful);
+}
+
} // namespace prerender