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

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: Cleaned up, responded to suggestions 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" 7 #include "base/stl_util.h"
willchan no longer on Chromium 2012/08/16 20:35:37 I think we can kill off most of these, right?
shalev 2012/08/22 19:10:11 Done.
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 URLRequestJobFactory::ProtocolHandler::~ProtocolHandler() {}
15 15
16 URLRequestJobFactory::Interceptor::~Interceptor() {} 16 URLRequestJobFactory::Interceptor::~Interceptor() {}
17 17
18 bool URLRequestJobFactory::Interceptor::WillHandleProtocol( 18 bool URLRequestJobFactory::Interceptor::WillHandleProtocol(
19 const std::string& protocol) const { 19 const std::string& protocol) const {
20 return false; 20 return false;
21 } 21 }
22 22
23 URLRequestJobFactory::URLRequestJobFactory() {} 23 URLRequestJobFactory::URLRequestJobFactory() {}
24 24
25 URLRequestJobFactory::~URLRequestJobFactory() { 25 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) 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);
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) const {
77 DCHECK(CalledOnValidThread());
78 ProtocolHandlerMap::const_iterator it = protocol_handler_map_.find(scheme);
79 if (it == protocol_handler_map_.end())
80 return NULL;
81 return it->second->MaybeCreateJob(request);
82 }
83
84 URLRequestJob* URLRequestJobFactory::MaybeInterceptRedirect(
85 const GURL& location,
86 URLRequest* request) const {
87 DCHECK(CalledOnValidThread());
88 URLRequestJob* job = NULL;
89
90 if (!(request->load_flags() & LOAD_DISABLE_INTERCEPT)) {
91 InterceptorList::const_iterator i;
92 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) {
93 job = (*i)->MaybeInterceptRedirect(location, request);
94 if (job)
95 return job;
96 }
97 }
98 return NULL;
99 }
100
101 URLRequestJob* URLRequestJobFactory::MaybeInterceptResponse(
102 URLRequest* request) const {
103 DCHECK(CalledOnValidThread());
104 URLRequestJob* job = NULL;
105
106 if (!(request->load_flags() & LOAD_DISABLE_INTERCEPT)) {
107 InterceptorList::const_iterator i;
108 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) {
109 job = (*i)->MaybeInterceptResponse(request);
110 if (job)
111 return job;
112 }
113 }
114 return NULL;
115 }
116
117 bool URLRequestJobFactory::IsHandledProtocol(const std::string& scheme) const {
118 DCHECK(CalledOnValidThread());
119 InterceptorList::const_iterator i;
120 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) {
121 if ((*i)->WillHandleProtocol(scheme))
122 return true;
123 }
124 return ContainsKey(protocol_handler_map_, scheme) ||
125 URLRequestJobManager::GetInstance()->SupportsScheme(scheme);
126 }
127
128 bool URLRequestJobFactory::IsHandledURL(const GURL& url) const {
129 if (!url.is_valid()) {
130 // We handle error cases.
131 return true;
132 }
133 return IsHandledProtocol(url.scheme());
134 }
135 26
136 } // namespace net 27 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698