Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(708)

Side by Side Diff: google_apis/gcm/engine/connection_handler_impl.cc

Issue 171683002: [GCM] Fix gcm login to properly identify chrome (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Self review Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "google/protobuf/io/coded_stream.h" 8 #include "google/protobuf/io/coded_stream.h"
9 #include "google_apis/gcm/base/mcs_util.h" 9 #include "google_apis/gcm/base/mcs_util.h"
10 #include "google_apis/gcm/base/socket_stream.h" 10 #include "google_apis/gcm/base/socket_stream.h"
11 #include "google_apis/gcm/protocol/mcs.pb.h" 11 #include "google_apis/gcm/protocol/mcs.pb.h"
12 #include "net/base/net_errors.h" 12 #include "net/base/net_errors.h"
13 #include "net/socket/stream_socket.h" 13 #include "net/socket/stream_socket.h"
14 14
15 using namespace google::protobuf::io; 15 using namespace google::protobuf::io;
16 16
17 namespace gcm { 17 namespace gcm {
18 18
19 namespace { 19 namespace {
20 20
21 // # of bytes a MCS version packet consumes. 21 // # of bytes a MCS version packet consumes.
22 const int kVersionPacketLen = 1; 22 const int kVersionPacketLen = 1;
23 // # of bytes a tag packet consumes. 23 // # of bytes a tag packet consumes.
24 const int kTagPacketLen = 1; 24 const int kTagPacketLen = 1;
25 // Max # of bytes a length packet consumes. 25 // Max # of bytes a length packet consumes.
26 const int kSizePacketLenMin = 1; 26 const int kSizePacketLenMin = 1;
27 const int kSizePacketLenMax = 2; 27 const int kSizePacketLenMax = 2;
28 28
29 // The current MCS protocol version. 29 // The current MCS protocol version.
30 // TODO(zea): bump to 41 once the server supports it. 30 const int kMCSVersion = 41;
31 const int kMCSVersion = 38;
32 31
33 } // namespace 32 } // namespace
34 33
35 ConnectionHandlerImpl::ConnectionHandlerImpl( 34 ConnectionHandlerImpl::ConnectionHandlerImpl(
36 base::TimeDelta read_timeout, 35 base::TimeDelta read_timeout,
37 const ProtoReceivedCallback& read_callback, 36 const ProtoReceivedCallback& read_callback,
38 const ProtoSentCallback& write_callback, 37 const ProtoSentCallback& write_callback,
39 const ConnectionChangedCallback& connection_callback) 38 const ConnectionChangedCallback& connection_callback)
40 : read_timeout_(read_timeout), 39 : read_timeout_(read_timeout),
41 socket_(NULL), 40 socket_(NULL),
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 NOTREACHED(); 255 NOTREACHED();
257 } 256 }
258 } 257 }
259 258
260 void ConnectionHandlerImpl::OnGotVersion() { 259 void ConnectionHandlerImpl::OnGotVersion() {
261 uint8 version = 0; 260 uint8 version = 0;
262 { 261 {
263 CodedInputStream coded_input_stream(input_stream_.get()); 262 CodedInputStream coded_input_stream(input_stream_.get());
264 coded_input_stream.ReadRaw(&version, 1); 263 coded_input_stream.ReadRaw(&version, 1);
265 } 264 }
266 if (version < kMCSVersion) { 265 // TODO(zea): remove this when the server is ready.
266 if (version < kMCSVersion && version != 38) {
jianli 2014/02/19 00:08:26 Why do we need to check for this? What's current v
Nicolas Zea 2014/02/19 18:40:28 A server bug that hasn't been fixed yet results in
267 LOG(ERROR) << "Invalid GCM version response: " << static_cast<int>(version); 267 LOG(ERROR) << "Invalid GCM version response: " << static_cast<int>(version);
268 connection_callback_.Run(net::ERR_FAILED); 268 connection_callback_.Run(net::ERR_FAILED);
269 return; 269 return;
270 } 270 }
271 271
272 input_stream_->RebuildBuffer(); 272 input_stream_->RebuildBuffer();
273 273
274 // Process the LoginResponse message tag. 274 // Process the LoginResponse message tag.
275 OnGotMessageTag(); 275 OnGotMessageTag();
276 } 276 }
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 read_timeout_timer_.Stop(); 401 read_timeout_timer_.Stop();
402 if (socket_) 402 if (socket_)
403 socket_->Disconnect(); 403 socket_->Disconnect();
404 socket_ = NULL; 404 socket_ = NULL;
405 input_stream_.reset(); 405 input_stream_.reset();
406 output_stream_.reset(); 406 output_stream_.reset();
407 weak_ptr_factory_.InvalidateWeakPtrs(); 407 weak_ptr_factory_.InvalidateWeakPtrs();
408 } 408 }
409 409
410 } // namespace gcm 410 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698