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 "base/location.h" | 7 #include "base/location.h" |
8 #include "base/thread_task_runner_handle.h" | 8 #include "base/thread_task_runner_handle.h" |
9 #include "google/protobuf/io/coded_stream.h" | 9 #include "google/protobuf/io/coded_stream.h" |
10 #include "google/protobuf/io/zero_copy_stream_impl_lite.h" | 10 #include "google/protobuf/io/zero_copy_stream_impl_lite.h" |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 break; | 282 break; |
283 case MCS_PROTO_BYTES: | 283 case MCS_PROTO_BYTES: |
284 OnGotMessageBytes(); | 284 OnGotMessageBytes(); |
285 break; | 285 break; |
286 default: | 286 default: |
287 NOTREACHED(); | 287 NOTREACHED(); |
288 } | 288 } |
289 } | 289 } |
290 | 290 |
291 void ConnectionHandlerImpl::OnGotVersion() { | 291 void ConnectionHandlerImpl::OnGotVersion() { |
292 uint8 version = 0; | 292 uint8_t version = 0; |
293 { | 293 { |
294 CodedInputStream coded_input_stream(input_stream_.get()); | 294 CodedInputStream coded_input_stream(input_stream_.get()); |
295 coded_input_stream.ReadRaw(&version, 1); | 295 coded_input_stream.ReadRaw(&version, 1); |
296 } | 296 } |
297 // TODO(zea): remove this when the server is ready. | 297 // TODO(zea): remove this when the server is ready. |
298 if (version < kMCSVersion && version != 38) { | 298 if (version < kMCSVersion && version != 38) { |
299 LOG(ERROR) << "Invalid GCM version response: " << static_cast<int>(version); | 299 LOG(ERROR) << "Invalid GCM version response: " << static_cast<int>(version); |
300 connection_callback_.Run(net::ERR_FAILED); | 300 connection_callback_.Run(net::ERR_FAILED); |
301 return; | 301 return; |
302 } | 302 } |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 LOG(ERROR) << "Unable to parse GCM message of type " | 414 LOG(ERROR) << "Unable to parse GCM message of type " |
415 << static_cast<unsigned int>(message_tag_); | 415 << static_cast<unsigned int>(message_tag_); |
416 result = net::ERR_FAILED; | 416 result = net::ERR_FAILED; |
417 } | 417 } |
418 } else { | 418 } else { |
419 // Copy any data in the input stream onto the end of the buffer. | 419 // Copy any data in the input stream onto the end of the buffer. |
420 const void* data_ptr = NULL; | 420 const void* data_ptr = NULL; |
421 int size = 0; | 421 int size = 0; |
422 input_stream_->Next(&data_ptr, &size); | 422 input_stream_->Next(&data_ptr, &size); |
423 payload_input_buffer_.insert(payload_input_buffer_.end(), | 423 payload_input_buffer_.insert(payload_input_buffer_.end(), |
424 static_cast<const uint8*>(data_ptr), | 424 static_cast<const uint8_t*>(data_ptr), |
425 static_cast<const uint8*>(data_ptr) + size); | 425 static_cast<const uint8_t*>(data_ptr) + size); |
426 DCHECK_LE(payload_input_buffer_.size(), message_size_); | 426 DCHECK_LE(payload_input_buffer_.size(), message_size_); |
427 | 427 |
428 if (payload_input_buffer_.size() == message_size_) { | 428 if (payload_input_buffer_.size() == message_size_) { |
429 ArrayInputStream buffer_input_stream(payload_input_buffer_.data(), | 429 ArrayInputStream buffer_input_stream(payload_input_buffer_.data(), |
430 payload_input_buffer_.size()); | 430 payload_input_buffer_.size()); |
431 CodedInputStream coded_input_stream(&buffer_input_stream); | 431 CodedInputStream coded_input_stream(&buffer_input_stream); |
432 if (!protobuf->ParsePartialFromCodedStream(&coded_input_stream)) { | 432 if (!protobuf->ParsePartialFromCodedStream(&coded_input_stream)) { |
433 LOG(ERROR) << "Unable to parse GCM message of type " | 433 LOG(ERROR) << "Unable to parse GCM message of type " |
434 << static_cast<unsigned int>(message_tag_); | 434 << static_cast<unsigned int>(message_tag_); |
435 result = net::ERR_FAILED; | 435 result = net::ERR_FAILED; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 message_tag_ = 0; | 489 message_tag_ = 0; |
490 message_size_ = 0; | 490 message_size_ = 0; |
491 size_packet_so_far_ = 0; | 491 size_packet_so_far_ = 0; |
492 payload_input_buffer_.clear(); | 492 payload_input_buffer_.clear(); |
493 input_stream_.reset(); | 493 input_stream_.reset(); |
494 output_stream_.reset(); | 494 output_stream_.reset(); |
495 weak_ptr_factory_.InvalidateWeakPtrs(); | 495 weak_ptr_factory_.InvalidateWeakPtrs(); |
496 } | 496 } |
497 | 497 |
498 } // namespace gcm | 498 } // namespace gcm |
OLD | NEW |