1 // Copyright 2013 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_pending_swap_throttle.h"
7 #include "chrome/browser/prerender/prerender_final_status.h"
8 #include "chrome/browser/prerender/prerender_manager.h"
9 #include "chrome/browser/prerender/prerender_tracker.h"
10 #include "chrome/browser/prerender/prerender_util.h"
11 #include "content/public/browser/resource_controller.h"
12 #include "content/public/browser/resource_request_info.h"
13 #include "net/url_request/url_request.h"
17 PrerenderPendingSwapThrottle::PrerenderPendingSwapThrottle(
18 net::URLRequest
* request
,
19 PrerenderTracker
* tracker
)
25 void PrerenderPendingSwapThrottle::WillStartRequest(bool* defer
) {
27 const content::ResourceRequestInfo
* info
=
28 content::ResourceRequestInfo::ForRequest(request_
);
30 // We only care about main frame loads.
31 if (info
->GetResourceType() != ResourceType::MAIN_FRAME
)
34 int render_process_id
= info
->GetChildID();
35 int render_frame_id
= info
->GetRenderFrameID();
37 // Check if this request is for a URL we intend to swap in.
38 if (!tracker_
->IsPendingSwapRequestOnIOThread(
39 render_process_id
, render_frame_id
, request_
->url())) {
45 tracker_
->AddPendingSwapThrottleOnIOThread(
46 render_process_id
, render_frame_id
, request_
->url(), this->AsWeakPtr());
49 const char* PrerenderPendingSwapThrottle::GetNameForLogging() const {
50 return "PrerenderPendingSwapThrottle";
53 void PrerenderPendingSwapThrottle::Resume() {
57 controller()->Resume();
60 void PrerenderPendingSwapThrottle::Cancel() {
64 controller()->Cancel();
67 } // namespace prerender