Commit 128078a0 authored by jianli@chromium.org's avatar jianli@chromium.org

[GCM] Support actual check-in in mcs_probe

BUG=284553
TEST=none due to that this is a tool
R=fgorski@chromium.org, zea@chromium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@244259 0039d316-1c4b-4281-b951-d872f2087c98
parent e5379697
...@@ -99,7 +99,6 @@ ConnectionHandler* ConnectionFactoryImpl::GetConnectionHandler() const { ...@@ -99,7 +99,6 @@ ConnectionHandler* ConnectionFactoryImpl::GetConnectionHandler() const {
void ConnectionFactoryImpl::Connect() { void ConnectionFactoryImpl::Connect() {
DCHECK(connection_handler_); DCHECK(connection_handler_);
DCHECK(!IsEndpointReachable());
connecting_ = true; connecting_ = true;
if (backoff_entry_->ShouldRejectRequest()) { if (backoff_entry_->ShouldRejectRequest()) {
...@@ -166,8 +165,6 @@ void ConnectionFactoryImpl::OnIPAddressChanged() { ...@@ -166,8 +165,6 @@ void ConnectionFactoryImpl::OnIPAddressChanged() {
} }
void ConnectionFactoryImpl::ConnectImpl() { void ConnectionFactoryImpl::ConnectImpl() {
DCHECK(!IsEndpointReachable());
if (socket_handle_.socket() && socket_handle_.socket()->IsConnected()) if (socket_handle_.socket() && socket_handle_.socket()->IsConnected())
socket_handle_.socket()->Disconnect(); socket_handle_.socket()->Disconnect();
socket_handle_.Reset(); socket_handle_.Reset();
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "base/values.h" #include "base/values.h"
#include "google_apis/gcm/base/mcs_message.h" #include "google_apis/gcm/base/mcs_message.h"
#include "google_apis/gcm/base/mcs_util.h" #include "google_apis/gcm/base/mcs_util.h"
#include "google_apis/gcm/engine/checkin_request.h"
#include "google_apis/gcm/engine/connection_factory_impl.h" #include "google_apis/gcm/engine/connection_factory_impl.h"
#include "google_apis/gcm/engine/gcm_store_impl.h" #include "google_apis/gcm/engine/gcm_store_impl.h"
#include "google_apis/gcm/engine/mcs_client.h" #include "google_apis/gcm/engine/mcs_client.h"
...@@ -50,6 +51,10 @@ ...@@ -50,6 +51,10 @@
namespace gcm { namespace gcm {
namespace { namespace {
// Default values used to communicate with the check-in server.
const char kChromeVersion[] = "Chrome MCS Probe";
const int64 kUserSerialNumber = 1;
// The default server to communicate with. // The default server to communicate with.
const char kMCSServerHost[] = "mtalk.google.com"; const char kMCSServerHost[] = "mtalk.google.com";
const uint16 kMCSServerPort = 5228; const uint16 kMCSServerPort = 5228;
...@@ -166,12 +171,14 @@ class MCSProbe { ...@@ -166,12 +171,14 @@ class MCSProbe {
uint64 secret() const { return secret_; } uint64 secret() const { return secret_; }
private: private:
void CheckIn();
void InitializeNetworkState(); void InitializeNetworkState();
void BuildNetworkSession(); void BuildNetworkSession();
void InitializationCallback(bool success, void InitializationCallback(bool success,
uint64 restored_android_id, uint64 restored_android_id,
uint64 restored_security_token); uint64 restored_security_token);
void OnCheckInCompleted(uint64 android_id, uint64 secret);
base::DefaultClock clock_; base::DefaultClock clock_;
...@@ -201,6 +208,7 @@ class MCSProbe { ...@@ -201,6 +208,7 @@ class MCSProbe {
scoped_ptr<GCMStore> gcm_store_; scoped_ptr<GCMStore> gcm_store_;
scoped_ptr<MCSClient> mcs_client_; scoped_ptr<MCSClient> mcs_client_;
scoped_ptr<CheckinRequest> checkin_request_;
scoped_ptr<ConnectionFactoryImpl> connection_factory_; scoped_ptr<ConnectionFactoryImpl> connection_factory_;
...@@ -340,11 +348,50 @@ void MCSProbe::InitializationCallback(bool success, ...@@ -340,11 +348,50 @@ void MCSProbe::InitializationCallback(bool success,
uint64 restored_security_token) { uint64 restored_security_token) {
LOG(INFO) << "Initialization " << (success ? "success!" : "failure!"); LOG(INFO) << "Initialization " << (success ? "success!" : "failure!");
if (restored_android_id && restored_security_token) { if (restored_android_id && restored_security_token) {
LOG(INFO) << "Restored device check-in info.";
android_id_ = restored_android_id; android_id_ = restored_android_id;
secret_ = restored_security_token; secret_ = restored_security_token;
} }
if (success) if (!success)
mcs_client_->Login(android_id_, secret_); return;
if (!android_id_ || !secret_) {
CheckIn();
return;
}
LOG(INFO) << "MCS login initiated.";
mcs_client_->Login(android_id_, secret_);
}
void MCSProbe::CheckIn() {
LOG(INFO) << "Check-in request initiated.";
checkin_proto::ChromeBuildProto chrome_build_proto;
chrome_build_proto.set_platform(
checkin_proto::ChromeBuildProto::PLATFORM_LINUX);
chrome_build_proto.set_channel(
checkin_proto::ChromeBuildProto::CHANNEL_CANARY);
chrome_build_proto.set_chrome_version(kChromeVersion);
checkin_request_.reset(new CheckinRequest(
base::Bind(&MCSProbe::OnCheckInCompleted, base::Unretained(this)),
chrome_build_proto,
kUserSerialNumber,
0,
0,
url_request_context_getter_.get()));
checkin_request_->Start();
}
void MCSProbe::OnCheckInCompleted(uint64 android_id, uint64 secret) {
LOG(INFO) << "Check-in request completion "
<< (android_id ? "success!" : "failure!");
if (!android_id || !secret)
return;
android_id_ = android_id;
secret_ = secret;
LOG(INFO) << "MCS login initiated.";
mcs_client_->Login(android_id_, secret_);
} }
int MCSProbeMain(int argc, char* argv[]) { int MCSProbeMain(int argc, char* argv[]) {
......
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