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_, | |
jianli
2014/01/25 01:00:28
Should we persist the check-in info when the check
Nicolas Zea
2014/01/25 01:04:14
Good point, done.
| |
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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
423 | 439 |
424 return 0; | 440 return 0; |
425 } | 441 } |
426 | 442 |
427 } // namespace | 443 } // namespace |
428 } // namespace gcm | 444 } // namespace gcm |
429 | 445 |
430 int main(int argc, char* argv[]) { | 446 int main(int argc, char* argv[]) { |
431 return gcm::MCSProbeMain(argc, argv); | 447 return gcm::MCSProbeMain(argc, argv); |
432 } | 448 } |
OLD | NEW |