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

Side by Side Diff: net/url_request/url_request_throttler_entry.cc

Issue 10532121: NetLogEventParameter to Callback refactoring 6. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Update includes Created 8 years, 6 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 | Annotate | Revision Log
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 "net/url_request/url_request_throttler_entry.h" 5 #include "net/url_request/url_request_throttler_entry.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/metrics/field_trial.h" 10 #include "base/metrics/field_trial.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 const int URLRequestThrottlerEntry::kDefaultInitialDelayMs = 700; 44 const int URLRequestThrottlerEntry::kDefaultInitialDelayMs = 700;
45 const double URLRequestThrottlerEntry::kDefaultMultiplyFactor = 1.4; 45 const double URLRequestThrottlerEntry::kDefaultMultiplyFactor = 1.4;
46 const double URLRequestThrottlerEntry::kDefaultJitterFactor = 0.4; 46 const double URLRequestThrottlerEntry::kDefaultJitterFactor = 0.4;
47 const int URLRequestThrottlerEntry::kDefaultMaximumBackoffMs = 15 * 60 * 1000; 47 const int URLRequestThrottlerEntry::kDefaultMaximumBackoffMs = 15 * 60 * 1000;
48 const int URLRequestThrottlerEntry::kDefaultEntryLifetimeMs = 2 * 60 * 1000; 48 const int URLRequestThrottlerEntry::kDefaultEntryLifetimeMs = 2 * 60 * 1000;
49 const char URLRequestThrottlerEntry::kExponentialThrottlingHeader[] = 49 const char URLRequestThrottlerEntry::kExponentialThrottlingHeader[] =
50 "X-Chrome-Exponential-Throttling"; 50 "X-Chrome-Exponential-Throttling";
51 const char URLRequestThrottlerEntry::kExponentialThrottlingDisableValue[] = 51 const char URLRequestThrottlerEntry::kExponentialThrottlingDisableValue[] =
52 "disable"; 52 "disable";
53 53
54 // NetLog parameters when a request is rejected by throttling. 54 // Returns NetLog parameters when a request is rejected by throttling.
55 class RejectedRequestParameters : public NetLog::EventParameters { 55 Value* NetLogRejectedRequestCallback(const std::string* url_id,
56 public: 56 int num_failures,
57 RejectedRequestParameters(const std::string& url_id, 57 int release_after_ms,
58 int num_failures, 58 NetLog::LogLevel /* log_level */) {
59 int release_after_ms) 59 DictionaryValue* dict = new DictionaryValue();
60 : url_id_(url_id), 60 dict->SetString("url", *url_id);
61 num_failures_(num_failures), 61 dict->SetInteger("num_failures", num_failures);
62 release_after_ms_(release_after_ms) { 62 dict->SetInteger("release_after_ms", release_after_ms);
63 } 63 return dict;
64 64 }
65 virtual Value* ToValue() const {
66 DictionaryValue* dict = new DictionaryValue();
67 dict->SetString("url", url_id_);
68 dict->SetInteger("num_failures", num_failures_);
69 dict->SetInteger("release_after_ms", release_after_ms_);
70 return dict;
71 }
72
73 protected:
74 virtual ~RejectedRequestParameters() {}
75
76 private:
77 std::string url_id_;
78 int num_failures_;
79 int release_after_ms_;
80 };
81 65
82 URLRequestThrottlerEntry::URLRequestThrottlerEntry( 66 URLRequestThrottlerEntry::URLRequestThrottlerEntry(
83 URLRequestThrottlerManager* manager, 67 URLRequestThrottlerManager* manager,
84 const std::string& url_id) 68 const std::string& url_id)
85 : sliding_window_period_( 69 : sliding_window_period_(
86 base::TimeDelta::FromMilliseconds(kDefaultSlidingWindowPeriodMs)), 70 base::TimeDelta::FromMilliseconds(kDefaultSlidingWindowPeriodMs)),
87 max_send_threshold_(kDefaultMaxSendThreshold), 71 max_send_threshold_(kDefaultMaxSendThreshold),
88 is_backoff_disabled_(false), 72 is_backoff_disabled_(false),
89 backoff_entry_(&backoff_policy_), 73 backoff_entry_(&backoff_policy_),
90 manager_(manager), 74 manager_(manager),
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 if (!is_backoff_disabled_ && !ExplicitUserRequest(request.load_flags()) && 155 if (!is_backoff_disabled_ && !ExplicitUserRequest(request.load_flags()) &&
172 (!request.context() || !request.context()->network_delegate() || 156 (!request.context() || !request.context()->network_delegate() ||
173 request.context()->network_delegate()->CanThrottleRequest(request)) && 157 request.context()->network_delegate()->CanThrottleRequest(request)) &&
174 GetBackoffEntry()->ShouldRejectRequest()) { 158 GetBackoffEntry()->ShouldRejectRequest()) {
175 int num_failures = GetBackoffEntry()->failure_count(); 159 int num_failures = GetBackoffEntry()->failure_count();
176 int release_after_ms = 160 int release_after_ms =
177 GetBackoffEntry()->GetTimeUntilRelease().InMilliseconds(); 161 GetBackoffEntry()->GetTimeUntilRelease().InMilliseconds();
178 162
179 net_log_.AddEvent( 163 net_log_.AddEvent(
180 NetLog::TYPE_THROTTLING_REJECTED_REQUEST, 164 NetLog::TYPE_THROTTLING_REJECTED_REQUEST,
181 make_scoped_refptr( 165 base::Bind(&NetLogRejectedRequestCallback,
182 new RejectedRequestParameters(url_id_, 166 &url_id_, num_failures, release_after_ms));
183 num_failures,
184 release_after_ms)));
185 167
186 reject_request = true; 168 reject_request = true;
187 } 169 }
188 170
189 int reject_count = reject_request ? 1 : 0; 171 int reject_count = reject_request ? 1 : 0;
190 UMA_HISTOGRAM_ENUMERATION( 172 UMA_HISTOGRAM_ENUMERATION(
191 "Throttling.RequestThrottled", reject_count, 2); 173 "Throttling.RequestThrottled", reject_count, 2);
192 174
193 return reject_request; 175 return reject_request;
194 } 176 }
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 BackoffEntry* URLRequestThrottlerEntry::GetBackoffEntry() { 312 BackoffEntry* URLRequestThrottlerEntry::GetBackoffEntry() {
331 return &backoff_entry_; 313 return &backoff_entry_;
332 } 314 }
333 315
334 // static 316 // static
335 bool URLRequestThrottlerEntry::ExplicitUserRequest(const int load_flags) { 317 bool URLRequestThrottlerEntry::ExplicitUserRequest(const int load_flags) {
336 return (load_flags & LOAD_MAYBE_USER_GESTURE) != 0; 318 return (load_flags & LOAD_MAYBE_USER_GESTURE) != 0;
337 } 319 }
338 320
339 } // namespace net 321 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698