Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / prerender / prerender_pending_swap_throttle.cc
bloba560bae1e98de54e58a9388dbc6132e5b7bd3e9e
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 namespace prerender {
17 PrerenderPendingSwapThrottle::PrerenderPendingSwapThrottle(
18 net::URLRequest* request,
19 PrerenderTracker* tracker)
20 : request_(request),
21 tracker_(tracker),
22 throttled_(false) {
25 void PrerenderPendingSwapThrottle::WillStartRequest(bool* defer) {
26 DCHECK(!throttled_);
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)
32 return;
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())) {
40 return;
43 *defer = true;
44 throttled_ = true;
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() {
54 DCHECK(throttled_);
56 throttled_ = false;
57 controller()->Resume();
60 void PrerenderPendingSwapThrottle::Cancel() {
61 DCHECK(throttled_);
63 throttled_ = false;
64 controller()->Cancel();
67 } // namespace prerender