Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "components/copresence/rpc/rpc_handler.h" | 5 #include "components/copresence/rpc/rpc_handler.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 311 } | 311 } |
| 312 | 312 |
| 313 // Private methods | 313 // Private methods |
| 314 | 314 |
| 315 void RpcHandler::RegisterResponseHandler( | 315 void RpcHandler::RegisterResponseHandler( |
| 316 const SuccessCallback& init_done_callback, | 316 const SuccessCallback& init_done_callback, |
| 317 HttpPost* completed_post, | 317 HttpPost* completed_post, |
| 318 int http_status_code, | 318 int http_status_code, |
| 319 const std::string& response_data) { | 319 const std::string& response_data) { |
| 320 if (completed_post) { | 320 if (completed_post) { |
| 321 DCHECK(pending_posts_.erase(completed_post)); | 321 int elements_erased = pending_posts_.erase(completed_post); |
| 322 DCHECK(elements_erased); | |
|
rkc
2014/08/13 15:41:51
This will probably throw an unused variable compil
Charlie
2014/08/13 15:48:27
Nope, I've used this pattern before. There's even
| |
| 322 delete completed_post; | 323 delete completed_post; |
| 323 } | 324 } |
| 324 | 325 |
| 325 if (http_status_code != net::HTTP_OK) { | 326 if (http_status_code != net::HTTP_OK) { |
| 326 init_done_callback.Run(false); | 327 init_done_callback.Run(false); |
| 327 return; | 328 return; |
| 328 } | 329 } |
| 329 | 330 |
| 330 RegisterDeviceResponse response; | 331 RegisterDeviceResponse response; |
| 331 if (!response.ParseFromString(response_data)) { | 332 if (!response.ParseFromString(response_data)) { |
| 332 LOG(ERROR) << "Invalid RegisterDeviceResponse:\n" << response_data; | 333 LOG(ERROR) << "Invalid RegisterDeviceResponse:\n" << response_data; |
| 333 init_done_callback.Run(false); | 334 init_done_callback.Run(false); |
| 334 return; | 335 return; |
| 335 } | 336 } |
| 336 | 337 |
| 337 if (CopresenceErrorLogged(response.header().status())) | 338 if (CopresenceErrorLogged(response.header().status())) |
| 338 return; | 339 return; |
| 339 device_id_ = response.registered_device_id(); | 340 device_id_ = response.registered_device_id(); |
| 340 DCHECK(!device_id_.empty()); | 341 DCHECK(!device_id_.empty()); |
| 341 DVLOG(2) << "Device registration successful: id " << device_id_; | 342 DVLOG(2) << "Device registration successful: id " << device_id_; |
| 342 init_done_callback.Run(true); | 343 init_done_callback.Run(true); |
| 343 } | 344 } |
| 344 | 345 |
| 345 void RpcHandler::ReportResponseHandler(const StatusCallback& status_callback, | 346 void RpcHandler::ReportResponseHandler(const StatusCallback& status_callback, |
| 346 HttpPost* completed_post, | 347 HttpPost* completed_post, |
| 347 int http_status_code, | 348 int http_status_code, |
| 348 const std::string& response_data) { | 349 const std::string& response_data) { |
| 349 if (completed_post) { | 350 if (completed_post) { |
| 350 DCHECK(pending_posts_.erase(completed_post)); | 351 int elements_erased = pending_posts_.erase(completed_post); |
| 352 DCHECK(elements_erased); | |
| 351 delete completed_post; | 353 delete completed_post; |
| 352 } | 354 } |
| 353 | 355 |
| 354 if (http_status_code != net::HTTP_OK) { | 356 if (http_status_code != net::HTTP_OK) { |
| 355 if (!status_callback.is_null()) | 357 if (!status_callback.is_null()) |
| 356 status_callback.Run(FAIL); | 358 status_callback.Run(FAIL); |
| 357 return; | 359 return; |
| 358 } | 360 } |
| 359 | 361 |
| 360 DVLOG(3) << "Received ReportResponse."; | 362 DVLOG(3) << "Received ReportResponse."; |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 540 bool audible, | 542 bool audible, |
| 541 const WhispernetClient::SamplesCallback& samples_callback) { | 543 const WhispernetClient::SamplesCallback& samples_callback) { |
| 542 WhispernetClient* whispernet_client = delegate_->GetWhispernetClient(); | 544 WhispernetClient* whispernet_client = delegate_->GetWhispernetClient(); |
| 543 if (whispernet_client) { | 545 if (whispernet_client) { |
| 544 whispernet_client->RegisterSamplesCallback(samples_callback); | 546 whispernet_client->RegisterSamplesCallback(samples_callback); |
| 545 whispernet_client->EncodeToken(token, audible); | 547 whispernet_client->EncodeToken(token, audible); |
| 546 } | 548 } |
| 547 } | 549 } |
| 548 | 550 |
| 549 } // namespace copresence | 551 } // namespace copresence |
| OLD | NEW |