1cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
2cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// found in the LICENSE file.
4cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
5cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "net/url_request/url_request_intercepting_job_factory.h"
6cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
7cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "base/logging.h"
8cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "net/url_request/url_request_interceptor.h"
9cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
10cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)namespace net {
11cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
12cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)URLRequestInterceptingJobFactory::URLRequestInterceptingJobFactory(
13cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    scoped_ptr<URLRequestJobFactory> job_factory,
14cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    scoped_ptr<URLRequestInterceptor> interceptor)
15cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    : job_factory_(job_factory.Pass()),
16cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      interceptor_(interceptor.Pass()) {
17cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)}
18cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
19cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)URLRequestInterceptingJobFactory::~URLRequestInterceptingJobFactory() {}
20cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
21cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)URLRequestJob* URLRequestInterceptingJobFactory::
22cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)MaybeCreateJobWithProtocolHandler(
23cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    const std::string& scheme,
24cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    URLRequest* request,
25cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    NetworkDelegate* network_delegate) const {
26cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  DCHECK(CalledOnValidThread());
27cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  URLRequestJob* job = interceptor_->MaybeInterceptRequest(request,
28cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)                                                           network_delegate);
29cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  if (job)
30cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    return job;
31cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  return job_factory_->MaybeCreateJobWithProtocolHandler(
32cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      scheme, request, network_delegate);
33cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)}
34cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
35cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)bool URLRequestInterceptingJobFactory::IsHandledProtocol(
36cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    const std::string& scheme) const {
37cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  return job_factory_->IsHandledProtocol(scheme);
38cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)}
39cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
40cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)bool URLRequestInterceptingJobFactory::IsHandledURL(const GURL& url) const {
41cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  return job_factory_->IsHandledURL(url);
42cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)}
43cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
44cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)bool URLRequestInterceptingJobFactory::IsSafeRedirectTarget(
45cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    const GURL& location) const {
46cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  return job_factory_->IsSafeRedirectTarget(location);
47cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)}
48cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
49cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)}  // namespace net
50