| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/init_proxy_resolver.h" | 5 #include "net/proxy/init_proxy_resolver.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/format_macros.h" | 8 #include "base/format_macros.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 int InitProxyResolver::Init(const ProxyConfig& config, | 35 int InitProxyResolver::Init(const ProxyConfig& config, |
| 36 CompletionCallback* callback, | 36 CompletionCallback* callback, |
| 37 const BoundNetLog& net_log) { | 37 const BoundNetLog& net_log) { |
| 38 DCHECK_EQ(STATE_NONE, next_state_); | 38 DCHECK_EQ(STATE_NONE, next_state_); |
| 39 DCHECK(callback); | 39 DCHECK(callback); |
| 40 DCHECK(config.MayRequirePACResolver()); | 40 DCHECK(config.MayRequirePACResolver()); |
| 41 DCHECK(!net_log_.net_log()); | 41 DCHECK(!net_log_.net_log()); |
| 42 | 42 |
| 43 net_log_ = net_log; | 43 net_log_ = net_log; |
| 44 | 44 |
| 45 net_log_.BeginEvent(NetLog::TYPE_INIT_PROXY_RESOLVER); | 45 net_log_.BeginEvent(NetLog::TYPE_INIT_PROXY_RESOLVER, NULL); |
| 46 | 46 |
| 47 pac_urls_ = BuildPacUrlsFallbackList(config); | 47 pac_urls_ = BuildPacUrlsFallbackList(config); |
| 48 DCHECK(!pac_urls_.empty()); | 48 DCHECK(!pac_urls_.empty()); |
| 49 | 49 |
| 50 next_state_ = GetStartState(); | 50 next_state_ = GetStartState(); |
| 51 | 51 |
| 52 int rv = DoLoop(OK); | 52 int rv = DoLoop(OK); |
| 53 if (rv == ERR_IO_PENDING) | 53 if (rv == ERR_IO_PENDING) |
| 54 user_callback_ = callback; | 54 user_callback_ = callback; |
| 55 else | 55 else |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 user_callback_->Run(result); | 119 user_callback_->Run(result); |
| 120 } | 120 } |
| 121 | 121 |
| 122 int InitProxyResolver::DoFetchPacScript() { | 122 int InitProxyResolver::DoFetchPacScript() { |
| 123 DCHECK(resolver_->expects_pac_bytes()); | 123 DCHECK(resolver_->expects_pac_bytes()); |
| 124 | 124 |
| 125 next_state_ = STATE_FETCH_PAC_SCRIPT_COMPLETE; | 125 next_state_ = STATE_FETCH_PAC_SCRIPT_COMPLETE; |
| 126 | 126 |
| 127 const GURL& pac_url = current_pac_url(); | 127 const GURL& pac_url = current_pac_url(); |
| 128 | 128 |
| 129 net_log_.BeginEventWithString( | 129 net_log_.BeginEvent( |
| 130 NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT, "url", pac_url.spec()); | 130 NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT, |
| 131 new NetLogStringParameter("url", pac_url.spec())); |
| 131 | 132 |
| 132 if (!proxy_script_fetcher_) { | 133 if (!proxy_script_fetcher_) { |
| 133 net_log_.AddEvent(NetLog::TYPE_INIT_PROXY_RESOLVER_HAS_NO_FETCHER); | 134 net_log_.AddEvent(NetLog::TYPE_INIT_PROXY_RESOLVER_HAS_NO_FETCHER, NULL); |
| 134 return ERR_UNEXPECTED; | 135 return ERR_UNEXPECTED; |
| 135 } | 136 } |
| 136 | 137 |
| 137 return proxy_script_fetcher_->Fetch(pac_url, &pac_bytes_, &io_callback_); | 138 return proxy_script_fetcher_->Fetch(pac_url, &pac_bytes_, &io_callback_); |
| 138 } | 139 } |
| 139 | 140 |
| 140 int InitProxyResolver::DoFetchPacScriptComplete(int result) { | 141 int InitProxyResolver::DoFetchPacScriptComplete(int result) { |
| 141 DCHECK(resolver_->expects_pac_bytes()); | 142 DCHECK(resolver_->expects_pac_bytes()); |
| 142 | 143 |
| 143 if (result == OK) { | 144 if (result == OK) { |
| 144 net_log_.EndEvent(NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT); | 145 net_log_.EndEvent(NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT, NULL); |
| 145 } else { | 146 } else { |
| 146 net_log_.EndEventWithInteger( | 147 net_log_.EndEvent( |
| 147 NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT, | 148 NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT, |
| 148 "net_error", result); | 149 new NetLogIntegerParameter("net_error", result)); |
| 149 return TryToFallbackPacUrl(result); | 150 return TryToFallbackPacUrl(result); |
| 150 } | 151 } |
| 151 | 152 |
| 152 next_state_ = STATE_SET_PAC_SCRIPT; | 153 next_state_ = STATE_SET_PAC_SCRIPT; |
| 153 return result; | 154 return result; |
| 154 } | 155 } |
| 155 | 156 |
| 156 int InitProxyResolver::DoSetPacScript() { | 157 int InitProxyResolver::DoSetPacScript() { |
| 157 net_log_.BeginEvent(NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT); | 158 net_log_.BeginEvent(NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT, NULL); |
| 158 | 159 |
| 159 const GURL& pac_url = current_pac_url(); | 160 const GURL& pac_url = current_pac_url(); |
| 160 | 161 |
| 161 next_state_ = STATE_SET_PAC_SCRIPT_COMPLETE; | 162 next_state_ = STATE_SET_PAC_SCRIPT_COMPLETE; |
| 162 | 163 |
| 163 return resolver_->expects_pac_bytes() ? | 164 return resolver_->expects_pac_bytes() ? |
| 164 resolver_->SetPacScriptByData(pac_bytes_, &io_callback_) : | 165 resolver_->SetPacScriptByData(pac_bytes_, &io_callback_) : |
| 165 resolver_->SetPacScriptByUrl(pac_url, &io_callback_); | 166 resolver_->SetPacScriptByUrl(pac_url, &io_callback_); |
| 166 } | 167 } |
| 167 | 168 |
| 168 int InitProxyResolver::DoSetPacScriptComplete(int result) { | 169 int InitProxyResolver::DoSetPacScriptComplete(int result) { |
| 169 if (result != OK) { | 170 if (result != OK) { |
| 170 net_log_.EndEventWithInteger( | 171 net_log_.EndEvent( |
| 171 NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT, | 172 NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT, |
| 172 "net_error", result); | 173 new NetLogIntegerParameter("net_error", result)); |
| 173 return TryToFallbackPacUrl(result); | 174 return TryToFallbackPacUrl(result); |
| 174 } | 175 } |
| 175 | 176 |
| 176 net_log_.EndEvent(NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT); | 177 net_log_.EndEvent(NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT, NULL); |
| 177 return result; | 178 return result; |
| 178 } | 179 } |
| 179 | 180 |
| 180 int InitProxyResolver::TryToFallbackPacUrl(int error) { | 181 int InitProxyResolver::TryToFallbackPacUrl(int error) { |
| 181 DCHECK_LT(error, 0); | 182 DCHECK_LT(error, 0); |
| 182 | 183 |
| 183 if (current_pac_url_index_ + 1 >= pac_urls_.size()) { | 184 if (current_pac_url_index_ + 1 >= pac_urls_.size()) { |
| 184 // Nothing left to fall back to. | 185 // Nothing left to fall back to. |
| 185 return error; | 186 return error; |
| 186 } | 187 } |
| 187 | 188 |
| 188 // Advance to next URL in our list. | 189 // Advance to next URL in our list. |
| 189 ++current_pac_url_index_; | 190 ++current_pac_url_index_; |
| 190 | 191 |
| 191 net_log_.AddEvent( | 192 net_log_.AddEvent( |
| 192 NetLog::TYPE_INIT_PROXY_RESOLVER_FALLING_BACK_TO_NEXT_PAC_URL); | 193 NetLog::TYPE_INIT_PROXY_RESOLVER_FALLING_BACK_TO_NEXT_PAC_URL, NULL); |
| 193 | 194 |
| 194 next_state_ = GetStartState(); | 195 next_state_ = GetStartState(); |
| 195 | 196 |
| 196 return OK; | 197 return OK; |
| 197 } | 198 } |
| 198 | 199 |
| 199 InitProxyResolver::State InitProxyResolver::GetStartState() const { | 200 InitProxyResolver::State InitProxyResolver::GetStartState() const { |
| 200 return resolver_->expects_pac_bytes() ? | 201 return resolver_->expects_pac_bytes() ? |
| 201 STATE_FETCH_PAC_SCRIPT : STATE_SET_PAC_SCRIPT; | 202 STATE_FETCH_PAC_SCRIPT : STATE_SET_PAC_SCRIPT; |
| 202 } | 203 } |
| 203 | 204 |
| 204 const GURL& InitProxyResolver::current_pac_url() const { | 205 const GURL& InitProxyResolver::current_pac_url() const { |
| 205 DCHECK_LT(current_pac_url_index_, pac_urls_.size()); | 206 DCHECK_LT(current_pac_url_index_, pac_urls_.size()); |
| 206 return pac_urls_[current_pac_url_index_]; | 207 return pac_urls_[current_pac_url_index_]; |
| 207 } | 208 } |
| 208 | 209 |
| 209 void InitProxyResolver::DidCompleteInit() { | 210 void InitProxyResolver::DidCompleteInit() { |
| 210 net_log_.EndEvent(NetLog::TYPE_INIT_PROXY_RESOLVER); | 211 net_log_.EndEvent(NetLog::TYPE_INIT_PROXY_RESOLVER, NULL); |
| 211 } | 212 } |
| 212 | 213 |
| 213 void InitProxyResolver::Cancel() { | 214 void InitProxyResolver::Cancel() { |
| 214 DCHECK_NE(STATE_NONE, next_state_); | 215 DCHECK_NE(STATE_NONE, next_state_); |
| 215 | 216 |
| 216 net_log_.AddEvent(NetLog::TYPE_CANCELLED); | 217 net_log_.AddEvent(NetLog::TYPE_CANCELLED, NULL); |
| 217 | 218 |
| 218 switch (next_state_) { | 219 switch (next_state_) { |
| 219 case STATE_FETCH_PAC_SCRIPT_COMPLETE: | 220 case STATE_FETCH_PAC_SCRIPT_COMPLETE: |
| 220 proxy_script_fetcher_->Cancel(); | 221 proxy_script_fetcher_->Cancel(); |
| 221 break; | 222 break; |
| 222 case STATE_SET_PAC_SCRIPT_COMPLETE: | 223 case STATE_SET_PAC_SCRIPT_COMPLETE: |
| 223 resolver_->CancelSetPacScript(); | 224 resolver_->CancelSetPacScript(); |
| 224 break; | 225 break; |
| 225 default: | 226 default: |
| 226 NOTREACHED(); | 227 NOTREACHED(); |
| 227 break; | 228 break; |
| 228 } | 229 } |
| 229 | 230 |
| 230 DidCompleteInit(); | 231 DidCompleteInit(); |
| 231 } | 232 } |
| 232 | 233 |
| 233 } // namespace net | 234 } // namespace net |
| OLD | NEW |