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

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

Issue 1888963004: Add HttpProtocolHandler and convert everything to use it (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove-supports-scheme
Patch Set: even more rebase Created 4 years, 8 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_manager.h" 5 #include "net/url_request/url_request_job_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/memory/singleton.h" 9 #include "base/memory/singleton.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "net/base/load_flags.h" 12 #include "net/base/load_flags.h"
13 #include "net/base/net_errors.h" 13 #include "net/base/net_errors.h"
14 #include "net/base/network_delegate.h" 14 #include "net/base/network_delegate.h"
15 #include "net/url_request/url_request_context.h" 15 #include "net/url_request/url_request_context.h"
16 #include "net/url_request/url_request_error_job.h" 16 #include "net/url_request/url_request_error_job.h"
17 #include "net/url_request/url_request_http_job.h"
18 #include "net/url_request/url_request_job_factory.h" 17 #include "net/url_request/url_request_job_factory.h"
19 18
20 namespace net { 19 namespace net {
21 20
22 // The built-in set of protocol factories
23 namespace {
24
25 struct SchemeToFactory {
26 const char* scheme;
27 URLRequest::ProtocolFactory* factory;
28 };
29
30 } // namespace
31
32 static const SchemeToFactory kBuiltinFactories[] = {
33 { "http", URLRequestHttpJob::Factory },
34 { "https", URLRequestHttpJob::Factory },
35
36 #if !defined(OS_IOS)
37 { "ws", URLRequestHttpJob::Factory },
38 { "wss", URLRequestHttpJob::Factory },
39 #endif // !defined(OS_IOS)
40 };
41
42 // static 21 // static
43 URLRequestJobManager* URLRequestJobManager::GetInstance() { 22 URLRequestJobManager* URLRequestJobManager::GetInstance() {
44 return base::Singleton<URLRequestJobManager>::get(); 23 return base::Singleton<URLRequestJobManager>::get();
45 } 24 }
46 25
47 URLRequestJob* URLRequestJobManager::CreateJob( 26 URLRequestJob* URLRequestJobManager::CreateJob(
48 URLRequest* request, NetworkDelegate* network_delegate) const { 27 URLRequest* request, NetworkDelegate* network_delegate) const {
49 DCHECK(IsAllowedThread()); 28 DCHECK(IsAllowedThread());
50 29
51 // If we are given an invalid URL, then don't even try to inspect the scheme. 30 // If we are given an invalid URL, then don't even try to inspect the scheme.
(...skipping 14 matching lines...) Expand all
66 // We do not need to acquire the lock here since we are only reading our 45 // We do not need to acquire the lock here since we are only reading our
67 // data structures. They should only be modified on the current thread. 46 // data structures. They should only be modified on the current thread.
68 47
69 // See if the request should be intercepted. 48 // See if the request should be intercepted.
70 // 49 //
71 URLRequestJob* job = job_factory->MaybeCreateJobWithProtocolHandler( 50 URLRequestJob* job = job_factory->MaybeCreateJobWithProtocolHandler(
72 scheme, request, network_delegate); 51 scheme, request, network_delegate);
73 if (job) 52 if (job)
74 return job; 53 return job;
75 54
76 // See if the request should be handled by a built-in protocol factory.
77 for (size_t i = 0; i < arraysize(kBuiltinFactories); ++i) {
78 if (scheme == kBuiltinFactories[i].scheme) {
79 URLRequestJob* new_job =
80 (kBuiltinFactories[i].factory)(request, network_delegate, scheme);
81 DCHECK(new_job); // The built-in factories are not expected to fail!
82 return new_job;
83 }
84 }
85
86 // If we reached here, then it means that a registered protocol factory 55 // If we reached here, then it means that a registered protocol factory
87 // wasn't interested in handling the URL. That is fairly unexpected, and we 56 // wasn't interested in handling the URL. That is fairly unexpected, and we
88 // don't have a specific error to report here :-( 57 // don't have a specific error to report here :-(
89 LOG(WARNING) << "Failed to map: " << request->url().spec(); 58 LOG(WARNING) << "Failed to map: " << request->url().spec();
90 return new URLRequestErrorJob(request, network_delegate, ERR_FAILED); 59 return new URLRequestErrorJob(request, network_delegate, ERR_FAILED);
91 } 60 }
92 61
93 URLRequestJob* URLRequestJobManager::MaybeInterceptRedirect( 62 URLRequestJob* URLRequestJobManager::MaybeInterceptRedirect(
94 URLRequest* request, 63 URLRequest* request,
95 NetworkDelegate* network_delegate, 64 NetworkDelegate* network_delegate,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 102
134 URLRequestJob* job = 103 URLRequestJob* job =
135 request->context()->job_factory()->MaybeInterceptResponse( 104 request->context()->job_factory()->MaybeInterceptResponse(
136 request, network_delegate); 105 request, network_delegate);
137 if (job) 106 if (job)
138 return job; 107 return job;
139 108
140 return NULL; 109 return NULL;
141 } 110 }
142 111
143 // TODO(mgersh): remove this and fix remaining callers once HttpProtocolHandler
144 // exists
145 // static
146 bool URLRequestJobManager::SupportsScheme(const std::string& scheme) {
147 for (size_t i = 0; i < arraysize(kBuiltinFactories); ++i) {
148 if (base::LowerCaseEqualsASCII(scheme, kBuiltinFactories[i].scheme))
149 return true;
150 }
151
152 return false;
153 }
154
155 URLRequestJobManager::URLRequestJobManager() { 112 URLRequestJobManager::URLRequestJobManager() {
156 } 113 }
157 114
158 URLRequestJobManager::~URLRequestJobManager() {} 115 URLRequestJobManager::~URLRequestJobManager() {}
159 116
160 } // namespace net 117 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698