1 // Copyright 2014 The Chromium Authors 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 COMPONENTS_CRONET_ANDROID_TEST_URL_REQUEST_INTERCEPTING_JOB_FACTORY_H_ 6 #define COMPONENTS_CRONET_ANDROID_TEST_URL_REQUEST_INTERCEPTING_JOB_FACTORY_H_ 7 8 #include <memory> 9 10 #include "base/compiler_specific.h" 11 #include "base/memory/raw_ptr.h" 12 #include "net/url_request/url_request_job_factory.h" 13 14 class GURL; 15 16 namespace net { 17 class URLRequest; 18 class URLRequestJob; 19 class URLRequestInterceptor; 20 } // namespace net 21 22 namespace cronet { 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. 32 class URLRequestInterceptingJobFactory : public net::URLRequestJobFactory { 33 public: 34 // Does not take ownership of |job_factory| and |interceptor|. 35 URLRequestInterceptingJobFactory(net::URLRequestJobFactory* job_factory, 36 net::URLRequestInterceptor* interceptor); 37 38 URLRequestInterceptingJobFactory(const URLRequestInterceptingJobFactory&) = 39 delete; 40 URLRequestInterceptingJobFactory& operator=( 41 const URLRequestInterceptingJobFactory&) = delete; 42 43 ~URLRequestInterceptingJobFactory() override; 44 45 // URLRequestJobFactory implementation 46 std::unique_ptr<net::URLRequestJob> CreateJob( 47 net::URLRequest* request) const override; 48 bool IsSafeRedirectTarget(const GURL& location) const override; 49 50 private: 51 const raw_ptr<net::URLRequestJobFactory> job_factory_; 52 const raw_ptr<net::URLRequestInterceptor> interceptor_; 53 }; 54 55 } // namespace cronet 56 57 #endif // COMPONENTS_CRONET_ANDROID_TEST_URL_REQUEST_INTERCEPTING_JOB_FACTORY_H_ 58