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_tracker.h" | 5 #include "chrome/browser/prerender/prerender_tracker.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/prerender/prerender_manager.h" | 10 #include "chrome/browser/prerender/prerender_manager.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 ChildRouteIdPair child_route_id_pair(child_id, route_id); | 65 ChildRouteIdPair child_route_id_pair(child_id, route_id); |
66 | 66 |
67 DCHECK_LT(prerender_contents->final_status(), FINAL_STATUS_MAX); | 67 DCHECK_LT(prerender_contents->final_status(), FINAL_STATUS_MAX); |
68 BrowserThread::PostTask( | 68 BrowserThread::PostTask( |
69 BrowserThread::IO, FROM_HERE, | 69 BrowserThread::IO, FROM_HERE, |
70 base::Bind(&PrerenderTracker::RemovePrerenderOnIOThread, | 70 base::Bind(&PrerenderTracker::RemovePrerenderOnIOThread, |
71 base::Unretained(this), child_route_id_pair, | 71 base::Unretained(this), child_route_id_pair, |
72 prerender_contents->final_status())); | 72 prerender_contents->final_status())); |
73 } | 73 } |
74 | 74 |
75 bool PrerenderTracker::IsPrerenderingOnIOThread(int child_id, | |
76 int route_id) const { | |
77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
78 | |
79 ChildRouteIdPair child_route_id_pair(child_id, route_id); | |
80 return resource_throttle_io_thread_map_.count(child_route_id_pair) > 0; | |
81 } | |
82 | |
83 bool PrerenderTracker::IsPendingSwapRequestOnIOThread( | 75 bool PrerenderTracker::IsPendingSwapRequestOnIOThread( |
84 int render_process_id, int render_frame_id, const GURL& url) const { | 76 int render_process_id, int render_frame_id, const GURL& url) const { |
85 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
86 | 78 |
87 ChildRouteIdPair render_frame_route_id_pair( | 79 ChildRouteIdPair render_frame_route_id_pair( |
88 render_process_id, render_frame_id); | 80 render_process_id, render_frame_id); |
89 PendingSwapThrottleMap::const_iterator it = | 81 PendingSwapThrottleMap::const_iterator it = |
90 pending_swap_throttle_map_.find(render_frame_route_id_pair); | 82 pending_swap_throttle_map_.find(render_frame_route_id_pair); |
91 return (it != pending_swap_throttle_map_.end() && it->second.url == url); | 83 return (it != pending_swap_throttle_map_.end() && it->second.url == url); |
92 } | 84 } |
(...skipping 22 matching lines...) Expand all Loading... | |
115 render_process_id, render_frame_id); | 107 render_process_id, render_frame_id); |
116 PendingSwapThrottleMap::iterator it = | 108 PendingSwapThrottleMap::iterator it = |
117 pending_swap_throttle_map_.find(render_frame_route_id_pair); | 109 pending_swap_throttle_map_.find(render_frame_route_id_pair); |
118 DCHECK(it != pending_swap_throttle_map_.end()); | 110 DCHECK(it != pending_swap_throttle_map_.end()); |
119 if (it == pending_swap_throttle_map_.end()) | 111 if (it == pending_swap_throttle_map_.end()) |
120 return; | 112 return; |
121 CHECK(!it->second.throttle); | 113 CHECK(!it->second.throttle); |
122 it->second.throttle = throttle; | 114 it->second.throttle = throttle; |
123 } | 115 } |
124 | 116 |
125 void PrerenderTracker::AddPrerenderOnIOThread( | 117 void PrerenderTracker::AddPrerenderOnIOThread( |
tburkard
2014/01/17 11:26:11
Assuming you want to convert resource_throttle_io_
| |
126 const ChildRouteIdPair& child_route_id_pair) { | 118 const ChildRouteIdPair& child_route_id_pair) { |
127 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 119 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
128 DCHECK(!IsPrerenderingOnIOThread(child_route_id_pair.first, | |
129 child_route_id_pair.second)); | |
130 | 120 |
131 resource_throttle_io_thread_map_.insert( | 121 std::pair<ResourceThrottleMap::iterator, bool> insert_result = |
132 std::make_pair(child_route_id_pair, ResourceThrottleList())); | 122 resource_throttle_io_thread_map_.insert( |
123 std::make_pair(child_route_id_pair, ResourceThrottleList())); | |
124 DCHECK(insert_result.second); | |
133 } | 125 } |
134 | 126 |
135 void PrerenderTracker::RemovePrerenderOnIOThread( | 127 void PrerenderTracker::RemovePrerenderOnIOThread( |
136 const ChildRouteIdPair& child_route_id_pair, | 128 const ChildRouteIdPair& child_route_id_pair, |
137 FinalStatus final_status) { | 129 FinalStatus final_status) { |
138 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 130 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
139 DCHECK(IsPrerenderingOnIOThread(child_route_id_pair.first, | |
140 child_route_id_pair.second)); | |
141 | 131 |
142 // Cancel or resume all throttled resources. | 132 // Cancel or resume all throttled resources. |
143 ResourceThrottleMap::iterator resource_throttle_map_it = | 133 ResourceThrottleMap::iterator resource_throttle_map_it = |
144 resource_throttle_io_thread_map_.find(child_route_id_pair); | 134 resource_throttle_io_thread_map_.find(child_route_id_pair); |
145 DCHECK(resource_throttle_map_it != resource_throttle_io_thread_map_.end()); | 135 DCHECK(resource_throttle_map_it != resource_throttle_io_thread_map_.end()); |
146 ResourceThrottleList& throttles = resource_throttle_map_it->second; | 136 ResourceThrottleList& throttles = resource_throttle_map_it->second; |
147 for (size_t i = 0; i < throttles.size(); i++) { | 137 for (size_t i = 0; i < throttles.size(); i++) { |
148 if (throttles[i]) { | 138 if (throttles[i]) { |
149 if (final_status == FINAL_STATUS_USED) { | 139 if (final_status == FINAL_STATUS_USED) { |
150 throttles[i]->Resume(); | 140 throttles[i]->Resume(); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
209 | 199 |
210 PrerenderTracker::PendingSwapThrottleData::~PendingSwapThrottleData() { | 200 PrerenderTracker::PendingSwapThrottleData::~PendingSwapThrottleData() { |
211 } | 201 } |
212 | 202 |
213 // static | 203 // static |
214 PrerenderTracker* PrerenderTracker::GetDefault() { | 204 PrerenderTracker* PrerenderTracker::GetDefault() { |
215 return g_browser_process->prerender_tracker(); | 205 return g_browser_process->prerender_tracker(); |
216 } | 206 } |
217 | 207 |
218 } // namespace prerender | 208 } // namespace prerender |
OLD | NEW |