NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / prerender / prerender_tracker.cc
blobb44c8d3430df98f16efc0ebf8689e0b4801e2018
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
3 // found in the LICENSE file.
5 #include "chrome/browser/prerender/prerender_tracker.h"
7 #include "base/bind.h"
8 #include "base/logging.h"
9 #include "chrome/browser/prerender/prerender_pending_swap_throttle.h"
10 #include "content/public/browser/browser_thread.h"
12 using content::BrowserThread;
14 namespace prerender {
16 PrerenderTracker::PrerenderTracker() {
17 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
20 PrerenderTracker::~PrerenderTracker() {
23 bool PrerenderTracker::IsPendingSwapRequestOnIOThread(
24 int render_process_id, int render_frame_id, const GURL& url) const {
25 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
27 ChildRouteIdPair render_frame_route_id_pair(
28 render_process_id, render_frame_id);
29 PendingSwapThrottleMap::const_iterator it =
30 pending_swap_throttle_map_.find(render_frame_route_id_pair);
31 return (it != pending_swap_throttle_map_.end() && it->second.url == url);
34 void PrerenderTracker::AddPendingSwapThrottleOnIOThread(
35 int render_process_id,
36 int render_frame_id,
37 const GURL& url,
38 const base::WeakPtr<PrerenderPendingSwapThrottle>& throttle) {
39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
41 ChildRouteIdPair render_frame_route_id_pair(
42 render_process_id, render_frame_id);
43 PendingSwapThrottleMap::iterator it =
44 pending_swap_throttle_map_.find(render_frame_route_id_pair);
45 DCHECK(it != pending_swap_throttle_map_.end());
46 if (it == pending_swap_throttle_map_.end())
47 return;
48 CHECK(!it->second.throttle);
49 it->second.throttle = throttle;
52 void PrerenderTracker::AddPrerenderPendingSwapOnIOThread(
53 const ChildRouteIdPair& render_frame_route_id_pair,
54 const GURL& url) {
55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
56 std::pair<PendingSwapThrottleMap::iterator, bool> insert_result =
57 pending_swap_throttle_map_.insert(std::make_pair(
58 render_frame_route_id_pair, PendingSwapThrottleData(url)));
59 DCHECK(insert_result.second);
62 void PrerenderTracker::RemovePrerenderPendingSwapOnIOThread(
63 const ChildRouteIdPair& render_frame_route_id_pair,
64 bool swap_successful) {
65 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
66 PendingSwapThrottleMap::iterator it =
67 pending_swap_throttle_map_.find(render_frame_route_id_pair);
68 DCHECK(it != pending_swap_throttle_map_.end());
69 // Cancel or resume all throttled resources.
70 if (it->second.throttle) {
71 if (swap_successful)
72 it->second.throttle->Cancel();
73 else
74 it->second.throttle->Resume();
76 pending_swap_throttle_map_.erase(render_frame_route_id_pair);
79 void PrerenderTracker::AddPrerenderPendingSwap(
80 const ChildRouteIdPair& render_frame_route_id_pair,
81 const GURL& url) {
82 BrowserThread::PostTask(
83 BrowserThread::IO, FROM_HERE,
84 base::Bind(&PrerenderTracker::AddPrerenderPendingSwapOnIOThread,
85 base::Unretained(this), render_frame_route_id_pair, url));
88 void PrerenderTracker::RemovePrerenderPendingSwap(
89 const ChildRouteIdPair& render_frame_route_id_pair,
90 bool swap_successful) {
91 BrowserThread::PostTask(
92 BrowserThread::IO, FROM_HERE,
93 base::Bind(&PrerenderTracker::RemovePrerenderPendingSwapOnIOThread,
94 base::Unretained(this), render_frame_route_id_pair,
95 swap_successful));
98 PrerenderTracker::PendingSwapThrottleData::PendingSwapThrottleData(
99 const GURL& swap_url)
100 : url(swap_url) {
103 PrerenderTracker::PendingSwapThrottleData::~PendingSwapThrottleData() {
106 } // namespace prerender