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

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

Issue 2910473005: Deprecate NonThreadSafe in net/ in favor of SequenceChecker/ThreadChecker. (Closed)
Patch Set: rebase on r476634 Created 3 years, 6 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) 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_impl.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 "net/base/load_flags.h" 8 #include "net/base/load_flags.h"
9 #include "net/url_request/url_request_interceptor.h" 9 #include "net/url_request/url_request_interceptor.h"
10 #include "net/url_request/url_request_job_manager.h" 10 #include "net/url_request/url_request_job_manager.h"
11 #include "url/gurl.h" 11 #include "url/gurl.h"
12 12
13 namespace net { 13 namespace net {
14 14
15 namespace { 15 namespace {
16 16
17 URLRequestInterceptor* g_interceptor_for_testing = NULL; 17 URLRequestInterceptor* g_interceptor_for_testing = NULL;
18 18
19 } // namespace 19 } // namespace
20 20
21 URLRequestJobFactoryImpl::URLRequestJobFactoryImpl() {} 21 URLRequestJobFactoryImpl::URLRequestJobFactoryImpl() {}
22 22
23 URLRequestJobFactoryImpl::~URLRequestJobFactoryImpl() {} 23 URLRequestJobFactoryImpl::~URLRequestJobFactoryImpl() {}
24 24
25 bool URLRequestJobFactoryImpl::SetProtocolHandler( 25 bool URLRequestJobFactoryImpl::SetProtocolHandler(
26 const std::string& scheme, 26 const std::string& scheme,
27 std::unique_ptr<ProtocolHandler> protocol_handler) { 27 std::unique_ptr<ProtocolHandler> protocol_handler) {
28 DCHECK(CalledOnValidThread()); 28 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
29 29
30 if (!protocol_handler) { 30 if (!protocol_handler) {
31 ProtocolHandlerMap::iterator it = protocol_handler_map_.find(scheme); 31 ProtocolHandlerMap::iterator it = protocol_handler_map_.find(scheme);
32 if (it == protocol_handler_map_.end()) 32 if (it == protocol_handler_map_.end())
33 return false; 33 return false;
34 34
35 protocol_handler_map_.erase(it); 35 protocol_handler_map_.erase(it);
36 return true; 36 return true;
37 } 37 }
38 38
39 if (base::ContainsKey(protocol_handler_map_, scheme)) 39 if (base::ContainsKey(protocol_handler_map_, scheme))
40 return false; 40 return false;
41 protocol_handler_map_[scheme] = std::move(protocol_handler); 41 protocol_handler_map_[scheme] = std::move(protocol_handler);
42 return true; 42 return true;
43 } 43 }
44 44
45 URLRequestJob* URLRequestJobFactoryImpl::MaybeCreateJobWithProtocolHandler( 45 URLRequestJob* URLRequestJobFactoryImpl::MaybeCreateJobWithProtocolHandler(
46 const std::string& scheme, 46 const std::string& scheme,
47 URLRequest* request, 47 URLRequest* request,
48 NetworkDelegate* network_delegate) const { 48 NetworkDelegate* network_delegate) const {
49 DCHECK(CalledOnValidThread()); 49 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
50 if (g_interceptor_for_testing) { 50 if (g_interceptor_for_testing) {
51 URLRequestJob* job = g_interceptor_for_testing->MaybeInterceptRequest( 51 URLRequestJob* job = g_interceptor_for_testing->MaybeInterceptRequest(
52 request, network_delegate); 52 request, network_delegate);
53 if (job) 53 if (job)
54 return job; 54 return job;
55 } 55 }
56 56
57 ProtocolHandlerMap::const_iterator it = protocol_handler_map_.find(scheme); 57 ProtocolHandlerMap::const_iterator it = protocol_handler_map_.find(scheme);
58 if (it == protocol_handler_map_.end()) 58 if (it == protocol_handler_map_.end())
59 return NULL; 59 return NULL;
60 return it->second->MaybeCreateJob(request, network_delegate); 60 return it->second->MaybeCreateJob(request, network_delegate);
61 } 61 }
62 62
63 URLRequestJob* URLRequestJobFactoryImpl::MaybeInterceptRedirect( 63 URLRequestJob* URLRequestJobFactoryImpl::MaybeInterceptRedirect(
64 URLRequest* request, 64 URLRequest* request,
65 NetworkDelegate* network_delegate, 65 NetworkDelegate* network_delegate,
66 const GURL& location) const { 66 const GURL& location) const {
67 return nullptr; 67 return nullptr;
68 } 68 }
69 69
70 URLRequestJob* URLRequestJobFactoryImpl::MaybeInterceptResponse( 70 URLRequestJob* URLRequestJobFactoryImpl::MaybeInterceptResponse(
71 URLRequest* request, 71 URLRequest* request,
72 NetworkDelegate* network_delegate) const { 72 NetworkDelegate* network_delegate) const {
73 return nullptr; 73 return nullptr;
74 } 74 }
75 75
76 bool URLRequestJobFactoryImpl::IsHandledProtocol( 76 bool URLRequestJobFactoryImpl::IsHandledProtocol(
77 const std::string& scheme) const { 77 const std::string& scheme) const {
78 DCHECK(CalledOnValidThread()); 78 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
79 return base::ContainsKey(protocol_handler_map_, scheme) || 79 return base::ContainsKey(protocol_handler_map_, scheme) ||
80 URLRequestJobManager::GetInstance()->SupportsScheme(scheme); 80 URLRequestJobManager::GetInstance()->SupportsScheme(scheme);
81 } 81 }
82 82
83 bool URLRequestJobFactoryImpl::IsSafeRedirectTarget( 83 bool URLRequestJobFactoryImpl::IsSafeRedirectTarget(
84 const GURL& location) const { 84 const GURL& location) const {
85 DCHECK(CalledOnValidThread()); 85 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
86 if (!location.is_valid()) { 86 if (!location.is_valid()) {
87 // Error cases are safely handled. 87 // Error cases are safely handled.
88 return true; 88 return true;
89 } 89 }
90 ProtocolHandlerMap::const_iterator it = protocol_handler_map_.find( 90 ProtocolHandlerMap::const_iterator it = protocol_handler_map_.find(
91 location.scheme()); 91 location.scheme());
92 if (it == protocol_handler_map_.end()) { 92 if (it == protocol_handler_map_.end()) {
93 // Unhandled cases are safely handled. 93 // Unhandled cases are safely handled.
94 return true; 94 return true;
95 } 95 }
96 return it->second->IsSafeRedirectTarget(location); 96 return it->second->IsSafeRedirectTarget(location);
97 } 97 }
98 98
99 // static 99 // static
100 void URLRequestJobFactoryImpl::SetInterceptorForTesting( 100 void URLRequestJobFactoryImpl::SetInterceptorForTesting(
101 URLRequestInterceptor* interceptor) { 101 URLRequestInterceptor* interceptor) {
102 DCHECK(!interceptor || !g_interceptor_for_testing); 102 DCHECK(!interceptor || !g_interceptor_for_testing);
103 103
104 g_interceptor_for_testing = interceptor; 104 g_interceptor_for_testing = interceptor;
105 } 105 }
106 106
107 } // namespace net 107 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_job_factory.cc ('k') | net/url_request/url_request_throttler_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698