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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 | 175 |
176 uint64 android_id() const { return android_id_; } | 176 uint64 android_id() const { return android_id_; } |
177 uint64 secret() const { return secret_; } | 177 uint64 secret() const { return secret_; } |
178 | 178 |
179 private: | 179 private: |
180 void CheckIn(); | 180 void CheckIn(); |
181 void InitializeNetworkState(); | 181 void InitializeNetworkState(); |
182 void BuildNetworkSession(); | 182 void BuildNetworkSession(); |
183 | 183 |
184 void LoadCallback(scoped_ptr<GCMStore::LoadResult> load_result); | 184 void LoadCallback(scoped_ptr<GCMStore::LoadResult> load_result); |
| 185 void UpdateCallback(bool success); |
185 void ErrorCallback(); | 186 void ErrorCallback(); |
186 void OnCheckInCompleted(uint64 android_id, uint64 secret); | 187 void OnCheckInCompleted(uint64 android_id, uint64 secret); |
187 | 188 |
188 base::DefaultClock clock_; | 189 base::DefaultClock clock_; |
189 | 190 |
190 CommandLine command_line_; | 191 CommandLine command_line_; |
191 | 192 |
192 base::FilePath gcm_store_path_; | 193 base::FilePath gcm_store_path_; |
193 uint64 android_id_; | 194 uint64 android_id_; |
194 uint64 secret_; | 195 uint64 secret_; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 connection_factory_.get(), | 276 connection_factory_.get(), |
276 gcm_store_.get())); | 277 gcm_store_.get())); |
277 run_loop_.reset(new base::RunLoop()); | 278 run_loop_.reset(new base::RunLoop()); |
278 gcm_store_->Load(base::Bind(&MCSProbe::LoadCallback, | 279 gcm_store_->Load(base::Bind(&MCSProbe::LoadCallback, |
279 base::Unretained(this))); | 280 base::Unretained(this))); |
280 run_loop_->Run(); | 281 run_loop_->Run(); |
281 } | 282 } |
282 | 283 |
283 void MCSProbe::LoadCallback(scoped_ptr<GCMStore::LoadResult> load_result) { | 284 void MCSProbe::LoadCallback(scoped_ptr<GCMStore::LoadResult> load_result) { |
284 DCHECK(load_result->success); | 285 DCHECK(load_result->success); |
285 android_id_ = load_result->device_android_id; | 286 if (android_id_ != 0 && secret_ != 0) { |
286 secret_ = load_result->device_security_token; | 287 DVLOG(1) << "Presetting MCS id " << android_id_; |
| 288 load_result->device_android_id = android_id_; |
| 289 load_result->device_security_token = secret_; |
| 290 gcm_store_->SetDeviceCredentials(android_id_, |
| 291 secret_, |
| 292 base::Bind(&MCSProbe::UpdateCallback, |
| 293 base::Unretained(this))); |
| 294 } else { |
| 295 android_id_ = load_result->device_android_id; |
| 296 secret_ = load_result->device_security_token; |
| 297 DVLOG(1) << "Loaded MCS id " << android_id_; |
| 298 } |
287 mcs_client_->Initialize( | 299 mcs_client_->Initialize( |
288 base::Bind(&MCSProbe::ErrorCallback, base::Unretained(this)), | 300 base::Bind(&MCSProbe::ErrorCallback, base::Unretained(this)), |
289 base::Bind(&MessageReceivedCallback), | 301 base::Bind(&MessageReceivedCallback), |
290 base::Bind(&MessageSentCallback), | 302 base::Bind(&MessageSentCallback), |
291 load_result.Pass()); | 303 load_result.Pass()); |
292 | 304 |
293 if (!android_id_ || !secret_) { | 305 if (!android_id_ || !secret_) { |
| 306 DVLOG(1) << "Checkin to generate new MCS credentials."; |
294 CheckIn(); | 307 CheckIn(); |
295 return; | 308 return; |
296 } | 309 } |
297 | 310 |
298 mcs_client_->Login(android_id_, secret_); | 311 mcs_client_->Login(android_id_, secret_); |
299 } | 312 } |
300 | 313 |
| 314 void MCSProbe::UpdateCallback(bool success) { |
| 315 } |
| 316 |
301 void MCSProbe::InitializeNetworkState() { | 317 void MCSProbe::InitializeNetworkState() { |
302 FILE* log_file = NULL; | 318 FILE* log_file = NULL; |
303 if (command_line_.HasSwitch(kLogFileSwitch)) { | 319 if (command_line_.HasSwitch(kLogFileSwitch)) { |
304 base::FilePath log_path = command_line_.GetSwitchValuePath(kLogFileSwitch); | 320 base::FilePath log_path = command_line_.GetSwitchValuePath(kLogFileSwitch); |
305 #if defined(OS_WIN) | 321 #if defined(OS_WIN) |
306 log_file = _wfopen(log_path.value().c_str(), L"w"); | 322 log_file = _wfopen(log_path.value().c_str(), L"w"); |
307 #elif defined(OS_POSIX) | 323 #elif defined(OS_POSIX) |
308 log_file = fopen(log_path.value().c_str(), "w"); | 324 log_file = fopen(log_path.value().c_str(), "w"); |
309 #endif | 325 #endif |
310 } | 326 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 } | 403 } |
388 | 404 |
389 void MCSProbe::OnCheckInCompleted(uint64 android_id, uint64 secret) { | 405 void MCSProbe::OnCheckInCompleted(uint64 android_id, uint64 secret) { |
390 LOG(INFO) << "Check-in request completion " | 406 LOG(INFO) << "Check-in request completion " |
391 << (android_id ? "success!" : "failure!"); | 407 << (android_id ? "success!" : "failure!"); |
392 if (!android_id || !secret) | 408 if (!android_id || !secret) |
393 return; | 409 return; |
394 android_id_ = android_id; | 410 android_id_ = android_id; |
395 secret_ = secret; | 411 secret_ = secret; |
396 | 412 |
| 413 gcm_store_->SetDeviceCredentials(android_id_, |
| 414 secret_, |
| 415 base::Bind(&MCSProbe::UpdateCallback, |
| 416 base::Unretained(this))); |
| 417 |
397 LOG(INFO) << "MCS login initiated."; | 418 LOG(INFO) << "MCS login initiated."; |
398 mcs_client_->Login(android_id_, secret_); | 419 mcs_client_->Login(android_id_, secret_); |
399 } | 420 } |
400 | 421 |
401 int MCSProbeMain(int argc, char* argv[]) { | 422 int MCSProbeMain(int argc, char* argv[]) { |
402 base::AtExitManager exit_manager; | 423 base::AtExitManager exit_manager; |
403 | 424 |
404 CommandLine::Init(argc, argv); | 425 CommandLine::Init(argc, argv); |
405 logging::LoggingSettings settings; | 426 logging::LoggingSettings settings; |
406 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; | 427 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; |
(...skipping 16 matching lines...) Expand all Loading... |
423 | 444 |
424 return 0; | 445 return 0; |
425 } | 446 } |
426 | 447 |
427 } // namespace | 448 } // namespace |
428 } // namespace gcm | 449 } // namespace gcm |
429 | 450 |
430 int main(int argc, char* argv[]) { | 451 int main(int argc, char* argv[]) { |
431 return gcm::MCSProbeMain(argc, argv); | 452 return gcm::MCSProbeMain(argc, argv); |
432 } | 453 } |
OLD | NEW |