| 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> |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 uint64 secret() const { return secret_; } | 203 uint64 secret() const { return secret_; } |
| 204 | 204 |
| 205 private: | 205 private: |
| 206 void CheckIn(); | 206 void CheckIn(); |
| 207 void InitializeNetworkState(); | 207 void InitializeNetworkState(); |
| 208 void BuildNetworkSession(); | 208 void BuildNetworkSession(); |
| 209 | 209 |
| 210 void LoadCallback(scoped_ptr<GCMStore::LoadResult> load_result); | 210 void LoadCallback(scoped_ptr<GCMStore::LoadResult> load_result); |
| 211 void UpdateCallback(bool success); | 211 void UpdateCallback(bool success); |
| 212 void ErrorCallback(); | 212 void ErrorCallback(); |
| 213 void OnCheckInCompleted(uint64 android_id, uint64 secret); | 213 void OnCheckInCompleted( |
| 214 const checkin_proto::AndroidCheckinResponse& checkin_response); |
| 214 void StartMCSLogin(); | 215 void StartMCSLogin(); |
| 215 | 216 |
| 216 base::DefaultClock clock_; | 217 base::DefaultClock clock_; |
| 217 | 218 |
| 218 CommandLine command_line_; | 219 CommandLine command_line_; |
| 219 | 220 |
| 220 base::FilePath gcm_store_path_; | 221 base::FilePath gcm_store_path_; |
| 221 uint64 android_id_; | 222 uint64 android_id_; |
| 222 uint64 secret_; | 223 uint64 secret_; |
| 223 std::string server_host_; | 224 std::string server_host_; |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 } | 418 } |
| 418 | 419 |
| 419 void MCSProbe::CheckIn() { | 420 void MCSProbe::CheckIn() { |
| 420 LOG(INFO) << "Check-in request initiated."; | 421 LOG(INFO) << "Check-in request initiated."; |
| 421 checkin_proto::ChromeBuildProto chrome_build_proto; | 422 checkin_proto::ChromeBuildProto chrome_build_proto; |
| 422 chrome_build_proto.set_platform( | 423 chrome_build_proto.set_platform( |
| 423 checkin_proto::ChromeBuildProto::PLATFORM_LINUX); | 424 checkin_proto::ChromeBuildProto::PLATFORM_LINUX); |
| 424 chrome_build_proto.set_channel( | 425 chrome_build_proto.set_channel( |
| 425 checkin_proto::ChromeBuildProto::CHANNEL_CANARY); | 426 checkin_proto::ChromeBuildProto::CHANNEL_CANARY); |
| 426 chrome_build_proto.set_chrome_version(kChromeVersion); | 427 chrome_build_proto.set_chrome_version(kChromeVersion); |
| 428 |
| 429 CheckinRequest::RequestInfo request_info( |
| 430 0, 0, std::string(), std::vector<std::string>(), chrome_build_proto); |
| 431 |
| 427 checkin_request_.reset(new CheckinRequest( | 432 checkin_request_.reset(new CheckinRequest( |
| 433 request_info, |
| 434 kDefaultBackoffPolicy, |
| 428 base::Bind(&MCSProbe::OnCheckInCompleted, base::Unretained(this)), | 435 base::Bind(&MCSProbe::OnCheckInCompleted, base::Unretained(this)), |
| 429 kDefaultBackoffPolicy, | |
| 430 chrome_build_proto, | |
| 431 0, | |
| 432 0, | |
| 433 std::vector<std::string>(), | |
| 434 url_request_context_getter_.get())); | 436 url_request_context_getter_.get())); |
| 435 checkin_request_->Start(); | 437 checkin_request_->Start(); |
| 436 } | 438 } |
| 437 | 439 |
| 438 void MCSProbe::OnCheckInCompleted(uint64 android_id, uint64 secret) { | 440 void MCSProbe::OnCheckInCompleted( |
| 441 const checkin_proto::AndroidCheckinResponse& checkin_response) { |
| 442 bool success = checkin_response.has_android_id() && |
| 443 checkin_response.android_id() != 0UL && |
| 444 checkin_response.has_security_token() && |
| 445 checkin_response.security_token() != 0UL; |
| 439 LOG(INFO) << "Check-in request completion " | 446 LOG(INFO) << "Check-in request completion " |
| 440 << (android_id ? "success!" : "failure!"); | 447 << (success ? "success!" : "failure!"); |
| 441 if (!android_id || !secret) | 448 |
| 449 if (!success) |
| 442 return; | 450 return; |
| 443 android_id_ = android_id; | 451 |
| 444 secret_ = secret; | 452 android_id_ = checkin_response.android_id(); |
| 453 secret_ = checkin_response.security_token(); |
| 445 | 454 |
| 446 gcm_store_->SetDeviceCredentials(android_id_, | 455 gcm_store_->SetDeviceCredentials(android_id_, |
| 447 secret_, | 456 secret_, |
| 448 base::Bind(&MCSProbe::UpdateCallback, | 457 base::Bind(&MCSProbe::UpdateCallback, |
| 449 base::Unretained(this))); | 458 base::Unretained(this))); |
| 450 | 459 |
| 451 StartMCSLogin(); | 460 StartMCSLogin(); |
| 452 } | 461 } |
| 453 | 462 |
| 454 void MCSProbe::StartMCSLogin() { | 463 void MCSProbe::StartMCSLogin() { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 482 | 491 |
| 483 return 0; | 492 return 0; |
| 484 } | 493 } |
| 485 | 494 |
| 486 } // namespace | 495 } // namespace |
| 487 } // namespace gcm | 496 } // namespace gcm |
| 488 | 497 |
| 489 int main(int argc, char* argv[]) { | 498 int main(int argc, char* argv[]) { |
| 490 return gcm::MCSProbeMain(argc, argv); | 499 return gcm::MCSProbeMain(argc, argv); |
| 491 } | 500 } |
| OLD | NEW |