Commit e262fd1f authored by zea@chromium.org's avatar zea@chromium.org

[GCM] Fix gcm login to properly identify chrome

Use version 41 and put the chrome version in the id field.

BUG=344694

Review URL: https://codereview.chromium.org/171683002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@252255 0039d316-1c4b-4281-b951-d872f2087c98
parent 5dbdf37e
...@@ -36,7 +36,7 @@ TEST_F(MCSMessageTest, Invalid) { ...@@ -36,7 +36,7 @@ TEST_F(MCSMessageTest, Invalid) {
TEST_F(MCSMessageTest, InitInferTag) { TEST_F(MCSMessageTest, InitInferTag) {
scoped_ptr<mcs_proto::LoginRequest> login_request( scoped_ptr<mcs_proto::LoginRequest> login_request(
BuildLoginRequest(kAndroidId, kSecret)); BuildLoginRequest(kAndroidId, kSecret, ""));
scoped_ptr<google::protobuf::MessageLite> login_copy( scoped_ptr<google::protobuf::MessageLite> login_copy(
new mcs_proto::LoginRequest(*login_request)); new mcs_proto::LoginRequest(*login_request));
MCSMessage message(*login_copy); MCSMessage message(*login_copy);
...@@ -54,7 +54,7 @@ TEST_F(MCSMessageTest, InitInferTag) { ...@@ -54,7 +54,7 @@ TEST_F(MCSMessageTest, InitInferTag) {
TEST_F(MCSMessageTest, InitWithTag) { TEST_F(MCSMessageTest, InitWithTag) {
scoped_ptr<mcs_proto::LoginRequest> login_request( scoped_ptr<mcs_proto::LoginRequest> login_request(
BuildLoginRequest(kAndroidId, kSecret)); BuildLoginRequest(kAndroidId, kSecret, ""));
scoped_ptr<google::protobuf::MessageLite> login_copy( scoped_ptr<google::protobuf::MessageLite> login_copy(
new mcs_proto::LoginRequest(*login_request)); new mcs_proto::LoginRequest(*login_request));
MCSMessage message(kLoginRequestTag, *login_copy); MCSMessage message(kLoginRequestTag, *login_copy);
...@@ -72,7 +72,7 @@ TEST_F(MCSMessageTest, InitWithTag) { ...@@ -72,7 +72,7 @@ TEST_F(MCSMessageTest, InitWithTag) {
TEST_F(MCSMessageTest, InitPassOwnership) { TEST_F(MCSMessageTest, InitPassOwnership) {
scoped_ptr<mcs_proto::LoginRequest> login_request( scoped_ptr<mcs_proto::LoginRequest> login_request(
BuildLoginRequest(kAndroidId, kSecret)); BuildLoginRequest(kAndroidId, kSecret, ""));
scoped_ptr<google::protobuf::MessageLite> login_copy( scoped_ptr<google::protobuf::MessageLite> login_copy(
new mcs_proto::LoginRequest(*login_request)); new mcs_proto::LoginRequest(*login_request));
MCSMessage message(kLoginRequestTag, MCSMessage message(kLoginRequestTag,
......
...@@ -39,8 +39,7 @@ const char* kProtoNames[] = { ...@@ -39,8 +39,7 @@ const char* kProtoNames[] = {
COMPILE_ASSERT(arraysize(kProtoNames) == kNumProtoTypes, COMPILE_ASSERT(arraysize(kProtoNames) == kNumProtoTypes,
ProtoNamesMustIncludeAllTags); ProtoNamesMustIncludeAllTags);
// TODO(zea): replace these with proper values. const char kLoginId[] = "chrome-";
const char kLoginId[] = "login-1";
const char kLoginDomain[] = "mcs.android.com"; const char kLoginDomain[] = "mcs.android.com";
const char kLoginDeviceIdPrefix[] = "android-"; const char kLoginDeviceIdPrefix[] = "android-";
const char kLoginSettingDefaultName[] = "new_vc"; const char kLoginSettingDefaultName[] = "new_vc";
...@@ -51,8 +50,10 @@ const int kMaxTTLSeconds = 4 * 7 * 24 * 60 * 60; // 4 weeks. ...@@ -51,8 +50,10 @@ const int kMaxTTLSeconds = 4 * 7 * 24 * 60 * 60; // 4 weeks.
} // namespace } // namespace
scoped_ptr<mcs_proto::LoginRequest> BuildLoginRequest(uint64 auth_id, scoped_ptr<mcs_proto::LoginRequest> BuildLoginRequest(
uint64 auth_token) { uint64 auth_id,
uint64 auth_token,
const std::string& version_string) {
// Create a hex encoded auth id for the device id field. // Create a hex encoded auth id for the device id field.
std::string auth_id_hex; std::string auth_id_hex;
auth_id_hex = base::StringPrintf("%" PRIx64, auth_id); auth_id_hex = base::StringPrintf("%" PRIx64, auth_id);
...@@ -63,12 +64,10 @@ scoped_ptr<mcs_proto::LoginRequest> BuildLoginRequest(uint64 auth_id, ...@@ -63,12 +64,10 @@ scoped_ptr<mcs_proto::LoginRequest> BuildLoginRequest(uint64 auth_id,
scoped_ptr<mcs_proto::LoginRequest> login_request( scoped_ptr<mcs_proto::LoginRequest> login_request(
new mcs_proto::LoginRequest()); new mcs_proto::LoginRequest());
// TODO(zea): set better values.
login_request->set_account_id(1000000);
login_request->set_adaptive_heartbeat(false); login_request->set_adaptive_heartbeat(false);
login_request->set_auth_service(mcs_proto::LoginRequest::ANDROID_ID); login_request->set_auth_service(mcs_proto::LoginRequest::ANDROID_ID);
login_request->set_auth_token(auth_token_str); login_request->set_auth_token(auth_token_str);
login_request->set_id(kLoginId); login_request->set_id(kLoginId + version_string);
login_request->set_domain(kLoginDomain); login_request->set_domain(kLoginDomain);
login_request->set_device_id(kLoginDeviceIdPrefix + auth_id_hex); login_request->set_device_id(kLoginDeviceIdPrefix + auth_id_hex);
login_request->set_network_type(1); login_request->set_network_type(1);
......
...@@ -57,7 +57,8 @@ enum MCSIqStanzaExtension { ...@@ -57,7 +57,8 @@ enum MCSIqStanzaExtension {
// Builds a LoginRequest with the hardcoded local data. // Builds a LoginRequest with the hardcoded local data.
GCM_EXPORT scoped_ptr<mcs_proto::LoginRequest> BuildLoginRequest( GCM_EXPORT scoped_ptr<mcs_proto::LoginRequest> BuildLoginRequest(
uint64 auth_id, uint64 auth_id,
uint64 auth_token); uint64 auth_token,
const std::string& version_string);
// Builds a StreamAck IqStanza message. // Builds a StreamAck IqStanza message.
GCM_EXPORT scoped_ptr<mcs_proto::IqStanza> BuildStreamAck(); GCM_EXPORT scoped_ptr<mcs_proto::IqStanza> BuildStreamAck();
......
...@@ -19,8 +19,8 @@ const uint64 kAuthToken = 12345; ...@@ -19,8 +19,8 @@ const uint64 kAuthToken = 12345;
// Build a login request protobuf. // Build a login request protobuf.
TEST(MCSUtilTest, BuildLoginRequest) { TEST(MCSUtilTest, BuildLoginRequest) {
scoped_ptr<mcs_proto::LoginRequest> login_request = scoped_ptr<mcs_proto::LoginRequest> login_request =
BuildLoginRequest(kAuthId, kAuthToken); BuildLoginRequest(kAuthId, kAuthToken, "1.0");
ASSERT_EQ("login-1", login_request->id()); ASSERT_EQ("chrome-1.0", login_request->id());
ASSERT_EQ(base::Uint64ToString(kAuthToken), login_request->auth_token()); ASSERT_EQ(base::Uint64ToString(kAuthToken), login_request->auth_token());
ASSERT_EQ(base::Uint64ToString(kAuthId), login_request->user()); ASSERT_EQ(base::Uint64ToString(kAuthId), login_request->user());
ASSERT_EQ("android-3d5c23dac2a1fa7c", login_request->device_id()); ASSERT_EQ("android-3d5c23dac2a1fa7c", login_request->device_id());
......
...@@ -27,8 +27,7 @@ const int kSizePacketLenMin = 1; ...@@ -27,8 +27,7 @@ const int kSizePacketLenMin = 1;
const int kSizePacketLenMax = 2; const int kSizePacketLenMax = 2;
// The current MCS protocol version. // The current MCS protocol version.
// TODO(zea): bump to 41 once the server supports it. const int kMCSVersion = 41;
const int kMCSVersion = 38;
} // namespace } // namespace
...@@ -263,7 +262,8 @@ void ConnectionHandlerImpl::OnGotVersion() { ...@@ -263,7 +262,8 @@ void ConnectionHandlerImpl::OnGotVersion() {
CodedInputStream coded_input_stream(input_stream_.get()); CodedInputStream coded_input_stream(input_stream_.get());
coded_input_stream.ReadRaw(&version, 1); coded_input_stream.ReadRaw(&version, 1);
} }
if (version < kMCSVersion) { // TODO(zea): remove this when the server is ready.
if (version < kMCSVersion && version != 38) {
LOG(ERROR) << "Invalid GCM version response: " << static_cast<int>(version); LOG(ERROR) << "Invalid GCM version response: " << static_cast<int>(version);
connection_callback_.Run(net::ERR_FAILED); connection_callback_.Run(net::ERR_FAILED);
return; return;
......
...@@ -27,7 +27,7 @@ typedef std::vector<net::MockWrite> WriteList; ...@@ -27,7 +27,7 @@ typedef std::vector<net::MockWrite> WriteList;
const uint64 kAuthId = 54321; const uint64 kAuthId = 54321;
const uint64 kAuthToken = 12345; const uint64 kAuthToken = 12345;
const char kMCSVersion = 38; // The protocol version. const char kMCSVersion = 41; // The protocol version.
const int kMCSPort = 5228; // The server port. const int kMCSPort = 5228; // The server port.
const char kDataMsgFrom[] = "data_from"; const char kDataMsgFrom[] = "data_from";
const char kDataMsgCategory[] = "data_category"; const char kDataMsgCategory[] = "data_category";
...@@ -67,7 +67,8 @@ std::string EncodeHandshakeRequest() { ...@@ -67,7 +67,8 @@ std::string EncodeHandshakeRequest() {
std::string result; std::string result;
const char version_byte[1] = {kMCSVersion}; const char version_byte[1] = {kMCSVersion};
result.append(version_byte, 1); result.append(version_byte, 1);
ScopedMessage login_request(BuildLoginRequest(kAuthId, kAuthToken)); ScopedMessage login_request(
BuildLoginRequest(kAuthId, kAuthToken, ""));
result.append(EncodePacket(kLoginRequestTag, result.append(EncodePacket(kLoginRequestTag,
login_request->SerializeAsString())); login_request->SerializeAsString()));
return result; return result;
...@@ -203,7 +204,7 @@ void GCMConnectionHandlerImplTest::Connect( ...@@ -203,7 +204,7 @@ void GCMConnectionHandlerImplTest::Connect(
base::Unretained(this)))); base::Unretained(this))));
EXPECT_FALSE(connection_handler()->CanSendMessage()); EXPECT_FALSE(connection_handler()->CanSendMessage());
connection_handler_->Init( connection_handler_->Init(
*BuildLoginRequest(kAuthId, kAuthToken), *BuildLoginRequest(kAuthId, kAuthToken, ""),
socket_.get()); socket_.get());
} }
......
...@@ -126,10 +126,12 @@ ReliablePacketInfo::ReliablePacketInfo() ...@@ -126,10 +126,12 @@ ReliablePacketInfo::ReliablePacketInfo()
} }
ReliablePacketInfo::~ReliablePacketInfo() {} ReliablePacketInfo::~ReliablePacketInfo() {}
MCSClient::MCSClient(base::Clock* clock, MCSClient::MCSClient(const std::string& version_string,
base::Clock* clock,
ConnectionFactory* connection_factory, ConnectionFactory* connection_factory,
GCMStore* gcm_store) GCMStore* gcm_store)
: clock_(clock), : version_string_(version_string),
clock_(clock),
state_(UNINITIALIZED), state_(UNINITIALIZED),
android_id_(0), android_id_(0),
security_token_(0), security_token_(0),
...@@ -369,7 +371,9 @@ void MCSClient::ResetStateAndBuildLoginRequest( ...@@ -369,7 +371,9 @@ void MCSClient::ResetStateAndBuildLoginRequest(
acked_server_ids_.clear(); acked_server_ids_.clear();
// Then build the request, consuming all pending acknowledgments. // Then build the request, consuming all pending acknowledgments.
request->Swap(BuildLoginRequest(android_id_, security_token_).get()); request->Swap(BuildLoginRequest(android_id_,
security_token_,
version_string_).get());
for (PersistentIdList::const_iterator iter = for (PersistentIdList::const_iterator iter =
restored_unackeds_server_ids_.begin(); restored_unackeds_server_ids_.begin();
iter != restored_unackeds_server_ids_.end(); ++iter) { iter != restored_unackeds_server_ids_.end(); ++iter) {
......
...@@ -84,7 +84,8 @@ class GCM_EXPORT MCSClient { ...@@ -84,7 +84,8 @@ class GCM_EXPORT MCSClient {
const std::string& message_id, const std::string& message_id,
MessageSendStatus status)> OnMessageSentCallback; MessageSendStatus status)> OnMessageSentCallback;
MCSClient(base::Clock* clock, MCSClient(const std::string& version_string,
base::Clock* clock,
ConnectionFactory* connection_factory, ConnectionFactory* connection_factory,
GCMStore* gcm_store); GCMStore* gcm_store);
virtual ~MCSClient(); virtual ~MCSClient();
...@@ -197,6 +198,9 @@ class GCM_EXPORT MCSClient { ...@@ -197,6 +198,9 @@ class GCM_EXPORT MCSClient {
// any associated state). // any associated state).
MCSPacketInternal PopMessageForSend(); MCSPacketInternal PopMessageForSend();
// Local version string. Sent on login.
const std::string version_string_;
// Clock for enforcing TTL. Passed in for testing. // Clock for enforcing TTL. Passed in for testing.
base::Clock* const clock_; base::Clock* const clock_;
......
...@@ -67,7 +67,7 @@ class TestMCSClient : public MCSClient { ...@@ -67,7 +67,7 @@ class TestMCSClient : public MCSClient {
TestMCSClient(base::Clock* clock, TestMCSClient(base::Clock* clock,
ConnectionFactory* connection_factory, ConnectionFactory* connection_factory,
GCMStore* gcm_store) GCMStore* gcm_store)
: MCSClient(clock, connection_factory, gcm_store), : MCSClient("", clock, connection_factory, gcm_store),
next_id_(0) { next_id_(0) {
} }
...@@ -180,7 +180,7 @@ void MCSClientTest::InitializeClient() { ...@@ -180,7 +180,7 @@ void MCSClientTest::InitializeClient() {
void MCSClientTest::LoginClient( void MCSClientTest::LoginClient(
const std::vector<std::string>& acknowledged_ids) { const std::vector<std::string>& acknowledged_ids) {
scoped_ptr<mcs_proto::LoginRequest> login_request = scoped_ptr<mcs_proto::LoginRequest> login_request =
BuildLoginRequest(kAndroidId, kSecurityToken); BuildLoginRequest(kAndroidId, kSecurityToken, "");
for (size_t i = 0; i < acknowledged_ids.size(); ++i) for (size_t i = 0; i < acknowledged_ids.size(); ++i)
login_request->add_received_persistent_id(acknowledged_ids[i]); login_request->add_received_persistent_id(acknowledged_ids[i]);
GetFakeHandler()->ExpectOutgoingMessage( GetFakeHandler()->ExpectOutgoingMessage(
...@@ -346,7 +346,7 @@ TEST_F(MCSClientTest, SendMessageRMQWhileDisconnected) { ...@@ -346,7 +346,7 @@ TEST_F(MCSClientTest, SendMessageRMQWhileDisconnected) {
GetFakeHandler()->ExpectOutgoingMessage( GetFakeHandler()->ExpectOutgoingMessage(
MCSMessage( MCSMessage(
kLoginRequestTag, kLoginRequestTag,
BuildLoginRequest(kAndroidId, kSecurityToken). BuildLoginRequest(kAndroidId, kSecurityToken, "").
PassAs<const google::protobuf::MessageLite>())); PassAs<const google::protobuf::MessageLite>()));
// The second (re)send. // The second (re)send.
MCSMessage message2(BuildDataMessage( MCSMessage message2(BuildDataMessage(
......
...@@ -156,7 +156,8 @@ void GCMClientImpl::Initialize( ...@@ -156,7 +156,8 @@ void GCMClientImpl::Initialize(
kDefaultBackoffPolicy, kDefaultBackoffPolicy,
network_session_, network_session_,
net_log_.net_log())); net_log_.net_log()));
mcs_client_.reset(new MCSClient(clock_.get(), mcs_client_.reset(new MCSClient(chrome_build_proto.chrome_version(),
clock_.get(),
connection_factory_.get(), connection_factory_.get(),
gcm_store_.get())); gcm_store_.get()));
} }
......
...@@ -83,7 +83,7 @@ class FakeMCSClient : public MCSClient { ...@@ -83,7 +83,7 @@ class FakeMCSClient : public MCSClient {
FakeMCSClient::FakeMCSClient(base::Clock* clock, FakeMCSClient::FakeMCSClient(base::Clock* clock,
ConnectionFactory* connection_factory) ConnectionFactory* connection_factory)
: MCSClient(clock, connection_factory, NULL), : MCSClient("", clock, connection_factory, NULL),
last_android_id_(0u), last_android_id_(0u),
last_security_token_(0u), last_security_token_(0u),
last_message_tag_(kNumProtoTypes) { last_message_tag_(kNumProtoTypes) {
......
...@@ -299,7 +299,8 @@ void MCSProbe::Start() { ...@@ -299,7 +299,8 @@ void MCSProbe::Start() {
new GCMStoreImpl(true, new GCMStoreImpl(true,
gcm_store_path_, gcm_store_path_,
file_thread_.message_loop_proxy())); file_thread_.message_loop_proxy()));
mcs_client_.reset(new MCSClient(&clock_, mcs_client_.reset(new MCSClient("probe",
&clock_,
connection_factory_.get(), connection_factory_.get(),
gcm_store_.get())); gcm_store_.get()));
run_loop_.reset(new base::RunLoop()); run_loop_.reset(new base::RunLoop());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment