Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(708)

Side by Side Diff: google_apis/gcm/tools/mcs_probe.cc

Issue 132193003: [GCM] Support actual check-in in mcs_probe (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comment Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « google_apis/gcm/engine/connection_factory_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/time/default_clock.h" 23 #include "base/time/default_clock.h"
24 #include "base/values.h" 24 #include "base/values.h"
25 #include "google_apis/gcm/base/mcs_message.h" 25 #include "google_apis/gcm/base/mcs_message.h"
26 #include "google_apis/gcm/base/mcs_util.h" 26 #include "google_apis/gcm/base/mcs_util.h"
27 #include "google_apis/gcm/engine/checkin_request.h"
27 #include "google_apis/gcm/engine/connection_factory_impl.h" 28 #include "google_apis/gcm/engine/connection_factory_impl.h"
28 #include "google_apis/gcm/engine/gcm_store_impl.h" 29 #include "google_apis/gcm/engine/gcm_store_impl.h"
29 #include "google_apis/gcm/engine/mcs_client.h" 30 #include "google_apis/gcm/engine/mcs_client.h"
30 #include "net/base/host_mapping_rules.h" 31 #include "net/base/host_mapping_rules.h"
31 #include "net/base/net_log_logger.h" 32 #include "net/base/net_log_logger.h"
32 #include "net/cert/cert_verifier.h" 33 #include "net/cert/cert_verifier.h"
33 #include "net/dns/host_resolver.h" 34 #include "net/dns/host_resolver.h"
34 #include "net/http/http_auth_handler_factory.h" 35 #include "net/http/http_auth_handler_factory.h"
35 #include "net/http/http_network_session.h" 36 #include "net/http/http_network_session.h"
36 #include "net/http/http_server_properties_impl.h" 37 #include "net/http/http_server_properties_impl.h"
37 #include "net/http/transport_security_state.h" 38 #include "net/http/transport_security_state.h"
38 #include "net/socket/client_socket_factory.h" 39 #include "net/socket/client_socket_factory.h"
39 #include "net/socket/ssl_client_socket.h" 40 #include "net/socket/ssl_client_socket.h"
40 #include "net/ssl/default_server_bound_cert_store.h" 41 #include "net/ssl/default_server_bound_cert_store.h"
41 #include "net/ssl/server_bound_cert_service.h" 42 #include "net/ssl/server_bound_cert_service.h"
42 #include "net/url_request/url_request_test_util.h" 43 #include "net/url_request/url_request_test_util.h"
43 44
44 #if defined(OS_MACOSX) 45 #if defined(OS_MACOSX)
45 #include "base/mac/scoped_nsautorelease_pool.h" 46 #include "base/mac/scoped_nsautorelease_pool.h"
46 #endif 47 #endif
47 48
48 // This is a simple utility that initializes an mcs client and 49 // This is a simple utility that initializes an mcs client and
49 // prints out any events. 50 // prints out any events.
50 namespace gcm { 51 namespace gcm {
51 namespace { 52 namespace {
52 53
54 // Default values used to communicate with the check-in server.
55 const char kChromeVersion[] = "Chrome MCS Probe";
56 const int64 kUserSerialNumber = 1;
57
53 // The default server to communicate with. 58 // The default server to communicate with.
54 const char kMCSServerHost[] = "mtalk.google.com"; 59 const char kMCSServerHost[] = "mtalk.google.com";
55 const uint16 kMCSServerPort = 5228; 60 const uint16 kMCSServerPort = 5228;
56 61
57 // Command line switches. 62 // Command line switches.
58 const char kRMQFileName[] = "rmq_file"; 63 const char kRMQFileName[] = "rmq_file";
59 const char kAndroidIdSwitch[] = "android_id"; 64 const char kAndroidIdSwitch[] = "android_id";
60 const char kSecretSwitch[] = "secret"; 65 const char kSecretSwitch[] = "secret";
61 const char kLogFileSwitch[] = "log-file"; 66 const char kLogFileSwitch[] = "log-file";
62 const char kIgnoreCertSwitch[] = "ignore-certs"; 67 const char kIgnoreCertSwitch[] = "ignore-certs";
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 const CommandLine& command_line, 164 const CommandLine& command_line,
160 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter); 165 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter);
161 ~MCSProbe(); 166 ~MCSProbe();
162 167
163 void Start(); 168 void Start();
164 169
165 uint64 android_id() const { return android_id_; } 170 uint64 android_id() const { return android_id_; }
166 uint64 secret() const { return secret_; } 171 uint64 secret() const { return secret_; }
167 172
168 private: 173 private:
174 void CheckIn();
169 void InitializeNetworkState(); 175 void InitializeNetworkState();
170 void BuildNetworkSession(); 176 void BuildNetworkSession();
171 177
172 void InitializationCallback(bool success, 178 void InitializationCallback(bool success,
173 uint64 restored_android_id, 179 uint64 restored_android_id,
174 uint64 restored_security_token); 180 uint64 restored_security_token);
181 void OnCheckInCompleted(uint64 android_id, uint64 secret);
175 182
176 base::DefaultClock clock_; 183 base::DefaultClock clock_;
177 184
178 CommandLine command_line_; 185 CommandLine command_line_;
179 186
180 base::FilePath gcm_store_path_; 187 base::FilePath gcm_store_path_;
181 uint64 android_id_; 188 uint64 android_id_;
182 uint64 secret_; 189 uint64 secret_;
183 std::string server_host_; 190 std::string server_host_;
184 int server_port_; 191 int server_port_;
185 192
186 // Network state. 193 // Network state.
187 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; 194 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
188 MyTestNetLog net_log_; 195 MyTestNetLog net_log_;
189 scoped_ptr<net::NetLogLogger> logger_; 196 scoped_ptr<net::NetLogLogger> logger_;
190 scoped_ptr<base::Value> net_constants_; 197 scoped_ptr<base::Value> net_constants_;
191 scoped_ptr<net::HostResolver> host_resolver_; 198 scoped_ptr<net::HostResolver> host_resolver_;
192 scoped_ptr<net::CertVerifier> cert_verifier_; 199 scoped_ptr<net::CertVerifier> cert_verifier_;
193 scoped_ptr<net::ServerBoundCertService> system_server_bound_cert_service_; 200 scoped_ptr<net::ServerBoundCertService> system_server_bound_cert_service_;
194 scoped_ptr<net::TransportSecurityState> transport_security_state_; 201 scoped_ptr<net::TransportSecurityState> transport_security_state_;
195 scoped_ptr<net::URLSecurityManager> url_security_manager_; 202 scoped_ptr<net::URLSecurityManager> url_security_manager_;
196 scoped_ptr<net::HttpAuthHandlerFactory> http_auth_handler_factory_; 203 scoped_ptr<net::HttpAuthHandlerFactory> http_auth_handler_factory_;
197 scoped_ptr<net::HttpServerPropertiesImpl> http_server_properties_; 204 scoped_ptr<net::HttpServerPropertiesImpl> http_server_properties_;
198 scoped_ptr<net::HostMappingRules> host_mapping_rules_; 205 scoped_ptr<net::HostMappingRules> host_mapping_rules_;
199 scoped_refptr<net::HttpNetworkSession> network_session_; 206 scoped_refptr<net::HttpNetworkSession> network_session_;
200 scoped_ptr<net::ProxyService> proxy_service_; 207 scoped_ptr<net::ProxyService> proxy_service_;
201 208
202 scoped_ptr<GCMStore> gcm_store_; 209 scoped_ptr<GCMStore> gcm_store_;
203 scoped_ptr<MCSClient> mcs_client_; 210 scoped_ptr<MCSClient> mcs_client_;
211 scoped_ptr<CheckinRequest> checkin_request_;
204 212
205 scoped_ptr<ConnectionFactoryImpl> connection_factory_; 213 scoped_ptr<ConnectionFactoryImpl> connection_factory_;
206 214
207 base::Thread file_thread_; 215 base::Thread file_thread_;
208 216
209 scoped_ptr<base::RunLoop> run_loop_; 217 scoped_ptr<base::RunLoop> run_loop_;
210 }; 218 };
211 219
212 MCSProbe::MCSProbe( 220 MCSProbe::MCSProbe(
213 const CommandLine& command_line, 221 const CommandLine& command_line,
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 session_params.proxy_service = proxy_service_.get(); 341 session_params.proxy_service = proxy_service_.get();
334 342
335 network_session_ = new net::HttpNetworkSession(session_params); 343 network_session_ = new net::HttpNetworkSession(session_params);
336 } 344 }
337 345
338 void MCSProbe::InitializationCallback(bool success, 346 void MCSProbe::InitializationCallback(bool success,
339 uint64 restored_android_id, 347 uint64 restored_android_id,
340 uint64 restored_security_token) { 348 uint64 restored_security_token) {
341 LOG(INFO) << "Initialization " << (success ? "success!" : "failure!"); 349 LOG(INFO) << "Initialization " << (success ? "success!" : "failure!");
342 if (restored_android_id && restored_security_token) { 350 if (restored_android_id && restored_security_token) {
351 LOG(INFO) << "Restored device check-in info.";
343 android_id_ = restored_android_id; 352 android_id_ = restored_android_id;
344 secret_ = restored_security_token; 353 secret_ = restored_security_token;
345 } 354 }
346 if (success) 355 if (!success)
347 mcs_client_->Login(android_id_, secret_); 356 return;
357
358 if (!android_id_ || !secret_) {
359 CheckIn();
360 return;
361 }
362
363 LOG(INFO) << "MCS login initiated.";
364 mcs_client_->Login(android_id_, secret_);
365 }
366
367 void MCSProbe::CheckIn() {
368 LOG(INFO) << "Check-in request initiated.";
369 checkin_proto::ChromeBuildProto chrome_build_proto;
370 chrome_build_proto.set_platform(
371 checkin_proto::ChromeBuildProto::PLATFORM_LINUX);
372 chrome_build_proto.set_channel(
373 checkin_proto::ChromeBuildProto::CHANNEL_CANARY);
374 chrome_build_proto.set_chrome_version(kChromeVersion);
375 checkin_request_.reset(new CheckinRequest(
376 base::Bind(&MCSProbe::OnCheckInCompleted, base::Unretained(this)),
377 chrome_build_proto,
378 kUserSerialNumber,
379 0,
380 0,
381 url_request_context_getter_.get()));
382 checkin_request_->Start();
383 }
384
385 void MCSProbe::OnCheckInCompleted(uint64 android_id, uint64 secret) {
386 LOG(INFO) << "Check-in request completion "
387 << (android_id ? "success!" : "failure!");
388 if (!android_id || !secret)
389 return;
390 android_id_ = android_id;
391 secret_ = secret;
392
393 LOG(INFO) << "MCS login initiated.";
394 mcs_client_->Login(android_id_, secret_);
348 } 395 }
349 396
350 int MCSProbeMain(int argc, char* argv[]) { 397 int MCSProbeMain(int argc, char* argv[]) {
351 base::AtExitManager exit_manager; 398 base::AtExitManager exit_manager;
352 399
353 CommandLine::Init(argc, argv); 400 CommandLine::Init(argc, argv);
354 logging::LoggingSettings settings; 401 logging::LoggingSettings settings;
355 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; 402 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
356 logging::InitLogging(settings); 403 logging::InitLogging(settings);
357 404
(...skipping 14 matching lines...) Expand all
372 419
373 return 0; 420 return 0;
374 } 421 }
375 422
376 } // namespace 423 } // namespace
377 } // namespace gcm 424 } // namespace gcm
378 425
379 int main(int argc, char* argv[]) { 426 int main(int argc, char* argv[]) {
380 return gcm::MCSProbeMain(argc, argv); 427 return gcm::MCSProbeMain(argc, argv);
381 } 428 }
OLDNEW
« no previous file with comments | « google_apis/gcm/engine/connection_factory_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698