| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/net/websocket_experiment/websocket_experiment_runner.h" | 5 #include "chrome/browser/net/websocket_experiment/websocket_experiment_runner.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
| 11 #include "base/stringprintf.h" |
| 11 #include "base/task.h" | 12 #include "base/task.h" |
| 12 #include "base/string_util.h" | |
| 13 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
| 14 #include "content/browser/browser_thread.h" | 14 #include "content/browser/browser_thread.h" |
| 15 #include "net/base/host_resolver.h" | 15 #include "net/base/host_resolver.h" |
| 16 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
| 17 #include "net/websockets/websocket.h" | 17 #include "net/websockets/websocket.h" |
| 18 | 18 |
| 19 namespace chrome_browser_net_websocket_experiment { | 19 namespace chrome_browser_net_websocket_experiment { |
| 20 | 20 |
| 21 static const char *kExperimentHost = "websocket-experiment.chromium.org"; | 21 static const char *kExperimentHost = "websocket-experiment.chromium.org"; |
| 22 static const int kAlternativePort = 61985; | 22 static const int kAlternativePort = 61985; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 } | 105 } |
| 106 #endif | 106 #endif |
| 107 | 107 |
| 108 WebSocketExperimentTask::Config* config; | 108 WebSocketExperimentTask::Config* config; |
| 109 WebSocketExperimentTask::Config task_config; | 109 WebSocketExperimentTask::Config task_config; |
| 110 | 110 |
| 111 task_config.protocol_version = net::WebSocket::DEFAULT_VERSION; | 111 task_config.protocol_version = net::WebSocket::DEFAULT_VERSION; |
| 112 config = &config_.ws_config[STATE_RUN_WS - STATE_RUN_WS]; | 112 config = &config_.ws_config[STATE_RUN_WS - STATE_RUN_WS]; |
| 113 *config = task_config; | 113 *config = task_config; |
| 114 config->url = | 114 config->url = |
| 115 GURL(StringPrintf("ws://%s/live_exp", experiment_host.c_str())); | 115 GURL(base::StringPrintf("ws://%s/live_exp", experiment_host.c_str())); |
| 116 config->ws_location = | 116 config->ws_location = |
| 117 StringPrintf("ws://%s/live_exp", experiment_host.c_str()); | 117 base::StringPrintf("ws://%s/live_exp", experiment_host.c_str()); |
| 118 config->http_url = | 118 config->http_url = |
| 119 GURL(StringPrintf("http://%s/", experiment_host.c_str())); | 119 GURL(base::StringPrintf("http://%s/", experiment_host.c_str())); |
| 120 | 120 |
| 121 config = &config_.ws_config[STATE_RUN_WSS - STATE_RUN_WS]; | 121 config = &config_.ws_config[STATE_RUN_WSS - STATE_RUN_WS]; |
| 122 *config = task_config; | 122 *config = task_config; |
| 123 config->url = | 123 config->url = |
| 124 GURL(StringPrintf("wss://%s/live_exp", experiment_host.c_str())); | 124 GURL(base::StringPrintf("wss://%s/live_exp", experiment_host.c_str())); |
| 125 config->ws_location = | 125 config->ws_location = |
| 126 StringPrintf("wss://%s/live_exp", experiment_host.c_str()); | 126 base::StringPrintf("wss://%s/live_exp", experiment_host.c_str()); |
| 127 config->http_url = | 127 config->http_url = |
| 128 GURL(StringPrintf("https://%s/", experiment_host.c_str())); | 128 GURL(base::StringPrintf("https://%s/", experiment_host.c_str())); |
| 129 | 129 |
| 130 config = &config_.ws_config[STATE_RUN_WS_NODEFAULT_PORT - | 130 config = &config_.ws_config[STATE_RUN_WS_NODEFAULT_PORT - |
| 131 STATE_RUN_WS]; | 131 STATE_RUN_WS]; |
| 132 *config = task_config; | 132 *config = task_config; |
| 133 config->url = | 133 config->url = |
| 134 GURL(StringPrintf("ws://%s:%d/live_exp", | 134 GURL(base::StringPrintf("ws://%s:%d/live_exp", |
| 135 experiment_host.c_str(), kAlternativePort)); | 135 experiment_host.c_str(), kAlternativePort)); |
| 136 config->ws_location = | 136 config->ws_location = |
| 137 StringPrintf("ws://%s:%d/live_exp", | 137 base::StringPrintf("ws://%s:%d/live_exp", |
| 138 experiment_host.c_str(), kAlternativePort); | 138 experiment_host.c_str(), kAlternativePort); |
| 139 config->http_url = | 139 config->http_url = |
| 140 GURL(StringPrintf("http://%s:%d/", | 140 GURL(base::StringPrintf("http://%s:%d/", |
| 141 experiment_host.c_str(), kAlternativePort)); | 141 experiment_host.c_str(), kAlternativePort)); |
| 142 | 142 |
| 143 task_config.protocol_version = net::WebSocket::DRAFT75; | 143 task_config.protocol_version = net::WebSocket::DRAFT75; |
| 144 config = &config_.ws_config[STATE_RUN_WS_DRAFT75 - STATE_RUN_WS]; | 144 config = &config_.ws_config[STATE_RUN_WS_DRAFT75 - STATE_RUN_WS]; |
| 145 *config = task_config; | 145 *config = task_config; |
| 146 config->url = | 146 config->url = |
| 147 GURL(StringPrintf("ws://%s/live_exp", experiment_host.c_str())); | 147 GURL(base::StringPrintf("ws://%s/live_exp", experiment_host.c_str())); |
| 148 config->ws_location = | 148 config->ws_location = |
| 149 StringPrintf("ws://%s/live_exp", experiment_host.c_str()); | 149 base::StringPrintf("ws://%s/live_exp", experiment_host.c_str()); |
| 150 config->http_url = | 150 config->http_url = |
| 151 GURL(StringPrintf("http://%s/", experiment_host.c_str())); | 151 GURL(base::StringPrintf("http://%s/", experiment_host.c_str())); |
| 152 | 152 |
| 153 config = &config_.ws_config[STATE_RUN_WSS_DRAFT75 - STATE_RUN_WS]; | 153 config = &config_.ws_config[STATE_RUN_WSS_DRAFT75 - STATE_RUN_WS]; |
| 154 *config = task_config; | 154 *config = task_config; |
| 155 config->url = | 155 config->url = |
| 156 GURL(StringPrintf("wss://%s/live_exp", experiment_host.c_str())); | 156 GURL(base::StringPrintf("wss://%s/live_exp", experiment_host.c_str())); |
| 157 config->ws_location = | 157 config->ws_location = |
| 158 StringPrintf("wss://%s/live_exp", experiment_host.c_str()); | 158 base::StringPrintf("wss://%s/live_exp", experiment_host.c_str()); |
| 159 config->http_url = | 159 config->http_url = |
| 160 GURL(StringPrintf("https://%s/", experiment_host.c_str())); | 160 GURL(base::StringPrintf("https://%s/", experiment_host.c_str())); |
| 161 | 161 |
| 162 config = &config_.ws_config[STATE_RUN_WS_NODEFAULT_PORT_DRAFT75 - | 162 config = &config_.ws_config[STATE_RUN_WS_NODEFAULT_PORT_DRAFT75 - |
| 163 STATE_RUN_WS]; | 163 STATE_RUN_WS]; |
| 164 *config = task_config; | 164 *config = task_config; |
| 165 config->url = | 165 config->url = |
| 166 GURL(StringPrintf("ws://%s:%d/live_exp", | 166 GURL(base::StringPrintf("ws://%s:%d/live_exp", |
| 167 experiment_host.c_str(), kAlternativePort)); | 167 experiment_host.c_str(), kAlternativePort)); |
| 168 config->ws_location = | 168 config->ws_location = |
| 169 StringPrintf("ws://%s:%d/live_exp", | 169 base::StringPrintf("ws://%s:%d/live_exp", |
| 170 experiment_host.c_str(), kAlternativePort); | 170 experiment_host.c_str(), kAlternativePort); |
| 171 config->http_url = | 171 config->http_url = |
| 172 GURL(StringPrintf("http://%s:%d/", | 172 GURL(base::StringPrintf("http://%s:%d/", |
| 173 experiment_host.c_str(), kAlternativePort)); | 173 experiment_host.c_str(), kAlternativePort)); |
| 174 | 174 |
| 175 } | 175 } |
| 176 | 176 |
| 177 void WebSocketExperimentRunner::DoLoop() { | 177 void WebSocketExperimentRunner::DoLoop() { |
| 178 if (next_state_ == STATE_NONE) { | 178 if (next_state_ == STATE_NONE) { |
| 179 if (task_.get()) { | 179 if (task_.get()) { |
| 180 AddRef(); // Release in OnTaskCompleted after Cancelled. | 180 AddRef(); // Release in OnTaskCompleted after Cancelled. |
| 181 task_->Cancel(); | 181 task_->Cancel(); |
| 182 } | 182 } |
| 183 return; | 183 return; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 Release(); | 227 Release(); |
| 228 return; | 228 return; |
| 229 } | 229 } |
| 230 task_->SaveResult(); | 230 task_->SaveResult(); |
| 231 task_.reset(); | 231 task_.reset(); |
| 232 | 232 |
| 233 DoLoop(); | 233 DoLoop(); |
| 234 } | 234 } |
| 235 | 235 |
| 236 } // namespace chrome_browser_net_websocket_experiment | 236 } // namespace chrome_browser_net_websocket_experiment |
| OLD | NEW |