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"
15 using content::ResourceType
;
19 PrerenderPendingSwapThrottle::PrerenderPendingSwapThrottle(
20 net::URLRequest
* request
,
21 PrerenderTracker
* tracker
)
27 void PrerenderPendingSwapThrottle::WillStartRequest(bool* defer
) {
29 const content::ResourceRequestInfo
* info
=
30 content::ResourceRequestInfo::ForRequest(request_
);
32 // We only care about main frame loads.
33 if (info
->GetResourceType() != content::RESOURCE_TYPE_MAIN_FRAME
)
36 int render_process_id
= info
->GetChildID();
37 int render_frame_id
= info
->GetRenderFrameID();
39 // Check if this request is for a URL we intend to swap in.
40 if (!tracker_
->IsPendingSwapRequestOnIOThread(
41 render_process_id
, render_frame_id
, request_
->url())) {
47 tracker_
->AddPendingSwapThrottleOnIOThread(
48 render_process_id
, render_frame_id
, request_
->url(), this->AsWeakPtr());
51 const char* PrerenderPendingSwapThrottle::GetNameForLogging() const {
52 return "PrerenderPendingSwapThrottle";
55 void PrerenderPendingSwapThrottle::Resume() {
59 controller()->Resume();
62 void PrerenderPendingSwapThrottle::Cancel() {
66 controller()->Cancel();
69 } // namespace prerender