0

[GCM] Fix mcs_probe credential handling

The mcs probe was no longer consuming credentials passed via command line
switch properly. This fixes it so that if credentials as passed, they're
used, otherwise if the credentials are restored they are used, and lastly
if no credentials are found a checkin is performed.

BUG=284553

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@247248 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
zea@chromium.org
2014-01-27 16:23:55 +00:00
parent 6c98afc0cb
commit 267d49001f
2 changed files with 25 additions and 3 deletions
google_apis/gcm

@ -204,9 +204,10 @@ void MCSClient::Login(uint64 android_id, uint64 security_token) {
security_token_ = security_token;
}
DCHECK(android_id_ != 0 || restored_unackeds_server_ids_.empty());
state_ = CONNECTING;
connection_factory_->Connect();
DCHECK(restored_unackeds_server_ids_.empty());
}
void MCSClient::SendMessage(const MCSMessage& message) {

@ -182,6 +182,7 @@ class MCSProbe {
void BuildNetworkSession();
void LoadCallback(scoped_ptr<GCMStore::LoadResult> load_result);
void UpdateCallback(bool success);
void ErrorCallback();
void OnCheckInCompleted(uint64 android_id, uint64 secret);
@ -282,8 +283,19 @@ void MCSProbe::Start() {
void MCSProbe::LoadCallback(scoped_ptr<GCMStore::LoadResult> load_result) {
DCHECK(load_result->success);
android_id_ = load_result->device_android_id;
secret_ = load_result->device_security_token;
if (android_id_ != 0 && secret_ != 0) {
DVLOG(1) << "Presetting MCS id " << android_id_;
load_result->device_android_id = android_id_;
load_result->device_security_token = secret_;
gcm_store_->SetDeviceCredentials(android_id_,
secret_,
base::Bind(&MCSProbe::UpdateCallback,
base::Unretained(this)));
} else {
android_id_ = load_result->device_android_id;
secret_ = load_result->device_security_token;
DVLOG(1) << "Loaded MCS id " << android_id_;
}
mcs_client_->Initialize(
base::Bind(&MCSProbe::ErrorCallback, base::Unretained(this)),
base::Bind(&MessageReceivedCallback),
@ -291,6 +303,7 @@ void MCSProbe::LoadCallback(scoped_ptr<GCMStore::LoadResult> load_result) {
load_result.Pass());
if (!android_id_ || !secret_) {
DVLOG(1) << "Checkin to generate new MCS credentials.";
CheckIn();
return;
}
@ -298,6 +311,9 @@ void MCSProbe::LoadCallback(scoped_ptr<GCMStore::LoadResult> load_result) {
mcs_client_->Login(android_id_, secret_);
}
void MCSProbe::UpdateCallback(bool success) {
}
void MCSProbe::InitializeNetworkState() {
FILE* log_file = NULL;
if (command_line_.HasSwitch(kLogFileSwitch)) {
@ -394,6 +410,11 @@ void MCSProbe::OnCheckInCompleted(uint64 android_id, uint64 secret) {
android_id_ = android_id;
secret_ = secret;
gcm_store_->SetDeviceCredentials(android_id_,
secret_,
base::Bind(&MCSProbe::UpdateCallback,
base::Unretained(this)));
LOG(INFO) << "MCS login initiated.";
mcs_client_->Login(android_id_, secret_);
}