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

Side by Side Diff: extensions/browser/extension_throttle_entry.cc

Issue 2315613002: Extracted NetLog class's inner enum types into their own enum classes and (Closed)
Patch Set: Ran "git cl format" on code. Much formatting ensued. Created 4 years, 3 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 "extensions/browser/extension_throttle_entry.h" 5 #include "extensions/browser/extension_throttle_entry.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/rand_util.h" 11 #include "base/rand_util.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "extensions/browser/extension_throttle_manager.h" 14 #include "extensions/browser/extension_throttle_manager.h"
15 #include "net/base/load_flags.h" 15 #include "net/base/load_flags.h"
16 #include "net/log/net_log.h" 16 #include "net/log/net_log.h"
17 #include "net/log/net_log_event_type.h"
18 #include "net/log/net_log_source_type.h"
17 #include "net/url_request/url_request.h" 19 #include "net/url_request/url_request.h"
18 #include "net/url_request/url_request_context.h" 20 #include "net/url_request/url_request_context.h"
19 21
20 namespace extensions { 22 namespace extensions {
21 23
22 const int ExtensionThrottleEntry::kDefaultSlidingWindowPeriodMs = 2000; 24 const int ExtensionThrottleEntry::kDefaultSlidingWindowPeriodMs = 2000;
23 const int ExtensionThrottleEntry::kDefaultMaxSendThreshold = 20; 25 const int ExtensionThrottleEntry::kDefaultMaxSendThreshold = 20;
24 26
25 // This set of back-off parameters will (at maximum values, i.e. without 27 // This set of back-off parameters will (at maximum values, i.e. without
26 // the reduction caused by jitter) add 0-41% (distributed uniformly 28 // the reduction caused by jitter) add 0-41% (distributed uniformly
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 bool ignore_user_gesture_load_flag_for_tests) 73 bool ignore_user_gesture_load_flag_for_tests)
72 : sliding_window_period_( 74 : sliding_window_period_(
73 base::TimeDelta::FromMilliseconds(kDefaultSlidingWindowPeriodMs)), 75 base::TimeDelta::FromMilliseconds(kDefaultSlidingWindowPeriodMs)),
74 max_send_threshold_(kDefaultMaxSendThreshold), 76 max_send_threshold_(kDefaultMaxSendThreshold),
75 is_backoff_disabled_(false), 77 is_backoff_disabled_(false),
76 backoff_entry_(&backoff_policy_), 78 backoff_entry_(&backoff_policy_),
77 manager_(manager), 79 manager_(manager),
78 url_id_(url_id), 80 url_id_(url_id),
79 net_log_(net::BoundNetLog::Make( 81 net_log_(net::BoundNetLog::Make(
80 manager->net_log(), 82 manager->net_log(),
81 net::NetLog::SOURCE_EXPONENTIAL_BACKOFF_THROTTLING)), 83 net::NetLogSourceType::EXPONENTIAL_BACKOFF_THROTTLING)),
82 ignore_user_gesture_load_flag_for_tests_( 84 ignore_user_gesture_load_flag_for_tests_(
83 ignore_user_gesture_load_flag_for_tests) { 85 ignore_user_gesture_load_flag_for_tests) {
84 DCHECK(manager_); 86 DCHECK(manager_);
85 Initialize(); 87 Initialize();
86 } 88 }
87 89
88 ExtensionThrottleEntry::ExtensionThrottleEntry( 90 ExtensionThrottleEntry::ExtensionThrottleEntry(
89 ExtensionThrottleManager* manager, 91 ExtensionThrottleManager* manager,
90 const std::string& url_id, 92 const std::string& url_id,
91 const net::BackoffEntry::Policy* backoff_policy, 93 const net::BackoffEntry::Policy* backoff_policy,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 void ExtensionThrottleEntry::DetachManager() { 146 void ExtensionThrottleEntry::DetachManager() {
145 manager_ = NULL; 147 manager_ = NULL;
146 } 148 }
147 149
148 bool ExtensionThrottleEntry::ShouldRejectRequest( 150 bool ExtensionThrottleEntry::ShouldRejectRequest(
149 const net::URLRequest& request) const { 151 const net::URLRequest& request) const {
150 bool reject_request = false; 152 bool reject_request = false;
151 if (!is_backoff_disabled_ && (ignore_user_gesture_load_flag_for_tests_ || 153 if (!is_backoff_disabled_ && (ignore_user_gesture_load_flag_for_tests_ ||
152 !ExplicitUserRequest(request.load_flags())) && 154 !ExplicitUserRequest(request.load_flags())) &&
153 GetBackoffEntry()->ShouldRejectRequest()) { 155 GetBackoffEntry()->ShouldRejectRequest()) {
154 net_log_.AddEvent(net::NetLog::TYPE_THROTTLING_REJECTED_REQUEST, 156 net_log_.AddEvent(net::NetLogEventType::THROTTLING_REJECTED_REQUEST,
155 base::Bind(&NetLogRejectedRequestCallback, &url_id_, 157 base::Bind(&NetLogRejectedRequestCallback, &url_id_,
156 GetBackoffEntry()->failure_count(), 158 GetBackoffEntry()->failure_count(),
157 GetBackoffEntry()->GetTimeUntilRelease())); 159 GetBackoffEntry()->GetTimeUntilRelease()));
158 reject_request = true; 160 reject_request = true;
159 } 161 }
160 return reject_request; 162 return reject_request;
161 } 163 }
162 164
163 int64_t ExtensionThrottleEntry::ReserveSendingTimeForNextRequest( 165 int64_t ExtensionThrottleEntry::ReserveSendingTimeForNextRequest(
164 const base::TimeTicks& earliest_time) { 166 const base::TimeTicks& earliest_time) {
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 net::BackoffEntry* ExtensionThrottleEntry::GetBackoffEntry() { 280 net::BackoffEntry* ExtensionThrottleEntry::GetBackoffEntry() {
279 return &backoff_entry_; 281 return &backoff_entry_;
280 } 282 }
281 283
282 // static 284 // static
283 bool ExtensionThrottleEntry::ExplicitUserRequest(const int load_flags) { 285 bool ExtensionThrottleEntry::ExplicitUserRequest(const int load_flags) {
284 return (load_flags & net::LOAD_MAYBE_USER_GESTURE) != 0; 286 return (load_flags & net::LOAD_MAYBE_USER_GESTURE) != 0;
285 } 287 }
286 288
287 } // namespace extensions 289 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/api/web_request/web_request_api_helpers.cc ('k') | extensions/browser/extension_throttle_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698