Adding instrumentation to locate the source of jankiness
[chromium-blink-merge.git] / chrome / browser / prerender / prerender_pending_swap_throttle.cc
blob5148ace853df1ed0d0776fffeb9884735e477e6f
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;
17 namespace prerender {
19 PrerenderPendingSwapThrottle::PrerenderPendingSwapThrottle(
20 net::URLRequest* request,
21 PrerenderTracker* tracker)
22 : request_(request),
23 tracker_(tracker),
24 throttled_(false) {
27 void PrerenderPendingSwapThrottle::WillStartRequest(bool* defer) {
28 DCHECK(!throttled_);
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)
34 return;
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())) {
42 return;
45 *defer = true;
46 throttled_ = true;
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() {
56 DCHECK(throttled_);
58 throttled_ = false;
59 controller()->Resume();
62 void PrerenderPendingSwapThrottle::Cancel() {
63 DCHECK(throttled_);
65 throttled_ = false;
66 controller()->Cancel();
69 } // namespace prerender