blob: 3ff3c9219f72a38fd9de22bdc37c8a51449b4d74 [file] [log] [blame]
// Copyright (c) 2011 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 <map>
#include <memory>
#include <string>
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "net/base/net_export.h"
#include "net/url_request/url_request_job_factory.h"
namespace net {
class URLRequestInterceptor;
class NET_EXPORT URLRequestJobFactoryImpl : public URLRequestJobFactory {
~URLRequestJobFactoryImpl() override;
// Sets the ProtocolHandler for a scheme. Returns true on success, false on
// failure (a ProtocolHandler already exists for |scheme|).
bool SetProtocolHandler(const std::string& scheme,
std::unique_ptr<ProtocolHandler> protocol_handler);
// URLRequestJobFactory implementation
URLRequestJob* MaybeCreateJobWithProtocolHandler(
const std::string& scheme,
URLRequest* request,
NetworkDelegate* network_delegate) const override;
URLRequestJob* MaybeInterceptRedirect(
URLRequest* request,
NetworkDelegate* network_delegate,
const GURL& location) const override;
URLRequestJob* MaybeInterceptResponse(
URLRequest* request,
NetworkDelegate* network_delegate) const override;
bool IsHandledProtocol(const std::string& scheme) const override;
bool IsSafeRedirectTarget(const GURL& location) const override;
// For testing only.
friend class URLRequestFilter;
typedef std::map<std::string, std::unique_ptr<ProtocolHandler>>
// Sets a global URLRequestInterceptor for testing purposes. The interceptor
// is given the chance to intercept any request before the corresponding
// ProtocolHandler, but after any other URLRequestJobFactories layered on top
// of the URLRequestJobFactoryImpl.
// If an interceptor is set, the old interceptor must be cleared before
// setting a new one.
static void SetInterceptorForTesting(URLRequestInterceptor* interceptor);
ProtocolHandlerMap protocol_handler_map_;
} // namespace net