summaryrefslogtreecommitdiffstats
path: root/net/url_request/url_request_job_factory_impl.h
blob: aee736857407a099ec104768fef731fb4dee8417 (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
59
60
61
62
63
64
65
66
67
68
69
70
71
// 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.

#ifndef NET_URL_REQUEST_URL_REQUEST_JOB_FACTORY_IMPL_H_
#define NET_URL_REQUEST_URL_REQUEST_JOB_FACTORY_IMPL_H_

#include <map>
#include <string>

#include "base/compiler_specific.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.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 {
 public:
  URLRequestJobFactoryImpl();
  ~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,
                          scoped_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 IsHandledURL(const GURL& url) const override;
  bool IsSafeRedirectTarget(const GURL& location) const override;

 private:
  // For testing only.
  friend class URLRequestFilter;

  typedef std::map<std::string, scoped_ptr<ProtocolHandler>> ProtocolHandlerMap;

  // 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_;

  DISALLOW_COPY_AND_ASSIGN(URLRequestJobFactoryImpl);
};

}  // namespace net

#endif  // NET_URL_REQUEST_URL_REQUEST_JOB_FACTORY_IMPL_H_