OLD | NEW |
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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 num_pending_fetchers_(0), | 56 num_pending_fetchers_(0), |
57 destination_string_(NULL), | 57 destination_string_(NULL), |
58 url_request_context_(url_request_context) { | 58 url_request_context_(url_request_context) { |
59 DCHECK(url_request_context_); | 59 DCHECK(url_request_context_); |
60 | 60 |
61 worker_pool_ = new base::SequencedWorkerPool( | 61 worker_pool_ = new base::SequencedWorkerPool( |
62 kMaxDhcpLookupThreads, "PacDhcpLookup", base::TaskPriority::USER_VISIBLE); | 62 kMaxDhcpLookupThreads, "PacDhcpLookup", base::TaskPriority::USER_VISIBLE); |
63 } | 63 } |
64 | 64 |
65 DhcpProxyScriptFetcherWin::~DhcpProxyScriptFetcherWin() { | 65 DhcpProxyScriptFetcherWin::~DhcpProxyScriptFetcherWin() { |
| 66 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
66 // Count as user-initiated if we are not yet in STATE_DONE. | 67 // Count as user-initiated if we are not yet in STATE_DONE. |
67 Cancel(); | 68 Cancel(); |
68 | 69 |
69 worker_pool_->Shutdown(); | 70 worker_pool_->Shutdown(); |
70 } | 71 } |
71 | 72 |
72 int DhcpProxyScriptFetcherWin::Fetch(base::string16* utf16_text, | 73 int DhcpProxyScriptFetcherWin::Fetch(base::string16* utf16_text, |
73 const CompletionCallback& callback) { | 74 const CompletionCallback& callback) { |
74 // TODO(joi): Remove ScopedTracker below once crbug.com/476182 is fixed. | 75 // TODO(joi): Remove ScopedTracker below once crbug.com/476182 is fixed. |
75 tracked_objects::ScopedTracker tracking_profile1( | 76 tracked_objects::ScopedTracker tracking_profile1( |
76 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 77 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
77 "476182 DhcpProxyScriptFetcherWin::Fetch 1")); | 78 "476182 DhcpProxyScriptFetcherWin::Fetch 1")); |
78 | 79 |
79 DCHECK(CalledOnValidThread()); | 80 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
80 if (state_ != STATE_START && state_ != STATE_DONE) { | 81 if (state_ != STATE_START && state_ != STATE_DONE) { |
81 NOTREACHED(); | 82 NOTREACHED(); |
82 return ERR_UNEXPECTED; | 83 return ERR_UNEXPECTED; |
83 } | 84 } |
84 | 85 |
85 if (!url_request_context_) | 86 if (!url_request_context_) |
86 return ERR_CONTEXT_SHUT_DOWN; | 87 return ERR_CONTEXT_SHUT_DOWN; |
87 | 88 |
88 state_ = STATE_WAIT_ADAPTERS; | 89 state_ = STATE_WAIT_ADAPTERS; |
89 callback_ = callback; | 90 callback_ = callback; |
(...skipping 11 matching lines...) Expand all Loading... |
101 last_query_.get()), | 102 last_query_.get()), |
102 base::Bind( | 103 base::Bind( |
103 &DhcpProxyScriptFetcherWin::OnGetCandidateAdapterNamesDone, | 104 &DhcpProxyScriptFetcherWin::OnGetCandidateAdapterNamesDone, |
104 AsWeakPtr(), | 105 AsWeakPtr(), |
105 last_query_)); | 106 last_query_)); |
106 | 107 |
107 return ERR_IO_PENDING; | 108 return ERR_IO_PENDING; |
108 } | 109 } |
109 | 110 |
110 void DhcpProxyScriptFetcherWin::Cancel() { | 111 void DhcpProxyScriptFetcherWin::Cancel() { |
111 DCHECK(CalledOnValidThread()); | 112 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
112 | 113 |
113 CancelImpl(); | 114 CancelImpl(); |
114 } | 115 } |
115 | 116 |
116 void DhcpProxyScriptFetcherWin::OnShutdown() { | 117 void DhcpProxyScriptFetcherWin::OnShutdown() { |
117 DCHECK(CalledOnValidThread()); | 118 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
118 | 119 |
119 // Back up callback, if there is one, as CancelImpl() will destroy it. | 120 // Back up callback, if there is one, as CancelImpl() will destroy it. |
120 net::CompletionCallback callback = std::move(callback_); | 121 net::CompletionCallback callback = std::move(callback_); |
121 | 122 |
122 // Cancel current request, if there is one. | 123 // Cancel current request, if there is one. |
123 CancelImpl(); | 124 CancelImpl(); |
124 | 125 |
125 // Prevent future network requests. | 126 // Prevent future network requests. |
126 url_request_context_ = nullptr; | 127 url_request_context_ = nullptr; |
127 | 128 |
128 // Invoke callback with error, if present. | 129 // Invoke callback with error, if present. |
129 if (callback) | 130 if (callback) |
130 callback.Run(ERR_CONTEXT_SHUT_DOWN); | 131 callback.Run(ERR_CONTEXT_SHUT_DOWN); |
131 } | 132 } |
132 | 133 |
133 void DhcpProxyScriptFetcherWin::CancelImpl() { | 134 void DhcpProxyScriptFetcherWin::CancelImpl() { |
134 DCHECK(CalledOnValidThread()); | 135 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
135 | 136 |
136 if (state_ != STATE_DONE) { | 137 if (state_ != STATE_DONE) { |
137 callback_.Reset(); | 138 callback_.Reset(); |
138 wait_timer_.Stop(); | 139 wait_timer_.Stop(); |
139 state_ = STATE_DONE; | 140 state_ = STATE_DONE; |
140 | 141 |
141 for (FetcherVector::iterator it = fetchers_.begin(); | 142 for (FetcherVector::iterator it = fetchers_.begin(); |
142 it != fetchers_.end(); | 143 it != fetchers_.end(); |
143 ++it) { | 144 ++it) { |
144 (*it)->Cancel(); | 145 (*it)->Cancel(); |
145 } | 146 } |
146 | 147 |
147 fetchers_.clear(); | 148 fetchers_.clear(); |
148 } | 149 } |
149 } | 150 } |
150 | 151 |
151 void DhcpProxyScriptFetcherWin::OnGetCandidateAdapterNamesDone( | 152 void DhcpProxyScriptFetcherWin::OnGetCandidateAdapterNamesDone( |
152 scoped_refptr<AdapterQuery> query) { | 153 scoped_refptr<AdapterQuery> query) { |
153 // TODO(joi): Remove ScopedTracker below once crbug.com/476182 is fixed. | 154 // TODO(joi): Remove ScopedTracker below once crbug.com/476182 is fixed. |
154 tracked_objects::ScopedTracker tracking_profile1( | 155 tracked_objects::ScopedTracker tracking_profile1( |
155 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 156 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
156 "476182 " | 157 "476182 " |
157 "DhcpProxyScriptFetcherWin::OnGetCandidateAdapterNamesDone 1")); | 158 "DhcpProxyScriptFetcherWin::OnGetCandidateAdapterNamesDone 1")); |
158 | 159 |
159 DCHECK(CalledOnValidThread()); | 160 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
160 | 161 |
161 // This can happen if this object is reused for multiple queries, | 162 // This can happen if this object is reused for multiple queries, |
162 // and a previous query was cancelled before it completed. | 163 // and a previous query was cancelled before it completed. |
163 if (query.get() != last_query_.get()) | 164 if (query.get() != last_query_.get()) |
164 return; | 165 return; |
165 last_query_ = NULL; | 166 last_query_ = NULL; |
166 | 167 |
167 // Enable unit tests to wait for this to happen; in production this function | 168 // Enable unit tests to wait for this to happen; in production this function |
168 // call is a no-op. | 169 // call is a no-op. |
169 ImplOnGetCandidateAdapterNamesDone(); | 170 ImplOnGetCandidateAdapterNamesDone(); |
(...skipping 30 matching lines...) Expand all Loading... |
200 ImplCreateAdapterFetcher()); | 201 ImplCreateAdapterFetcher()); |
201 fetcher->Fetch( | 202 fetcher->Fetch( |
202 *it, base::Bind(&DhcpProxyScriptFetcherWin::OnFetcherDone, | 203 *it, base::Bind(&DhcpProxyScriptFetcherWin::OnFetcherDone, |
203 base::Unretained(this))); | 204 base::Unretained(this))); |
204 fetchers_.push_back(std::move(fetcher)); | 205 fetchers_.push_back(std::move(fetcher)); |
205 } | 206 } |
206 num_pending_fetchers_ = fetchers_.size(); | 207 num_pending_fetchers_ = fetchers_.size(); |
207 } | 208 } |
208 | 209 |
209 std::string DhcpProxyScriptFetcherWin::GetFetcherName() const { | 210 std::string DhcpProxyScriptFetcherWin::GetFetcherName() const { |
210 DCHECK(CalledOnValidThread()); | 211 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
211 return "win"; | 212 return "win"; |
212 } | 213 } |
213 | 214 |
214 const GURL& DhcpProxyScriptFetcherWin::GetPacURL() const { | 215 const GURL& DhcpProxyScriptFetcherWin::GetPacURL() const { |
215 DCHECK(CalledOnValidThread()); | 216 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
216 DCHECK_EQ(state_, STATE_DONE); | 217 DCHECK_EQ(state_, STATE_DONE); |
217 | 218 |
218 return pac_url_; | 219 return pac_url_; |
219 } | 220 } |
220 | 221 |
221 void DhcpProxyScriptFetcherWin::OnFetcherDone(int result) { | 222 void DhcpProxyScriptFetcherWin::OnFetcherDone(int result) { |
222 DCHECK(state_ == STATE_NO_RESULTS || state_ == STATE_SOME_RESULTS); | 223 DCHECK(state_ == STATE_NO_RESULTS || state_ == STATE_SOME_RESULTS); |
223 | 224 |
224 if (--num_pending_fetchers_ == 0) { | 225 if (--num_pending_fetchers_ == 0) { |
225 TransitionToDone(); | 226 TransitionToDone(); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 | 395 |
395 bool DhcpProxyScriptFetcherWin::AdapterQuery::ImplGetCandidateAdapterNames( | 396 bool DhcpProxyScriptFetcherWin::AdapterQuery::ImplGetCandidateAdapterNames( |
396 std::set<std::string>* adapter_names) { | 397 std::set<std::string>* adapter_names) { |
397 return DhcpProxyScriptFetcherWin::GetCandidateAdapterNames(adapter_names); | 398 return DhcpProxyScriptFetcherWin::GetCandidateAdapterNames(adapter_names); |
398 } | 399 } |
399 | 400 |
400 DhcpProxyScriptFetcherWin::AdapterQuery::~AdapterQuery() { | 401 DhcpProxyScriptFetcherWin::AdapterQuery::~AdapterQuery() { |
401 } | 402 } |
402 | 403 |
403 } // namespace net | 404 } // namespace net |
OLD | NEW |