| 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 #include "google_apis/gcm/engine/connection_handler_impl.h" | 5 #include "google_apis/gcm/engine/connection_handler_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 | 305 |
| 306 input_stream_->RebuildBuffer(); | 306 input_stream_->RebuildBuffer(); |
| 307 | 307 |
| 308 // Process the LoginResponse message tag. | 308 // Process the LoginResponse message tag. |
| 309 OnGotMessageTag(); | 309 OnGotMessageTag(); |
| 310 } | 310 } |
| 311 | 311 |
| 312 void ConnectionHandlerImpl::OnGotMessageTag() { | 312 void ConnectionHandlerImpl::OnGotMessageTag() { |
| 313 if (input_stream_->GetState() != SocketInputStream::READY) { | 313 if (input_stream_->GetState() != SocketInputStream::READY) { |
| 314 LOG(ERROR) << "Failed to receive protobuf tag."; | 314 LOG(ERROR) << "Failed to receive protobuf tag."; |
| 315 read_callback_.Run(scoped_ptr<google::protobuf::MessageLite>()); | 315 read_callback_.Run(std::unique_ptr<google::protobuf::MessageLite>()); |
| 316 return; | 316 return; |
| 317 } | 317 } |
| 318 | 318 |
| 319 { | 319 { |
| 320 CodedInputStream coded_input_stream(input_stream_.get()); | 320 CodedInputStream coded_input_stream(input_stream_.get()); |
| 321 coded_input_stream.ReadRaw(&message_tag_, 1); | 321 coded_input_stream.ReadRaw(&message_tag_, 1); |
| 322 } | 322 } |
| 323 | 323 |
| 324 DVLOG(1) << "Received proto of type " | 324 DVLOG(1) << "Received proto of type " |
| 325 << static_cast<unsigned int>(message_tag_); | 325 << static_cast<unsigned int>(message_tag_); |
| 326 | 326 |
| 327 if (!read_timeout_timer_.IsRunning()) { | 327 if (!read_timeout_timer_.IsRunning()) { |
| 328 read_timeout_timer_.Start(FROM_HERE, | 328 read_timeout_timer_.Start(FROM_HERE, |
| 329 read_timeout_, | 329 read_timeout_, |
| 330 base::Bind(&ConnectionHandlerImpl::OnTimeout, | 330 base::Bind(&ConnectionHandlerImpl::OnTimeout, |
| 331 weak_ptr_factory_.GetWeakPtr())); | 331 weak_ptr_factory_.GetWeakPtr())); |
| 332 } | 332 } |
| 333 OnGotMessageSize(); | 333 OnGotMessageSize(); |
| 334 } | 334 } |
| 335 | 335 |
| 336 void ConnectionHandlerImpl::OnGotMessageSize() { | 336 void ConnectionHandlerImpl::OnGotMessageSize() { |
| 337 if (input_stream_->GetState() != SocketInputStream::READY) { | 337 if (input_stream_->GetState() != SocketInputStream::READY) { |
| 338 LOG(ERROR) << "Failed to receive message size."; | 338 LOG(ERROR) << "Failed to receive message size."; |
| 339 read_callback_.Run(scoped_ptr<google::protobuf::MessageLite>()); | 339 read_callback_.Run(std::unique_ptr<google::protobuf::MessageLite>()); |
| 340 return; | 340 return; |
| 341 } | 341 } |
| 342 | 342 |
| 343 int prev_byte_count = input_stream_->UnreadByteCount(); | 343 int prev_byte_count = input_stream_->UnreadByteCount(); |
| 344 int result = net::OK; | 344 int result = net::OK; |
| 345 bool incomplete_size_packet = false; | 345 bool incomplete_size_packet = false; |
| 346 { | 346 { |
| 347 CodedInputStream coded_input_stream(input_stream_.get()); | 347 CodedInputStream coded_input_stream(input_stream_.get()); |
| 348 if (!coded_input_stream.ReadVarint32(&message_size_)) { | 348 if (!coded_input_stream.ReadVarint32(&message_size_)) { |
| 349 DVLOG(1) << "Expecting another message size byte."; | 349 DVLOG(1) << "Expecting another message size byte."; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 374 payload_input_buffer_.clear(); | 374 payload_input_buffer_.clear(); |
| 375 | 375 |
| 376 if (message_size_ > 0) | 376 if (message_size_ > 0) |
| 377 WaitForData(MCS_PROTO_BYTES); | 377 WaitForData(MCS_PROTO_BYTES); |
| 378 else | 378 else |
| 379 OnGotMessageBytes(); | 379 OnGotMessageBytes(); |
| 380 } | 380 } |
| 381 | 381 |
| 382 void ConnectionHandlerImpl::OnGotMessageBytes() { | 382 void ConnectionHandlerImpl::OnGotMessageBytes() { |
| 383 read_timeout_timer_.Stop(); | 383 read_timeout_timer_.Stop(); |
| 384 scoped_ptr<google::protobuf::MessageLite> protobuf( | 384 std::unique_ptr<google::protobuf::MessageLite> protobuf( |
| 385 BuildProtobufFromTag(message_tag_)); | 385 BuildProtobufFromTag(message_tag_)); |
| 386 // Messages with no content are valid; just use the default protobuf for | 386 // Messages with no content are valid; just use the default protobuf for |
| 387 // that tag. | 387 // that tag. |
| 388 if (protobuf.get() && message_size_ == 0) { | 388 if (protobuf.get() && message_size_ == 0) { |
| 389 base::ThreadTaskRunnerHandle::Get()->PostTask( | 389 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 390 FROM_HERE, | 390 FROM_HERE, |
| 391 base::Bind(&ConnectionHandlerImpl::GetNextMessage, | 391 base::Bind(&ConnectionHandlerImpl::GetNextMessage, |
| 392 weak_ptr_factory_.GetWeakPtr())); | 392 weak_ptr_factory_.GetWeakPtr())); |
| 393 read_callback_.Run(std::move(protobuf)); | 393 read_callback_.Run(std::move(protobuf)); |
| 394 return; | 394 return; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 message_tag_ = 0; | 491 message_tag_ = 0; |
| 492 message_size_ = 0; | 492 message_size_ = 0; |
| 493 size_packet_so_far_ = 0; | 493 size_packet_so_far_ = 0; |
| 494 payload_input_buffer_.clear(); | 494 payload_input_buffer_.clear(); |
| 495 input_stream_.reset(); | 495 input_stream_.reset(); |
| 496 output_stream_.reset(); | 496 output_stream_.reset(); |
| 497 weak_ptr_factory_.InvalidateWeakPtrs(); | 497 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 498 } | 498 } |
| 499 | 499 |
| 500 } // namespace gcm | 500 } // namespace gcm |
| OLD | NEW |