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

Side by Side Diff: net/proxy/dhcp_proxy_script_fetcher_win.cc

Issue 2845643003: Allow ProxyService to share URLRequestContext with everything else. (Closed)
Patch Set: Fix fetcher shutdown with no active request, add test, add comment Created 3 years, 7 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/proxy/dhcp_proxy_script_fetcher_win.h" 5 #include "net/proxy/dhcp_proxy_script_fetcher_win.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 tracked_objects::ScopedTracker tracking_profile1( 75 tracked_objects::ScopedTracker tracking_profile1(
76 FROM_HERE_WITH_EXPLICIT_FUNCTION( 76 FROM_HERE_WITH_EXPLICIT_FUNCTION(
77 "476182 DhcpProxyScriptFetcherWin::Fetch 1")); 77 "476182 DhcpProxyScriptFetcherWin::Fetch 1"));
78 78
79 DCHECK(CalledOnValidThread()); 79 DCHECK(CalledOnValidThread());
80 if (state_ != STATE_START && state_ != STATE_DONE) { 80 if (state_ != STATE_START && state_ != STATE_DONE) {
81 NOTREACHED(); 81 NOTREACHED();
82 return ERR_UNEXPECTED; 82 return ERR_UNEXPECTED;
83 } 83 }
84 84
85 if (!url_request_context_)
86 return ERR_CONTEXT_SHUT_DOWN;
87
85 state_ = STATE_WAIT_ADAPTERS; 88 state_ = STATE_WAIT_ADAPTERS;
86 callback_ = callback; 89 callback_ = callback;
87 destination_string_ = utf16_text; 90 destination_string_ = utf16_text;
88 91
89 last_query_ = ImplCreateAdapterQuery(); 92 last_query_ = ImplCreateAdapterQuery();
90 // TODO(joi): Remove ScopedTracker below once crbug.com/476182 is fixed. 93 // TODO(joi): Remove ScopedTracker below once crbug.com/476182 is fixed.
91 tracked_objects::ScopedTracker tracking_profile2( 94 tracked_objects::ScopedTracker tracking_profile2(
92 FROM_HERE_WITH_EXPLICIT_FUNCTION( 95 FROM_HERE_WITH_EXPLICIT_FUNCTION(
93 "476182 DhcpProxyScriptFetcherWin::Fetch 2")); 96 "476182 DhcpProxyScriptFetcherWin::Fetch 2"));
94 GetTaskRunner()->PostTaskAndReply( 97 GetTaskRunner()->PostTaskAndReply(
95 FROM_HERE, 98 FROM_HERE,
96 base::Bind( 99 base::Bind(
97 &DhcpProxyScriptFetcherWin::AdapterQuery::GetCandidateAdapterNames, 100 &DhcpProxyScriptFetcherWin::AdapterQuery::GetCandidateAdapterNames,
98 last_query_.get()), 101 last_query_.get()),
99 base::Bind( 102 base::Bind(
100 &DhcpProxyScriptFetcherWin::OnGetCandidateAdapterNamesDone, 103 &DhcpProxyScriptFetcherWin::OnGetCandidateAdapterNamesDone,
101 AsWeakPtr(), 104 AsWeakPtr(),
102 last_query_)); 105 last_query_));
103 106
104 return ERR_IO_PENDING; 107 return ERR_IO_PENDING;
105 } 108 }
106 109
107 void DhcpProxyScriptFetcherWin::Cancel() { 110 void DhcpProxyScriptFetcherWin::Cancel() {
108 DCHECK(CalledOnValidThread()); 111 DCHECK(CalledOnValidThread());
109 112
110 CancelImpl(); 113 CancelImpl();
111 } 114 }
112 115
116 void DhcpProxyScriptFetcherWin::OnShutdown() {
117 DCHECK(CalledOnValidThread());
118
119 // Back up callback, if there is one, as CancelImpl() will destroy it.
120 net::CompletionCallback callback = std::move(callback_);
121
122 // Cancel current request, if there is one.
123 CancelImpl();
124
125 // Prevent future network requests.
126 url_request_context_ = nullptr;
127
128 // Invoke callback with error, if present.
129 if (callback)
130 callback.Run(ERR_CONTEXT_SHUT_DOWN);
131 }
132
113 void DhcpProxyScriptFetcherWin::CancelImpl() { 133 void DhcpProxyScriptFetcherWin::CancelImpl() {
114 DCHECK(CalledOnValidThread()); 134 DCHECK(CalledOnValidThread());
115 135
116 if (state_ != STATE_DONE) { 136 if (state_ != STATE_DONE) {
117 callback_.Reset(); 137 callback_.Reset();
118 wait_timer_.Stop(); 138 wait_timer_.Stop();
119 state_ = STATE_DONE; 139 state_ = STATE_DONE;
120 140
121 for (FetcherVector::iterator it = fetchers_.begin(); 141 for (FetcherVector::iterator it = fetchers_.begin();
122 it != fetchers_.end(); 142 it != fetchers_.end();
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 394
375 bool DhcpProxyScriptFetcherWin::AdapterQuery::ImplGetCandidateAdapterNames( 395 bool DhcpProxyScriptFetcherWin::AdapterQuery::ImplGetCandidateAdapterNames(
376 std::set<std::string>* adapter_names) { 396 std::set<std::string>* adapter_names) {
377 return DhcpProxyScriptFetcherWin::GetCandidateAdapterNames(adapter_names); 397 return DhcpProxyScriptFetcherWin::GetCandidateAdapterNames(adapter_names);
378 } 398 }
379 399
380 DhcpProxyScriptFetcherWin::AdapterQuery::~AdapterQuery() { 400 DhcpProxyScriptFetcherWin::AdapterQuery::~AdapterQuery() {
381 } 401 }
382 402
383 } // namespace net 403 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/dhcp_proxy_script_fetcher_win.h ('k') | net/proxy/dhcp_proxy_script_fetcher_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698