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