blob: 240d95e1967b0a01d028d8c4be9e8a961bcde7be [file] [log] [blame]
// Copyright (c) 2012 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 <vector>
class GURL;
namespace net {
struct RedirectInfo;
namespace content {
class ResourceController;
// A ResourceThrottle gets notified at various points during the process of
// loading a resource. At each stage, it has the opportunity to defer the
// resource load. The ResourceController interface may be used to resume a
// deferred resource load, or it may be used to cancel a resource load at any
// time.
class ResourceThrottle {
virtual ~ResourceThrottle() {}
// Called before the resource request is started.
virtual void WillStartRequest(bool* defer) {}
// Called before the resource request uses the network for the first time.
virtual void WillStartUsingNetwork(bool* defer) {}
// Called when the request was redirected. |redirect_info| contains the
// redirect responses's HTTP status code and some information about the new
// request that will be sent if the redirect is followed, including the new
// URL and new method.
virtual void WillRedirectRequest(const net::RedirectInfo& redirect_info,
bool* defer) {}
// Called when the response headers and meta data are available.
virtual void WillProcessResponse(bool* defer) {}
// Returns the name of the throttle, as a UTF-8 C-string, for logging
// purposes. nullptr is not allowed. Caller does *not* take ownership of the
// returned string.
virtual const char* GetNameForLogging() const = 0;
void set_controller_for_testing(ResourceController* c) {
controller_ = c;
ResourceThrottle() : controller_(nullptr) {}
ResourceController* controller() { return controller_; }
friend class ThrottlingResourceHandler;
void set_controller(ResourceController* c) { controller_ = c; }
ResourceController* controller_;
} // namespace content