| 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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 | 115 |
| 116 void InitProxyResolver::DoCallback(int result) { | 116 void InitProxyResolver::DoCallback(int result) { |
| 117 DCHECK_NE(ERR_IO_PENDING, result); | 117 DCHECK_NE(ERR_IO_PENDING, result); |
| 118 DCHECK(user_callback_); | 118 DCHECK(user_callback_); |
| 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 net_log_.BeginEvent(NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT); | |
| 126 | |
| 127 next_state_ = STATE_FETCH_PAC_SCRIPT_COMPLETE; | 125 next_state_ = STATE_FETCH_PAC_SCRIPT_COMPLETE; |
| 128 | 126 |
| 129 const GURL& pac_url = current_pac_url(); | 127 const GURL& pac_url = current_pac_url(); |
| 130 | 128 |
| 131 net_log_.AddString(pac_url.spec()); | 129 net_log_.BeginEventWithString( |
| 130 NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT, "url", pac_url.spec()); |
| 132 | 131 |
| 133 if (!proxy_script_fetcher_) { | 132 if (!proxy_script_fetcher_) { |
| 134 net_log_.AddStringLiteral( | 133 net_log_.AddEvent(NetLog::TYPE_INIT_PROXY_RESOLVER_HAS_NO_FETCHER); |
| 135 "Can't download PAC script, because no fetcher was specified"); | |
| 136 return ERR_UNEXPECTED; | 134 return ERR_UNEXPECTED; |
| 137 } | 135 } |
| 138 | 136 |
| 139 return proxy_script_fetcher_->Fetch(pac_url, &pac_bytes_, &io_callback_); | 137 return proxy_script_fetcher_->Fetch(pac_url, &pac_bytes_, &io_callback_); |
| 140 } | 138 } |
| 141 | 139 |
| 142 int InitProxyResolver::DoFetchPacScriptComplete(int result) { | 140 int InitProxyResolver::DoFetchPacScriptComplete(int result) { |
| 143 DCHECK(resolver_->expects_pac_bytes()); | 141 DCHECK(resolver_->expects_pac_bytes()); |
| 144 | 142 |
| 145 net_log_.AddString(StringPrintf( | 143 if (result == OK) { |
| 146 "Completed fetch with result %s. Received %" PRIuS " bytes", | 144 net_log_.EndEvent(NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT); |
| 147 ErrorToString(result), | 145 } else { |
| 148 pac_bytes_.size())); | 146 net_log_.EndEventWithInteger( |
| 149 | 147 NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT, |
| 150 net_log_.EndEvent(NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT); | 148 "net_error", result); |
| 151 | |
| 152 if (result != OK) | |
| 153 return TryToFallbackPacUrl(result); | 149 return TryToFallbackPacUrl(result); |
| 150 } |
| 154 | 151 |
| 155 next_state_ = STATE_SET_PAC_SCRIPT; | 152 next_state_ = STATE_SET_PAC_SCRIPT; |
| 156 return result; | 153 return result; |
| 157 } | 154 } |
| 158 | 155 |
| 159 int InitProxyResolver::DoSetPacScript() { | 156 int InitProxyResolver::DoSetPacScript() { |
| 160 net_log_.BeginEvent(NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT); | 157 net_log_.BeginEvent(NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT); |
| 161 | 158 |
| 162 const GURL& pac_url = current_pac_url(); | 159 const GURL& pac_url = current_pac_url(); |
| 163 | 160 |
| 164 next_state_ = STATE_SET_PAC_SCRIPT_COMPLETE; | 161 next_state_ = STATE_SET_PAC_SCRIPT_COMPLETE; |
| 165 | 162 |
| 166 return resolver_->expects_pac_bytes() ? | 163 return resolver_->expects_pac_bytes() ? |
| 167 resolver_->SetPacScriptByData(pac_bytes_, &io_callback_) : | 164 resolver_->SetPacScriptByData(pac_bytes_, &io_callback_) : |
| 168 resolver_->SetPacScriptByUrl(pac_url, &io_callback_); | 165 resolver_->SetPacScriptByUrl(pac_url, &io_callback_); |
| 169 } | 166 } |
| 170 | 167 |
| 171 int InitProxyResolver::DoSetPacScriptComplete(int result) { | 168 int InitProxyResolver::DoSetPacScriptComplete(int result) { |
| 172 if (result != OK) { | 169 if (result != OK) { |
| 173 net_log_.AddString( | 170 net_log_.EndEventWithInteger( |
| 174 StringPrintf("Failed initializing the PAC script with error: %s", | 171 NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT, |
| 175 ErrorToString(result))); | 172 "net_error", result); |
| 176 net_log_.EndEvent(NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT); | |
| 177 return TryToFallbackPacUrl(result); | 173 return TryToFallbackPacUrl(result); |
| 178 } | 174 } |
| 179 | 175 |
| 180 net_log_.AddStringLiteral("Successfully initialized PAC script."); | |
| 181 | |
| 182 net_log_.EndEvent(NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT); | 176 net_log_.EndEvent(NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT); |
| 183 return result; | 177 return result; |
| 184 } | 178 } |
| 185 | 179 |
| 186 int InitProxyResolver::TryToFallbackPacUrl(int error) { | 180 int InitProxyResolver::TryToFallbackPacUrl(int error) { |
| 187 DCHECK_LT(error, 0); | 181 DCHECK_LT(error, 0); |
| 188 | 182 |
| 189 if (current_pac_url_index_ + 1 >= pac_urls_.size()) { | 183 if (current_pac_url_index_ + 1 >= pac_urls_.size()) { |
| 190 // Nothing left to fall back to. | 184 // Nothing left to fall back to. |
| 191 return error; | 185 return error; |
| 192 } | 186 } |
| 193 | 187 |
| 194 // Advance to next URL in our list. | 188 // Advance to next URL in our list. |
| 195 ++current_pac_url_index_; | 189 ++current_pac_url_index_; |
| 196 | 190 |
| 197 net_log_.AddStringLiteral("Falling back to next PAC URL..."); | 191 net_log_.AddEvent( |
| 192 NetLog::TYPE_INIT_PROXY_RESOLVER_FALLING_BACK_TO_NEXT_PAC_URL); |
| 198 | 193 |
| 199 next_state_ = GetStartState(); | 194 next_state_ = GetStartState(); |
| 200 | 195 |
| 201 return OK; | 196 return OK; |
| 202 } | 197 } |
| 203 | 198 |
| 204 InitProxyResolver::State InitProxyResolver::GetStartState() const { | 199 InitProxyResolver::State InitProxyResolver::GetStartState() const { |
| 205 return resolver_->expects_pac_bytes() ? | 200 return resolver_->expects_pac_bytes() ? |
| 206 STATE_FETCH_PAC_SCRIPT : STATE_SET_PAC_SCRIPT; | 201 STATE_FETCH_PAC_SCRIPT : STATE_SET_PAC_SCRIPT; |
| 207 } | 202 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 229 break; | 224 break; |
| 230 default: | 225 default: |
| 231 NOTREACHED(); | 226 NOTREACHED(); |
| 232 break; | 227 break; |
| 233 } | 228 } |
| 234 | 229 |
| 235 DidCompleteInit(); | 230 DidCompleteInit(); |
| 236 } | 231 } |
| 237 | 232 |
| 238 } // namespace net | 233 } // namespace net |
| OLD | NEW |