Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(439)

Side by Side Diff: net/url_request/url_request_job_factory.cc

Issue 10836248: Turned job_factory into a pure virtual class (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Latest merge Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/url_request/url_request_job_factory.h" 5 #include "net/url_request/url_request_job_factory.h"
6 6
7 #include "base/stl_util.h"
8 #include "googleurl/src/gurl.h"
9 #include "net/base/load_flags.h"
10 #include "net/url_request/url_request_job_manager.h"
11
12 namespace net { 7 namespace net {
13 8
14 URLRequestJobFactory::ProtocolHandler::~ProtocolHandler() {} 9 URLRequestJobFactory::ProtocolHandler::~ProtocolHandler() {}
15 10
16 URLRequestJobFactory::Interceptor::~Interceptor() {} 11 URLRequestJobFactory::Interceptor::~Interceptor() {}
17 12
18 bool URLRequestJobFactory::Interceptor::WillHandleProtocol( 13 bool URLRequestJobFactory::Interceptor::WillHandleProtocol(
19 const std::string& protocol) const { 14 const std::string& protocol) const {
20 return false; 15 return false;
21 } 16 }
22 17
23 URLRequestJobFactory::URLRequestJobFactory() {} 18 URLRequestJobFactory::URLRequestJobFactory() {}
24 19
25 URLRequestJobFactory::~URLRequestJobFactory() { 20 URLRequestJobFactory::~URLRequestJobFactory() {}
26 STLDeleteValues(&protocol_handler_map_);
27 STLDeleteElements(&interceptors_);
28 }
29
30 bool URLRequestJobFactory::SetProtocolHandler(
31 const std::string& scheme,
32 ProtocolHandler* protocol_handler) {
33 DCHECK(CalledOnValidThread());
34
35 if (!protocol_handler) {
36 ProtocolHandlerMap::iterator it = protocol_handler_map_.find(scheme);
37 if (it == protocol_handler_map_.end())
38 return false;
39
40 delete it->second;
41 protocol_handler_map_.erase(it);
42 return true;
43 }
44
45 if (ContainsKey(protocol_handler_map_, scheme))
46 return false;
47 protocol_handler_map_[scheme] = protocol_handler;
48 return true;
49 }
50
51 void URLRequestJobFactory::AddInterceptor(Interceptor* interceptor) {
52 DCHECK(CalledOnValidThread());
53 CHECK(interceptor);
54
55 interceptors_.push_back(interceptor);
56 }
57
58 URLRequestJob* URLRequestJobFactory::MaybeCreateJobWithInterceptor(
59 URLRequest* request, NetworkDelegate* network_delegate) const {
60 DCHECK(CalledOnValidThread());
61 URLRequestJob* job = NULL;
62
63 if (!(request->load_flags() & LOAD_DISABLE_INTERCEPT)) {
64 InterceptorList::const_iterator i;
65 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) {
66 job = (*i)->MaybeIntercept(request, network_delegate);
67 if (job)
68 return job;
69 }
70 }
71 return NULL;
72 }
73
74 URLRequestJob* URLRequestJobFactory::MaybeCreateJobWithProtocolHandler(
75 const std::string& scheme,
76 URLRequest* request,
77 NetworkDelegate* network_delegate) const {
78 DCHECK(CalledOnValidThread());
79 ProtocolHandlerMap::const_iterator it = protocol_handler_map_.find(scheme);
80 if (it == protocol_handler_map_.end())
81 return NULL;
82 return it->second->MaybeCreateJob(request, network_delegate);
83 }
84
85 URLRequestJob* URLRequestJobFactory::MaybeInterceptRedirect(
86 const GURL& location,
87 URLRequest* request,
88 NetworkDelegate* network_delegate) const {
89 DCHECK(CalledOnValidThread());
90 URLRequestJob* job = NULL;
91
92 if (!(request->load_flags() & LOAD_DISABLE_INTERCEPT)) {
93 InterceptorList::const_iterator i;
94 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) {
95 job = (*i)->MaybeInterceptRedirect(location, request, network_delegate);
96 if (job)
97 return job;
98 }
99 }
100 return NULL;
101 }
102
103 URLRequestJob* URLRequestJobFactory::MaybeInterceptResponse(
104 URLRequest* request, NetworkDelegate* network_delegate) const {
105 DCHECK(CalledOnValidThread());
106 URLRequestJob* job = NULL;
107
108 if (!(request->load_flags() & LOAD_DISABLE_INTERCEPT)) {
109 InterceptorList::const_iterator i;
110 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) {
111 job = (*i)->MaybeInterceptResponse(request, network_delegate);
112 if (job)
113 return job;
114 }
115 }
116 return NULL;
117 }
118
119 bool URLRequestJobFactory::IsHandledProtocol(const std::string& scheme) const {
120 DCHECK(CalledOnValidThread());
121 InterceptorList::const_iterator i;
122 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) {
123 if ((*i)->WillHandleProtocol(scheme))
124 return true;
125 }
126 return ContainsKey(protocol_handler_map_, scheme) ||
127 URLRequestJobManager::GetInstance()->SupportsScheme(scheme);
128 }
129
130 bool URLRequestJobFactory::IsHandledURL(const GURL& url) const {
131 if (!url.is_valid()) {
132 // We handle error cases.
133 return true;
134 }
135 return IsHandledProtocol(url.scheme());
136 }
137 21
138 } // namespace net 22 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_job_factory.h ('k') | net/url_request/url_request_job_factory_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698