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

Side by Side Diff: net/url_request/url_request_job_factory_impl.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_impl.h"
6 6
7 #include "base/stl_util.h" 7 #include "base/stl_util.h"
8 #include "googleurl/src/gurl.h" 8 #include "googleurl/src/gurl.h"
9 #include "net/base/load_flags.h" 9 #include "net/base/load_flags.h"
10 #include "net/url_request/url_request_job_manager.h" 10 #include "net/url_request/url_request_job_manager.h"
11 11
12 namespace net { 12 namespace net {
13 13
14 URLRequestJobFactory::ProtocolHandler::~ProtocolHandler() {} 14 URLRequestJobFactoryImpl::URLRequestJobFactoryImpl() {}
15 15
16 URLRequestJobFactory::Interceptor::~Interceptor() {} 16 URLRequestJobFactoryImpl::~URLRequestJobFactoryImpl() {
17
18 bool URLRequestJobFactory::Interceptor::WillHandleProtocol(
19 const std::string& protocol) const {
20 return false;
21 }
22
23 URLRequestJobFactory::URLRequestJobFactory() {}
24
25 URLRequestJobFactory::~URLRequestJobFactory() {
26 STLDeleteValues(&protocol_handler_map_); 17 STLDeleteValues(&protocol_handler_map_);
27 STLDeleteElements(&interceptors_); 18 STLDeleteElements(&interceptors_);
28 } 19 }
29 20
30 bool URLRequestJobFactory::SetProtocolHandler( 21 bool URLRequestJobFactoryImpl::SetProtocolHandler(
31 const std::string& scheme, 22 const std::string& scheme,
32 ProtocolHandler* protocol_handler) { 23 ProtocolHandler* protocol_handler) {
33 DCHECK(CalledOnValidThread()); 24 DCHECK(CalledOnValidThread());
34 25
35 if (!protocol_handler) { 26 if (!protocol_handler) {
36 ProtocolHandlerMap::iterator it = protocol_handler_map_.find(scheme); 27 ProtocolHandlerMap::iterator it = protocol_handler_map_.find(scheme);
37 if (it == protocol_handler_map_.end()) 28 if (it == protocol_handler_map_.end())
38 return false; 29 return false;
39 30
40 delete it->second; 31 delete it->second;
41 protocol_handler_map_.erase(it); 32 protocol_handler_map_.erase(it);
42 return true; 33 return true;
43 } 34 }
44 35
45 if (ContainsKey(protocol_handler_map_, scheme)) 36 if (ContainsKey(protocol_handler_map_, scheme))
46 return false; 37 return false;
47 protocol_handler_map_[scheme] = protocol_handler; 38 protocol_handler_map_[scheme] = protocol_handler;
48 return true; 39 return true;
49 } 40 }
50 41
51 void URLRequestJobFactory::AddInterceptor(Interceptor* interceptor) { 42 void URLRequestJobFactoryImpl::AddInterceptor(Interceptor* interceptor) {
52 DCHECK(CalledOnValidThread()); 43 DCHECK(CalledOnValidThread());
53 CHECK(interceptor); 44 CHECK(interceptor);
54 45
55 interceptors_.push_back(interceptor); 46 interceptors_.push_back(interceptor);
56 } 47 }
57 48
58 URLRequestJob* URLRequestJobFactory::MaybeCreateJobWithInterceptor( 49 URLRequestJob* URLRequestJobFactoryImpl::MaybeCreateJobWithInterceptor(
59 URLRequest* request, NetworkDelegate* network_delegate) const { 50 URLRequest* request, NetworkDelegate* network_delegate) const {
60 DCHECK(CalledOnValidThread()); 51 DCHECK(CalledOnValidThread());
61 URLRequestJob* job = NULL; 52 URLRequestJob* job = NULL;
62 53
63 if (!(request->load_flags() & LOAD_DISABLE_INTERCEPT)) { 54 if (!(request->load_flags() & LOAD_DISABLE_INTERCEPT)) {
64 InterceptorList::const_iterator i; 55 InterceptorList::const_iterator i;
65 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) { 56 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) {
66 job = (*i)->MaybeIntercept(request, network_delegate); 57 job = (*i)->MaybeIntercept(request, network_delegate);
67 if (job) 58 if (job)
68 return job; 59 return job;
69 } 60 }
70 } 61 }
71 return NULL; 62 return NULL;
72 } 63 }
73 64
74 URLRequestJob* URLRequestJobFactory::MaybeCreateJobWithProtocolHandler( 65 URLRequestJob* URLRequestJobFactoryImpl::MaybeCreateJobWithProtocolHandler(
75 const std::string& scheme, 66 const std::string& scheme,
76 URLRequest* request, 67 URLRequest* request,
77 NetworkDelegate* network_delegate) const { 68 NetworkDelegate* network_delegate) const {
78 DCHECK(CalledOnValidThread()); 69 DCHECK(CalledOnValidThread());
79 ProtocolHandlerMap::const_iterator it = protocol_handler_map_.find(scheme); 70 ProtocolHandlerMap::const_iterator it = protocol_handler_map_.find(scheme);
80 if (it == protocol_handler_map_.end()) 71 if (it == protocol_handler_map_.end())
81 return NULL; 72 return NULL;
82 return it->second->MaybeCreateJob(request, network_delegate); 73 return it->second->MaybeCreateJob(request, network_delegate);
83 } 74 }
84 75
85 URLRequestJob* URLRequestJobFactory::MaybeInterceptRedirect( 76 URLRequestJob* URLRequestJobFactoryImpl::MaybeInterceptRedirect(
86 const GURL& location, 77 const GURL& location,
87 URLRequest* request, 78 URLRequest* request,
88 NetworkDelegate* network_delegate) const { 79 NetworkDelegate* network_delegate) const {
89 DCHECK(CalledOnValidThread()); 80 DCHECK(CalledOnValidThread());
90 URLRequestJob* job = NULL; 81 URLRequestJob* job = NULL;
91 82
92 if (!(request->load_flags() & LOAD_DISABLE_INTERCEPT)) { 83 if (!(request->load_flags() & LOAD_DISABLE_INTERCEPT)) {
93 InterceptorList::const_iterator i; 84 InterceptorList::const_iterator i;
94 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) { 85 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) {
95 job = (*i)->MaybeInterceptRedirect(location, request, network_delegate); 86 job = (*i)->MaybeInterceptRedirect(location, request, network_delegate);
96 if (job) 87 if (job)
97 return job; 88 return job;
98 } 89 }
99 } 90 }
100 return NULL; 91 return NULL;
101 } 92 }
102 93
103 URLRequestJob* URLRequestJobFactory::MaybeInterceptResponse( 94 URLRequestJob* URLRequestJobFactoryImpl::MaybeInterceptResponse(
104 URLRequest* request, NetworkDelegate* network_delegate) const { 95 URLRequest* request, NetworkDelegate* network_delegate) const {
105 DCHECK(CalledOnValidThread()); 96 DCHECK(CalledOnValidThread());
106 URLRequestJob* job = NULL; 97 URLRequestJob* job = NULL;
107 98
108 if (!(request->load_flags() & LOAD_DISABLE_INTERCEPT)) { 99 if (!(request->load_flags() & LOAD_DISABLE_INTERCEPT)) {
109 InterceptorList::const_iterator i; 100 InterceptorList::const_iterator i;
110 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) { 101 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) {
111 job = (*i)->MaybeInterceptResponse(request, network_delegate); 102 job = (*i)->MaybeInterceptResponse(request, network_delegate);
112 if (job) 103 if (job)
113 return job; 104 return job;
114 } 105 }
115 } 106 }
116 return NULL; 107 return NULL;
117 } 108 }
118 109
119 bool URLRequestJobFactory::IsHandledProtocol(const std::string& scheme) const { 110 bool URLRequestJobFactoryImpl::IsHandledProtocol(
111 const std::string& scheme) const {
120 DCHECK(CalledOnValidThread()); 112 DCHECK(CalledOnValidThread());
121 InterceptorList::const_iterator i; 113 InterceptorList::const_iterator i;
122 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) { 114 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) {
123 if ((*i)->WillHandleProtocol(scheme)) 115 if ((*i)->WillHandleProtocol(scheme))
124 return true; 116 return true;
125 } 117 }
126 return ContainsKey(protocol_handler_map_, scheme) || 118 return ContainsKey(protocol_handler_map_, scheme) ||
127 URLRequestJobManager::GetInstance()->SupportsScheme(scheme); 119 URLRequestJobManager::GetInstance()->SupportsScheme(scheme);
128 } 120 }
129 121
130 bool URLRequestJobFactory::IsHandledURL(const GURL& url) const { 122 bool URLRequestJobFactoryImpl::IsHandledURL(const GURL& url) const {
131 if (!url.is_valid()) { 123 if (!url.is_valid()) {
132 // We handle error cases. 124 // We handle error cases.
133 return true; 125 return true;
134 } 126 }
135 return IsHandledProtocol(url.scheme()); 127 return IsHandledProtocol(url.scheme());
136 } 128 }
137 129
138 } // namespace net 130 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_job_factory_impl.h ('k') | net/url_request/url_request_job_factory_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698