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

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: Fixed nits Created 8 years, 3 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) const { 50 URLRequest* request) 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); 57 job = (*i)->MaybeIntercept(request);
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) const { 67 URLRequest* request) const {
77 DCHECK(CalledOnValidThread()); 68 DCHECK(CalledOnValidThread());
78 ProtocolHandlerMap::const_iterator it = protocol_handler_map_.find(scheme); 69 ProtocolHandlerMap::const_iterator it = protocol_handler_map_.find(scheme);
79 if (it == protocol_handler_map_.end()) 70 if (it == protocol_handler_map_.end())
80 return NULL; 71 return NULL;
81 return it->second->MaybeCreateJob(request); 72 return it->second->MaybeCreateJob(request);
82 } 73 }
83 74
84 URLRequestJob* URLRequestJobFactory::MaybeInterceptRedirect( 75 URLRequestJob* URLRequestJobFactoryImpl::MaybeInterceptRedirect(
85 const GURL& location, 76 const GURL& location,
86 URLRequest* request) const { 77 URLRequest* request) const {
87 DCHECK(CalledOnValidThread()); 78 DCHECK(CalledOnValidThread());
88 URLRequestJob* job = NULL; 79 URLRequestJob* job = NULL;
89 80
90 if (!(request->load_flags() & LOAD_DISABLE_INTERCEPT)) { 81 if (!(request->load_flags() & LOAD_DISABLE_INTERCEPT)) {
91 InterceptorList::const_iterator i; 82 InterceptorList::const_iterator i;
92 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) { 83 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) {
93 job = (*i)->MaybeInterceptRedirect(location, request); 84 job = (*i)->MaybeInterceptRedirect(location, request);
94 if (job) 85 if (job)
95 return job; 86 return job;
96 } 87 }
97 } 88 }
98 return NULL; 89 return NULL;
99 } 90 }
100 91
101 URLRequestJob* URLRequestJobFactory::MaybeInterceptResponse( 92 URLRequestJob* URLRequestJobFactoryImpl::MaybeInterceptResponse(
102 URLRequest* request) const { 93 URLRequest* request) const {
103 DCHECK(CalledOnValidThread()); 94 DCHECK(CalledOnValidThread());
104 URLRequestJob* job = NULL; 95 URLRequestJob* job = NULL;
105 96
106 if (!(request->load_flags() & LOAD_DISABLE_INTERCEPT)) { 97 if (!(request->load_flags() & LOAD_DISABLE_INTERCEPT)) {
107 InterceptorList::const_iterator i; 98 InterceptorList::const_iterator i;
108 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) { 99 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) {
109 job = (*i)->MaybeInterceptResponse(request); 100 job = (*i)->MaybeInterceptResponse(request);
110 if (job) 101 if (job)
111 return job; 102 return job;
112 } 103 }
113 } 104 }
114 return NULL; 105 return NULL;
115 } 106 }
116 107
117 bool URLRequestJobFactory::IsHandledProtocol(const std::string& scheme) const { 108 bool URLRequestJobFactoryImpl::IsHandledProtocol(
109 const std::string& scheme) const {
118 DCHECK(CalledOnValidThread()); 110 DCHECK(CalledOnValidThread());
119 InterceptorList::const_iterator i; 111 InterceptorList::const_iterator i;
120 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) { 112 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) {
121 if ((*i)->WillHandleProtocol(scheme)) 113 if ((*i)->WillHandleProtocol(scheme))
122 return true; 114 return true;
123 } 115 }
124 return ContainsKey(protocol_handler_map_, scheme) || 116 return ContainsKey(protocol_handler_map_, scheme) ||
125 URLRequestJobManager::GetInstance()->SupportsScheme(scheme); 117 URLRequestJobManager::GetInstance()->SupportsScheme(scheme);
126 } 118 }
127 119
128 bool URLRequestJobFactory::IsHandledURL(const GURL& url) const { 120 bool URLRequestJobFactoryImpl::IsHandledURL(const GURL& url) const {
129 if (!url.is_valid()) { 121 if (!url.is_valid()) {
130 // We handle error cases. 122 // We handle error cases.
131 return true; 123 return true;
132 } 124 }
133 return IsHandledProtocol(url.scheme()); 125 return IsHandledProtocol(url.scheme());
134 } 126 }
135 127
136 } // namespace net 128 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698