1 // Copyright (c) 2011 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.
5 #include "net/url_request/url_request_job_factory_impl.h"
7 #include "base/stl_util.h"
8 #include "net/base/load_flags.h"
9 #include "net/url_request/url_request_job_manager.h"
14 URLRequestJobFactoryImpl::URLRequestJobFactoryImpl() {}
16 URLRequestJobFactoryImpl::~URLRequestJobFactoryImpl() {
17 STLDeleteValues(&protocol_handler_map_
);
20 bool URLRequestJobFactoryImpl::SetProtocolHandler(
21 const std::string
& scheme
,
22 ProtocolHandler
* protocol_handler
) {
23 DCHECK(CalledOnValidThread());
25 if (!protocol_handler
) {
26 ProtocolHandlerMap::iterator it
= protocol_handler_map_
.find(scheme
);
27 if (it
== protocol_handler_map_
.end())
31 protocol_handler_map_
.erase(it
);
35 if (ContainsKey(protocol_handler_map_
, scheme
))
37 protocol_handler_map_
[scheme
] = protocol_handler
;
41 URLRequestJob
* URLRequestJobFactoryImpl::MaybeCreateJobWithProtocolHandler(
42 const std::string
& scheme
,
44 NetworkDelegate
* network_delegate
) const {
45 DCHECK(CalledOnValidThread());
46 ProtocolHandlerMap::const_iterator it
= protocol_handler_map_
.find(scheme
);
47 if (it
== protocol_handler_map_
.end())
49 return it
->second
->MaybeCreateJob(request
, network_delegate
);
52 bool URLRequestJobFactoryImpl::IsHandledProtocol(
53 const std::string
& scheme
) const {
54 DCHECK(CalledOnValidThread());
55 return ContainsKey(protocol_handler_map_
, scheme
) ||
56 URLRequestJobManager::GetInstance()->SupportsScheme(scheme
);
59 bool URLRequestJobFactoryImpl::IsHandledURL(const GURL
& url
) const {
60 if (!url
.is_valid()) {
61 // We handle error cases.
64 return IsHandledProtocol(url
.scheme());
67 bool URLRequestJobFactoryImpl::IsSafeRedirectTarget(
68 const GURL
& location
) const {
69 DCHECK(CalledOnValidThread());
70 if (!location
.is_valid()) {
71 // Error cases are safely handled.
74 ProtocolHandlerMap::const_iterator it
= protocol_handler_map_
.find(
76 if (it
== protocol_handler_map_
.end()) {
77 // Unhandled cases are safely handled.
80 return it
->second
->IsSafeRedirectTarget(location
);