| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 // A standalone tool for testing MCS connections and the MCS client on their | 5 // A standalone tool for testing MCS connections and the MCS client on their |
| 6 // own. | 6 // own. |
| 7 | 7 |
| 8 #include <cstddef> | 8 #include <cstddef> |
| 9 #include <cstdio> | 9 #include <cstdio> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/at_exit.h" | 12 #include "base/at_exit.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/message_loop/message_loop.h" | 18 #include "base/message_loop/message_loop.h" |
| 19 #include "base/run_loop.h" | 19 #include "base/run_loop.h" |
| 20 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
| 21 #include "base/threading/thread.h" | 21 #include "base/threading/thread.h" |
| 22 #include "base/threading/worker_pool.h" | 22 #include "base/threading/worker_pool.h" |
| 23 #include "base/values.h" | 23 #include "base/values.h" |
| 24 #include "google_apis/gcm/base/mcs_message.h" | 24 #include "google_apis/gcm/base/mcs_message.h" |
| 25 #include "google_apis/gcm/base/mcs_util.h" | 25 #include "google_apis/gcm/base/mcs_util.h" |
| 26 #include "google_apis/gcm/engine/connection_factory_impl.h" | 26 #include "google_apis/gcm/engine/connection_factory_impl.h" |
| 27 #include "google_apis/gcm/engine/gcm_store_impl.h" |
| 27 #include "google_apis/gcm/engine/mcs_client.h" | 28 #include "google_apis/gcm/engine/mcs_client.h" |
| 28 #include "net/base/host_mapping_rules.h" | 29 #include "net/base/host_mapping_rules.h" |
| 29 #include "net/base/net_log_logger.h" | 30 #include "net/base/net_log_logger.h" |
| 30 #include "net/cert/cert_verifier.h" | 31 #include "net/cert/cert_verifier.h" |
| 31 #include "net/dns/host_resolver.h" | 32 #include "net/dns/host_resolver.h" |
| 32 #include "net/http/http_auth_handler_factory.h" | 33 #include "net/http/http_auth_handler_factory.h" |
| 33 #include "net/http/http_network_session.h" | 34 #include "net/http/http_network_session.h" |
| 34 #include "net/http/http_server_properties_impl.h" | 35 #include "net/http/http_server_properties_impl.h" |
| 35 #include "net/http/transport_security_state.h" | 36 #include "net/http/transport_security_state.h" |
| 36 #include "net/socket/client_socket_factory.h" | 37 #include "net/socket/client_socket_factory.h" |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 private: | 167 private: |
| 167 void InitializeNetworkState(); | 168 void InitializeNetworkState(); |
| 168 void BuildNetworkSession(); | 169 void BuildNetworkSession(); |
| 169 | 170 |
| 170 void InitializationCallback(bool success, | 171 void InitializationCallback(bool success, |
| 171 uint64 restored_android_id, | 172 uint64 restored_android_id, |
| 172 uint64 restored_security_token); | 173 uint64 restored_security_token); |
| 173 | 174 |
| 174 CommandLine command_line_; | 175 CommandLine command_line_; |
| 175 | 176 |
| 176 base::FilePath rmq_path_; | 177 base::FilePath gcm_store_path_; |
| 177 uint64 android_id_; | 178 uint64 android_id_; |
| 178 uint64 secret_; | 179 uint64 secret_; |
| 179 std::string server_host_; | 180 std::string server_host_; |
| 180 int server_port_; | 181 int server_port_; |
| 181 | 182 |
| 182 // Network state. | 183 // Network state. |
| 183 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; | 184 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; |
| 184 MyTestNetLog net_log_; | 185 MyTestNetLog net_log_; |
| 185 scoped_ptr<net::NetLogLogger> logger_; | 186 scoped_ptr<net::NetLogLogger> logger_; |
| 186 scoped_ptr<base::Value> net_constants_; | 187 scoped_ptr<base::Value> net_constants_; |
| 187 scoped_ptr<net::HostResolver> host_resolver_; | 188 scoped_ptr<net::HostResolver> host_resolver_; |
| 188 scoped_ptr<net::CertVerifier> cert_verifier_; | 189 scoped_ptr<net::CertVerifier> cert_verifier_; |
| 189 scoped_ptr<net::ServerBoundCertService> system_server_bound_cert_service_; | 190 scoped_ptr<net::ServerBoundCertService> system_server_bound_cert_service_; |
| 190 scoped_ptr<net::TransportSecurityState> transport_security_state_; | 191 scoped_ptr<net::TransportSecurityState> transport_security_state_; |
| 191 scoped_ptr<net::URLSecurityManager> url_security_manager_; | 192 scoped_ptr<net::URLSecurityManager> url_security_manager_; |
| 192 scoped_ptr<net::HttpAuthHandlerFactory> http_auth_handler_factory_; | 193 scoped_ptr<net::HttpAuthHandlerFactory> http_auth_handler_factory_; |
| 193 scoped_ptr<net::HttpServerPropertiesImpl> http_server_properties_; | 194 scoped_ptr<net::HttpServerPropertiesImpl> http_server_properties_; |
| 194 scoped_ptr<net::HostMappingRules> host_mapping_rules_; | 195 scoped_ptr<net::HostMappingRules> host_mapping_rules_; |
| 195 scoped_refptr<net::HttpNetworkSession> network_session_; | 196 scoped_refptr<net::HttpNetworkSession> network_session_; |
| 196 scoped_ptr<net::ProxyService> proxy_service_; | 197 scoped_ptr<net::ProxyService> proxy_service_; |
| 197 | 198 |
| 198 scoped_ptr<RMQStore> rmq_store_; | 199 scoped_ptr<GCMStore> gcm_store_; |
| 199 scoped_ptr<MCSClient> mcs_client_; | 200 scoped_ptr<MCSClient> mcs_client_; |
| 200 | 201 |
| 201 scoped_ptr<ConnectionFactoryImpl> connection_factory_; | 202 scoped_ptr<ConnectionFactoryImpl> connection_factory_; |
| 202 | 203 |
| 203 base::Thread file_thread_; | 204 base::Thread file_thread_; |
| 204 | 205 |
| 205 scoped_ptr<base::RunLoop> run_loop_; | 206 scoped_ptr<base::RunLoop> run_loop_; |
| 206 }; | 207 }; |
| 207 | 208 |
| 208 MCSProbe::MCSProbe( | 209 MCSProbe::MCSProbe( |
| 209 const CommandLine& command_line, | 210 const CommandLine& command_line, |
| 210 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter) | 211 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter) |
| 211 : command_line_(command_line), | 212 : command_line_(command_line), |
| 212 rmq_path_(base::FilePath(FILE_PATH_LITERAL("gcm_rmq_store"))), | 213 gcm_store_path_(base::FilePath(FILE_PATH_LITERAL("gcm_store"))), |
| 213 android_id_(0), | 214 android_id_(0), |
| 214 secret_(0), | 215 secret_(0), |
| 215 server_port_(0), | 216 server_port_(0), |
| 216 url_request_context_getter_(url_request_context_getter), | 217 url_request_context_getter_(url_request_context_getter), |
| 217 file_thread_("FileThread") { | 218 file_thread_("FileThread") { |
| 218 if (command_line.HasSwitch(kRMQFileName)) { | 219 if (command_line.HasSwitch(kRMQFileName)) { |
| 219 rmq_path_ = command_line.GetSwitchValuePath(kRMQFileName); | 220 gcm_store_path_ = command_line.GetSwitchValuePath(kRMQFileName); |
| 220 } | 221 } |
| 221 if (command_line.HasSwitch(kAndroidIdSwitch)) { | 222 if (command_line.HasSwitch(kAndroidIdSwitch)) { |
| 222 base::StringToUint64(command_line.GetSwitchValueASCII(kAndroidIdSwitch), | 223 base::StringToUint64(command_line.GetSwitchValueASCII(kAndroidIdSwitch), |
| 223 &android_id_); | 224 &android_id_); |
| 224 } | 225 } |
| 225 if (command_line.HasSwitch(kSecretSwitch)) { | 226 if (command_line.HasSwitch(kSecretSwitch)) { |
| 226 base::StringToUint64(command_line.GetSwitchValueASCII(kSecretSwitch), | 227 base::StringToUint64(command_line.GetSwitchValueASCII(kSecretSwitch), |
| 227 &secret_); | 228 &secret_); |
| 228 } | 229 } |
| 229 server_host_ = kMCSServerHost; | 230 server_host_ = kMCSServerHost; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 243 | 244 |
| 244 void MCSProbe::Start() { | 245 void MCSProbe::Start() { |
| 245 file_thread_.Start(); | 246 file_thread_.Start(); |
| 246 InitializeNetworkState(); | 247 InitializeNetworkState(); |
| 247 BuildNetworkSession(); | 248 BuildNetworkSession(); |
| 248 connection_factory_.reset( | 249 connection_factory_.reset( |
| 249 new ConnectionFactoryImpl(GURL("https://" + net::HostPortPair( | 250 new ConnectionFactoryImpl(GURL("https://" + net::HostPortPair( |
| 250 server_host_, server_port_).ToString()), | 251 server_host_, server_port_).ToString()), |
| 251 network_session_, | 252 network_session_, |
| 252 &net_log_)); | 253 &net_log_)); |
| 253 rmq_store_.reset(new RMQStore(rmq_path_, file_thread_.message_loop_proxy())); | 254 gcm_store_.reset( |
| 254 mcs_client_.reset(new MCSClient(connection_factory_.get(), | 255 new GCMStoreImpl(gcm_store_path_, file_thread_.message_loop_proxy())); |
| 255 rmq_store_.get())); | 256 mcs_client_.reset(new MCSClient(connection_factory_.get(), gcm_store_.get())); |
| 256 run_loop_.reset(new base::RunLoop()); | 257 run_loop_.reset(new base::RunLoop()); |
| 257 rmq_store_->Load(base::Bind(&MCSClient::Initialize, | 258 gcm_store_->Load(base::Bind( |
| 258 base::Unretained(mcs_client_.get()), | 259 &MCSClient::Initialize, |
| 259 base::Bind(&MCSProbe::InitializationCallback, | 260 base::Unretained(mcs_client_.get()), |
| 260 base::Unretained(this)), | 261 base::Bind(&MCSProbe::InitializationCallback, base::Unretained(this)), |
| 261 base::Bind(&MessageReceivedCallback), | 262 base::Bind(&MessageReceivedCallback), |
| 262 base::Bind(&MessageSentCallback))); | 263 base::Bind(&MessageSentCallback))); |
| 263 run_loop_->Run(); | 264 run_loop_->Run(); |
| 264 } | 265 } |
| 265 | 266 |
| 266 void MCSProbe::InitializeNetworkState() { | 267 void MCSProbe::InitializeNetworkState() { |
| 267 FILE* log_file = NULL; | 268 FILE* log_file = NULL; |
| 268 if (command_line_.HasSwitch(kLogFileSwitch)) { | 269 if (command_line_.HasSwitch(kLogFileSwitch)) { |
| 269 base::FilePath log_path = command_line_.GetSwitchValuePath(kLogFileSwitch); | 270 base::FilePath log_path = command_line_.GetSwitchValuePath(kLogFileSwitch); |
| 270 #if defined(OS_WIN) | 271 #if defined(OS_WIN) |
| 271 log_file = _wfopen(log_path.value().c_str(), L"w"); | 272 log_file = _wfopen(log_path.value().c_str(), L"w"); |
| 272 #elif defined(OS_POSIX) | 273 #elif defined(OS_POSIX) |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 | 367 |
| 367 return 0; | 368 return 0; |
| 368 } | 369 } |
| 369 | 370 |
| 370 } // namespace | 371 } // namespace |
| 371 } // namespace gcm | 372 } // namespace gcm |
| 372 | 373 |
| 373 int main(int argc, char* argv[]) { | 374 int main(int argc, char* argv[]) { |
| 374 return gcm::MCSProbeMain(argc, argv); | 375 return gcm::MCSProbeMain(argc, argv); |
| 375 } | 376 } |
| OLD | NEW |