[go: nahoru, domu]

blob: f6bd70ec23b7a83095ad4cd442209f54f5290188 [file] [log] [blame]
mmenke@chromium.org3b90aab2014-05-30 17:56:151// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef NET_URL_REQUEST_URL_REQUEST_INTERCEPTING_JOB_FACTORY_H_
6#define NET_URL_REQUEST_URL_REQUEST_INTERCEPTING_JOB_FACTORY_H_
7
danakj8522a25b2016-04-16 00:17:368#include <memory>
mmenke@chromium.org3b90aab2014-05-30 17:56:159#include <string>
10
mmenke@chromium.org3b90aab2014-05-30 17:56:1511#include "base/compiler_specific.h"
Avi Drissman13fc8932015-12-20 04:40:4612#include "base/macros.h"
mmenke@chromium.org3b90aab2014-05-30 17:56:1513#include "net/base/net_export.h"
14#include "net/url_request/url_request_job_factory.h"
15
16class GURL;
17
18namespace net {
19
20class URLRequest;
21class URLRequestJob;
22class URLRequestInterceptor;
23
24// This class acts as a wrapper for URLRequestJobFactory. The
25// URLRequestInteceptor is given the option of creating a URLRequestJob for each
26// URLRequest. If the interceptor does not create a job, the URLRequest is
27// forwarded to the wrapped URLRequestJobFactory instead.
28//
29// This class is only intended for use in intercepting requests before they
30// are passed on to their default ProtocolHandler. Each supported scheme should
31// have its own ProtocolHandler.
32class NET_EXPORT URLRequestInterceptingJobFactory
33 : public URLRequestJobFactory {
34 public:
pauljensenfd031f12016-11-21 13:52:5735 // Takes ownership of |job_factory| and |interceptor|.
mmenke@chromium.org3b90aab2014-05-30 17:56:1536 URLRequestInterceptingJobFactory(
danakj8522a25b2016-04-16 00:17:3637 std::unique_ptr<URLRequestJobFactory> job_factory,
38 std::unique_ptr<URLRequestInterceptor> interceptor);
pauljensenfd031f12016-11-21 13:52:5739 // Does not take ownership of |job_factory| and |interceptor|. Necessary if
40 // ownership is held elsewhere.
41 URLRequestInterceptingJobFactory(URLRequestJobFactory* job_factory,
42 URLRequestInterceptor* interceptor);
dchengb03027d2014-10-21 12:00:2043 ~URLRequestInterceptingJobFactory() override;
mmenke@chromium.org3b90aab2014-05-30 17:56:1544
45 // URLRequestJobFactory implementation
dchengb03027d2014-10-21 12:00:2046 URLRequestJob* MaybeCreateJobWithProtocolHandler(
mmenke@chromium.org3b90aab2014-05-30 17:56:1547 const std::string& scheme,
48 URLRequest* request,
mostynbba063d6032014-10-09 11:01:1349 NetworkDelegate* network_delegate) const override;
bengr1bf8e942014-11-07 01:36:5050
51 URLRequestJob* MaybeInterceptRedirect(
52 URLRequest* request,
53 NetworkDelegate* network_delegate,
54 const GURL& location) const override;
55
56 URLRequestJob* MaybeInterceptResponse(
57 URLRequest* request,
58 NetworkDelegate* network_delegate) const override;
59
dchengb03027d2014-10-21 12:00:2060 bool IsHandledProtocol(const std::string& scheme) const override;
61 bool IsHandledURL(const GURL& url) const override;
62 bool IsSafeRedirectTarget(const GURL& location) const override;
mmenke@chromium.org3b90aab2014-05-30 17:56:1563
64 private:
pauljensenfd031f12016-11-21 13:52:5765 // |owning_| indicates if this object owns |job_factory_| and |interceptor_|.
66 bool owning_;
67 URLRequestJobFactory* job_factory_;
68 URLRequestInterceptor* interceptor_;
mmenke@chromium.org3b90aab2014-05-30 17:56:1569
70 DISALLOW_COPY_AND_ASSIGN(URLRequestInterceptingJobFactory);
71};
72
73} // namespace net
74
75#endif // NET_URL_REQUEST_URL_REQUEST_INTERCEPTING_JOB_FACTORY_H_