[Bluetooth] Clean up code to extract a UUID from SDP data.
[chromium-blink-merge.git] / net / url_request / url_request_job_factory_impl.cc
blobf456da2798f57e2e7580992161afa8cdfb736ca9
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"
10 #include "url/gurl.h"
12 namespace net {
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())
28 return false;
30 delete it->second;
31 protocol_handler_map_.erase(it);
32 return true;
35 if (ContainsKey(protocol_handler_map_, scheme))
36 return false;
37 protocol_handler_map_[scheme] = protocol_handler;
38 return true;
41 URLRequestJob* URLRequestJobFactoryImpl::MaybeCreateJobWithProtocolHandler(
42 const std::string& scheme,
43 URLRequest* request,
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())
48 return NULL;
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.
62 return true;
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.
72 return true;
74 ProtocolHandlerMap::const_iterator it = protocol_handler_map_.find(
75 location.scheme());
76 if (it == protocol_handler_map_.end()) {
77 // Unhandled cases are safely handled.
78 return true;
80 return it->second->IsSafeRedirectTarget(location);
83 } // namespace net