blob: 05d041014e3ae00aee4b1386986f515b16febddd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "extensions/browser/extension_request_limiting_throttle.h"
#include "base/logging.h"
#include "content/public/browser/resource_controller.h"
#include "extensions/browser/extension_throttle_entry.h"
#include "extensions/browser/extension_throttle_manager.h"
#include "net/base/net_errors.h"
#include "net/url_request/redirect_info.h"
#include "net/url_request/url_request.h"
namespace extensions {
ExtensionRequestLimitingThrottle::ExtensionRequestLimitingThrottle(
const net::URLRequest* request,
ExtensionThrottleManager* manager)
: request_(request), manager_(manager) {
DCHECK(manager_);
}
ExtensionRequestLimitingThrottle::~ExtensionRequestLimitingThrottle() {
}
void ExtensionRequestLimitingThrottle::WillStartRequest(bool* defer) {
throttling_entry_ = manager_->RegisterRequestUrl(request_->url());
if (throttling_entry_->ShouldRejectRequest(*request_))
controller()->CancelWithError(net::ERR_TEMPORARILY_THROTTLED);
}
void ExtensionRequestLimitingThrottle::WillRedirectRequest(
const net::RedirectInfo& redirect_info,
bool* defer) {
DCHECK_EQ(manager_->GetIdFromUrl(request_->url()),
throttling_entry_->GetURLIdForDebugging());
throttling_entry_->UpdateWithResponse(redirect_info.status_code);
throttling_entry_ = manager_->RegisterRequestUrl(redirect_info.new_url);
if (throttling_entry_->ShouldRejectRequest(*request_))
controller()->CancelWithError(net::ERR_TEMPORARILY_THROTTLED);
}
void ExtensionRequestLimitingThrottle::WillProcessResponse(bool* defer) {
DCHECK_EQ(manager_->GetIdFromUrl(request_->url()),
throttling_entry_->GetURLIdForDebugging());
if (!request_->was_cached())
throttling_entry_->UpdateWithResponse(request_->GetResponseCode());
}
const char* ExtensionRequestLimitingThrottle::GetNameForLogging() const {
return "ExtensionRequestLimitingThrottle";
}
} // namespace extensions
|