Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: content/browser/loader/throttling_resource_handler.cc

Issue 1569673002: [NOT FOR LANDING] Detailed loading traces Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "content/browser/loader/throttling_resource_handler.h" 5 #include "content/browser/loader/throttling_resource_handler.h"
6 6
7 #include <utility> 7 #include <utility>
8 #include "base/trace_event/trace_event.h"
8 9
9 #include "content/browser/loader/resource_request_info_impl.h" 10 #include "content/browser/loader/resource_request_info_impl.h"
10 #include "content/public/browser/resource_throttle.h" 11 #include "content/public/browser/resource_throttle.h"
11 #include "content/public/common/resource_response.h" 12 #include "content/public/common/resource_response.h"
12 #include "net/url_request/url_request.h" 13 #include "net/url_request/url_request.h"
13 14
14 namespace content { 15 namespace content {
15 16
16 ThrottlingResourceHandler::ThrottlingResourceHandler( 17 ThrottlingResourceHandler::ThrottlingResourceHandler(
17 scoped_ptr<ResourceHandler> next_handler, 18 scoped_ptr<ResourceHandler> next_handler,
18 net::URLRequest* request, 19 net::URLRequest* request,
19 ScopedVector<ResourceThrottle> throttles) 20 ScopedVector<ResourceThrottle> throttles)
20 : LayeredResourceHandler(request, std::move(next_handler)), 21 : LayeredResourceHandler(request, std::move(next_handler)),
21 deferred_stage_(DEFERRED_NONE), 22 deferred_stage_(DEFERRED_NONE),
22 throttles_(std::move(throttles)), 23 throttles_(std::move(throttles)),
23 next_index_(0), 24 next_index_(0),
24 cancelled_by_resource_throttle_(false) { 25 cancelled_by_resource_throttle_(false) {
25 for (size_t i = 0; i < throttles_.size(); ++i) { 26 for (size_t i = 0; i < throttles_.size(); ++i) {
26 throttles_[i]->set_controller(this); 27 throttles_[i]->set_controller(this);
27 // Throttles must have a name, as otherwise, bugs where a throttle fails 28 // Throttles must have a name, as otherwise, bugs where a throttle fails
28 // to resume a request can be very difficult to debug. 29 // to resume a request can be very difficult to debug.
29 DCHECK(throttles_[i]->GetNameForLogging()); 30 DCHECK(throttles_[i]->GetNameForLogging());
30 } 31 }
31 } 32 }
32 33
33 ThrottlingResourceHandler::~ThrottlingResourceHandler() { 34 ThrottlingResourceHandler::~ThrottlingResourceHandler() {
35 TRACE_EVENT0("toplevel",
36 "ThrottlingResourceHandler::~ThrottlingResourceHandler");
34 } 37 }
35 38
36 bool ThrottlingResourceHandler::OnRequestRedirected( 39 bool ThrottlingResourceHandler::OnRequestRedirected(
37 const net::RedirectInfo& redirect_info, 40 const net::RedirectInfo& redirect_info,
38 ResourceResponse* response, 41 ResourceResponse* response,
39 bool* defer) { 42 bool* defer) {
40 DCHECK(!cancelled_by_resource_throttle_); 43 DCHECK(!cancelled_by_resource_throttle_);
41 44
42 *defer = false; 45 *defer = false;
43 while (next_index_ < throttles_.size()) { 46 while (next_index_ < throttles_.size()) {
(...skipping 10 matching lines...) Expand all
54 return true; // Do not cancel. 57 return true; // Do not cancel.
55 } 58 }
56 } 59 }
57 60
58 next_index_ = 0; // Reset for next time. 61 next_index_ = 0; // Reset for next time.
59 62
60 return next_handler_->OnRequestRedirected(redirect_info, response, defer); 63 return next_handler_->OnRequestRedirected(redirect_info, response, defer);
61 } 64 }
62 65
63 bool ThrottlingResourceHandler::OnWillStart(const GURL& url, bool* defer) { 66 bool ThrottlingResourceHandler::OnWillStart(const GURL& url, bool* defer) {
67 TRACE_EVENT0("toplevel", "ThrottlingResourceHandler::OnWillStart");
64 DCHECK(!cancelled_by_resource_throttle_); 68 DCHECK(!cancelled_by_resource_throttle_);
65 69
66 *defer = false; 70 *defer = false;
67 while (next_index_ < throttles_.size()) { 71 while (next_index_ < throttles_.size()) {
68 int index = next_index_; 72 int index = next_index_;
69 throttles_[index]->WillStartRequest(defer); 73 {
74 TRACE_EVENT0("toplevel", "Throttle::OnWillStartRequest");
75 throttles_[index]->WillStartRequest(defer);
76 }
70 next_index_++; 77 next_index_++;
71 if (cancelled_by_resource_throttle_) 78 if (cancelled_by_resource_throttle_)
72 return false; 79 return false;
73 if (*defer) { 80 if (*defer) {
74 OnRequestDefered(index); 81 {
82 TRACE_EVENT0("toplevel", "ThrottlingResourceHandler::OnRequestDefered");
83 OnRequestDefered(index);
84 }
75 deferred_stage_ = DEFERRED_START; 85 deferred_stage_ = DEFERRED_START;
76 deferred_url_ = url; 86 deferred_url_ = url;
77 return true; // Do not cancel. 87 return true; // Do not cancel.
78 } 88 }
79 } 89 }
80 90
81 next_index_ = 0; // Reset for next time. 91 next_index_ = 0; // Reset for next time.
82 92
83 return next_handler_->OnWillStart(url, defer); 93 return next_handler_->OnWillStart(url, defer);
84 } 94 }
(...skipping 17 matching lines...) Expand all
102 } 112 }
103 } 113 }
104 114
105 next_index_ = 0; // Reset for next time. 115 next_index_ = 0; // Reset for next time.
106 116
107 return next_handler_->OnBeforeNetworkStart(url, defer); 117 return next_handler_->OnBeforeNetworkStart(url, defer);
108 } 118 }
109 119
110 bool ThrottlingResourceHandler::OnResponseStarted(ResourceResponse* response, 120 bool ThrottlingResourceHandler::OnResponseStarted(ResourceResponse* response,
111 bool* defer) { 121 bool* defer) {
122 TRACE_EVENT0("toplevel", "ThrottlingResourceHandler::OnResponseStarted");
123
112 DCHECK(!cancelled_by_resource_throttle_); 124 DCHECK(!cancelled_by_resource_throttle_);
113 125
114 while (next_index_ < throttles_.size()) { 126 while (next_index_ < throttles_.size()) {
115 int index = next_index_; 127 int index = next_index_;
116 throttles_[index]->WillProcessResponse(defer); 128 throttles_[index]->WillProcessResponse(defer);
117 next_index_++; 129 next_index_++;
118 if (cancelled_by_resource_throttle_) 130 if (cancelled_by_resource_throttle_)
119 return false; 131 return false;
120 if (*defer) { 132 if (*defer) {
121 OnRequestDefered(index); 133 OnRequestDefered(index);
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 } else if (!defer) { 239 } else if (!defer) {
228 controller()->Resume(); 240 controller()->Resume();
229 } 241 }
230 } 242 }
231 243
232 void ThrottlingResourceHandler::OnRequestDefered(int throttle_index) { 244 void ThrottlingResourceHandler::OnRequestDefered(int throttle_index) {
233 request()->LogBlockedBy(throttles_[throttle_index]->GetNameForLogging()); 245 request()->LogBlockedBy(throttles_[throttle_index]->GetNameForLogging());
234 } 246 }
235 247
236 } // namespace content 248 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/sync_resource_handler.cc ('k') | content/public/browser/browser_message_filter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698