summaryrefslogtreecommitdiffstats
path: root/google_apis/gcm
diff options
context:
space:
mode:
authorjianli@chromium.org <jianli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-10 22:05:33 +0000
committerjianli@chromium.org <jianli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-10 22:05:33 +0000
commit128078a052bc335fd28729562f3781acb5ef103d (patch)
treebe07fa9f251c9a29e25cb87a572b39421ef24338 /google_apis/gcm
parente5379697de29afd17c92a8ad29dd2e3e920523b2 (diff)
downloadchromium_src-128078a052bc335fd28729562f3781acb5ef103d.zip
chromium_src-128078a052bc335fd28729562f3781acb5ef103d.tar.gz
chromium_src-128078a052bc335fd28729562f3781acb5ef103d.tar.bz2
[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
Diffstat (limited to 'google_apis/gcm')
-rw-r--r--google_apis/gcm/engine/connection_factory_impl.cc3
-rw-r--r--google_apis/gcm/tools/mcs_probe.cc51
2 files changed, 49 insertions, 5 deletions
diff --git a/google_apis/gcm/engine/connection_factory_impl.cc b/google_apis/gcm/engine/connection_factory_impl.cc
index b9e7f4f..bc416f8 100644
--- a/google_apis/gcm/engine/connection_factory_impl.cc
+++ b/google_apis/gcm/engine/connection_factory_impl.cc
@@ -99,7 +99,6 @@ ConnectionHandler* ConnectionFactoryImpl::GetConnectionHandler() const {
void ConnectionFactoryImpl::Connect() {
DCHECK(connection_handler_);
- DCHECK(!IsEndpointReachable());
connecting_ = true;
if (backoff_entry_->ShouldRejectRequest()) {
@@ -166,8 +165,6 @@ void ConnectionFactoryImpl::OnIPAddressChanged() {
}
void ConnectionFactoryImpl::ConnectImpl() {
- DCHECK(!IsEndpointReachable());
-
if (socket_handle_.socket() && socket_handle_.socket()->IsConnected())
socket_handle_.socket()->Disconnect();
socket_handle_.Reset();
diff --git a/google_apis/gcm/tools/mcs_probe.cc b/google_apis/gcm/tools/mcs_probe.cc
index 3170aa2..de1e4b8 100644
--- a/google_apis/gcm/tools/mcs_probe.cc
+++ b/google_apis/gcm/tools/mcs_probe.cc
@@ -24,6 +24,7 @@
#include "base/values.h"
#include "google_apis/gcm/base/mcs_message.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/gcm_store_impl.h"
#include "google_apis/gcm/engine/mcs_client.h"
@@ -50,6 +51,10 @@
namespace gcm {
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.
const char kMCSServerHost[] = "mtalk.google.com";
const uint16 kMCSServerPort = 5228;
@@ -166,12 +171,14 @@ class MCSProbe {
uint64 secret() const { return secret_; }
private:
+ void CheckIn();
void InitializeNetworkState();
void BuildNetworkSession();
void InitializationCallback(bool success,
uint64 restored_android_id,
uint64 restored_security_token);
+ void OnCheckInCompleted(uint64 android_id, uint64 secret);
base::DefaultClock clock_;
@@ -201,6 +208,7 @@ class MCSProbe {
scoped_ptr<GCMStore> gcm_store_;
scoped_ptr<MCSClient> mcs_client_;
+ scoped_ptr<CheckinRequest> checkin_request_;
scoped_ptr<ConnectionFactoryImpl> connection_factory_;
@@ -340,11 +348,50 @@ void MCSProbe::InitializationCallback(bool success,
uint64 restored_security_token) {
LOG(INFO) << "Initialization " << (success ? "success!" : "failure!");
if (restored_android_id && restored_security_token) {
+ LOG(INFO) << "Restored device check-in info.";
android_id_ = restored_android_id;
secret_ = restored_security_token;
}
- if (success)
- mcs_client_->Login(android_id_, secret_);
+ if (!success)
+ 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[]) {