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

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

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, 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 #ifndef NET_URL_REQUEST_URL_REQUEST_JOB_FACTORY_H_ 5 #ifndef NET_URL_REQUEST_URL_REQUEST_JOB_FACTORY_H_
6 #define NET_URL_REQUEST_URL_REQUEST_JOB_FACTORY_H_ 6 #define NET_URL_REQUEST_URL_REQUEST_JOB_FACTORY_H_
7 7
8 #include <map>
9 #include <string> 8 #include <string>
mmenke 2012/08/23 15:00:21 While you're here, could you add a blank line afte
shalev 2012/08/23 15:15:46 Done.
10 #include <vector>
11 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/compiler_specific.h"
12 #include "base/threading/non_thread_safe.h" 11 #include "base/threading/non_thread_safe.h"
13 #include "net/base/net_export.h" 12 #include "net/base/net_export.h"
14 13
15 class GURL; 14 class GURL;
16 15
17 namespace net { 16 namespace net {
18 17
19 class URLRequest; 18 class URLRequest;
20 class URLRequestJob; 19 class URLRequestJob;
21 20
22 class NET_EXPORT URLRequestJobFactory 21 class NET_EXPORT URLRequestJobFactory
23 : NON_EXPORTED_BASE(public base::NonThreadSafe) { 22 : NON_EXPORTED_BASE(public base::NonThreadSafe) {
24 public: 23 public:
24 // TODO(shalev): Move this to URLRequestJobFactoryImpl.
25 class NET_EXPORT ProtocolHandler { 25 class NET_EXPORT ProtocolHandler {
26 public: 26 public:
27 virtual ~ProtocolHandler(); 27 virtual ~ProtocolHandler();
28 28
29 virtual URLRequestJob* MaybeCreateJob(URLRequest* request) const = 0; 29 virtual URLRequestJob* MaybeCreateJob(URLRequest* request) const = 0;
30 }; 30 };
31 31
32 // TODO(shalev): Move this to URLRequestJobFactoryImpl.
32 class NET_EXPORT Interceptor { 33 class NET_EXPORT Interceptor {
33 public: 34 public:
34 virtual ~Interceptor(); 35 virtual ~Interceptor();
35 36
36 // Called for every request made. Should return a new job to handle the 37 // Called for every request made. Should return a new job to handle the
37 // request if it should be intercepted, or NULL to allow the request to 38 // request if it should be intercepted, or NULL to allow the request to
38 // be handled in the normal manner. 39 // be handled in the normal manner.
39 virtual URLRequestJob* MaybeIntercept(URLRequest* request) const = 0; 40 virtual URLRequestJob* MaybeIntercept(URLRequest* request) const = 0;
40 41
41 // Called after having received a redirect response, but prior to the 42 // Called after having received a redirect response, but prior to the
(...skipping 17 matching lines...) Expand all
59 virtual URLRequestJob* MaybeInterceptResponse( 60 virtual URLRequestJob* MaybeInterceptResponse(
60 URLRequest* request) const = 0; 61 URLRequest* request) const = 0;
61 62
62 // Returns true if this interceptor handles requests for URLs with the 63 // Returns true if this interceptor handles requests for URLs with the
63 // given protocol. Returning false does not imply that this interceptor 64 // given protocol. Returning false does not imply that this interceptor
64 // can't or won't handle requests with the given protocol. 65 // can't or won't handle requests with the given protocol.
65 virtual bool WillHandleProtocol(const std::string& protocol) const; 66 virtual bool WillHandleProtocol(const std::string& protocol) const;
66 }; 67 };
67 68
68 URLRequestJobFactory(); 69 URLRequestJobFactory();
69 ~URLRequestJobFactory(); 70 virtual ~URLRequestJobFactory();
70 71
72 // TODO(shalev): Remove this from the interface.
71 // Sets the ProtocolHandler for a scheme. Returns true on success, false on 73 // Sets the ProtocolHandler for a scheme. Returns true on success, false on
72 // failure (a ProtocolHandler already exists for |scheme|). On success, 74 // failure (a ProtocolHandler already exists for |scheme|). On success,
73 // URLRequestJobFactory takes ownership of |protocol_handler|. 75 // URLRequestJobFactory takes ownership of |protocol_handler|.
74 bool SetProtocolHandler(const std::string& scheme, 76 virtual bool SetProtocolHandler(const std::string& scheme,
75 ProtocolHandler* protocol_handler); 77 ProtocolHandler* protocol_handler) = 0;
76 78
79 // TODO(shalev): Remove this from the interface.
77 // Takes ownership of |interceptor|. Adds it to the end of the Interceptor 80 // Takes ownership of |interceptor|. Adds it to the end of the Interceptor
78 // list. 81 // list.
79 void AddInterceptor(Interceptor* interceptor); 82 virtual void AddInterceptor(Interceptor* interceptor) = 0;
80 83
81 URLRequestJob* MaybeCreateJobWithInterceptor(URLRequest* request) const; 84 // TODO(shalev): Consolidate MaybeCreateJobWithInterceptor and
85 // MaybeCreateJobWithProtocolHandler into a single method.
86 virtual URLRequestJob* MaybeCreateJobWithInterceptor(
87 URLRequest* request) const = 0;
82 88
83 URLRequestJob* MaybeCreateJobWithProtocolHandler(const std::string& scheme, 89 virtual URLRequestJob* MaybeCreateJobWithProtocolHandler(
84 URLRequest* request) const; 90 const std::string& scheme, URLRequest* request) const = 0;
85 91
86 URLRequestJob* MaybeInterceptRedirect(const GURL& location, 92 virtual URLRequestJob* MaybeInterceptRedirect(
87 URLRequest* request) const; 93 const GURL& location, URLRequest* request) const = 0;
88 94
89 URLRequestJob* MaybeInterceptResponse(URLRequest* request) const; 95 virtual URLRequestJob* MaybeInterceptResponse(URLRequest* request) const = 0;
90 96
91 bool IsHandledProtocol(const std::string& scheme) const; 97 virtual bool IsHandledProtocol(const std::string& scheme) const = 0;
92 98
93 bool IsHandledURL(const GURL& url) const; 99 virtual bool IsHandledURL(const GURL& url) const = 0;
94 100
95 private: 101 private:
96 typedef std::map<std::string, ProtocolHandler*> ProtocolHandlerMap;
97 typedef std::vector<Interceptor*> InterceptorList;
98
99 ProtocolHandlerMap protocol_handler_map_;
100 InterceptorList interceptors_;
101
102 DISALLOW_COPY_AND_ASSIGN(URLRequestJobFactory); 102 DISALLOW_COPY_AND_ASSIGN(URLRequestJobFactory);
103 }; 103 };
104 104
105 } // namespace net 105 } // namespace net
106 106
107 #endif // NET_URL_REQUEST_URL_REQUEST_JOB_FACTORY_H_ 107 #endif // NET_URL_REQUEST_URL_REQUEST_JOB_FACTORY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698