Commit 47869f0c authored by fgorski's avatar fgorski Committed by Commit bot

Adding Send to Gaia ID feature

* Exposing MessageReceived as virtual on GCMDriver so that it can be
called from outside of GCMClientImpl (through IOWorker)
* Adding handling of gcmb key to GCMAccountMapper
* Adding a test for dispatching the message from GCMAccountMapper

BUG=462053
R=zea@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#318537}
parent 495ad5a3
......@@ -29,6 +29,9 @@ const char kTokenMessageKey[] = "t";
const char kAccountMessageKey[] = "a";
const char kRemoveAccountKey[] = "r";
const char kRemoveAccountValue[] = "1";
// Use to handle send to Gaia ID scenario:
const char kGCMSendToGaiaIdAppIdKey[] = "gcmb";
std::string GenerateMessageID() {
return base::GenerateGUID();
......@@ -48,11 +51,12 @@ GCMAccountMapper::GCMAccountMapper(GCMDriver* gcm_driver)
GCMAccountMapper::~GCMAccountMapper() {
}
void GCMAccountMapper::Initialize(
const std::vector<AccountMapping>& account_mappings) {
void GCMAccountMapper::Initialize(const AccountMappings& account_mappings,
const DispatchMessageCallback& callback) {
DCHECK(!initialized_);
initialized_ = true;
accounts_ = account_mappings;
dispatch_message_callback_ = callback;
GetRegistration();
}
......@@ -141,11 +145,36 @@ void GCMAccountMapper::ShutdownHandler() {
initialized_ = false;
accounts_.clear();
registration_id_.clear();
dispatch_message_callback_.Reset();
}
void GCMAccountMapper::OnMessage(const std::string& app_id,
const GCMClient::IncomingMessage& message) {
// Account message does not expect messages right now.
DCHECK_EQ(app_id, kGCMAccountMapperAppId);
// TODO(fgorski): Report Send to Gaia ID failures using UMA.
if (dispatch_message_callback_.is_null()) {
DVLOG(1) << "dispatch_message_callback_ missing in GCMAccountMapper";
return;
}
GCMClient::MessageData::const_iterator it =
message.data.find(kGCMSendToGaiaIdAppIdKey);
if (it == message.data.end()) {
DVLOG(1) << "Send to Gaia ID failure: Embedded app ID missing.";
return;
}
std::string embedded_app_id = it->second;
if (embedded_app_id.empty()) {
DVLOG(1) << "Send to Gaia ID failure: Embedded app ID is empty.";
return;
}
// Ensuring the message does not carry the embedded app ID.
GCMClient::IncomingMessage new_message = message;
new_message.data.erase(new_message.data.find(kGCMSendToGaiaIdAppIdKey));
dispatch_message_callback_.Run(embedded_app_id, new_message);
}
void GCMAccountMapper::OnMessagesDeleted(const std::string& app_id) {
......
......@@ -8,6 +8,7 @@
#include <string>
#include <vector>
#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
......@@ -29,11 +30,15 @@ class GCMAccountMapper : public GCMAppHandler {
public:
// List of account mappings.
typedef std::vector<AccountMapping> AccountMappings;
typedef base::Callback<void(const std::string& app_id,
const GCMClient::IncomingMessage& message)>
DispatchMessageCallback;
explicit GCMAccountMapper(GCMDriver* gcm_driver);
~GCMAccountMapper() override;
void Initialize(const AccountMappings& account_mappings);
void Initialize(const AccountMappings& account_mappings,
const DispatchMessageCallback& callback);
// Called by AccountTracker, when a new list of account tokens is available.
// This will cause a refresh of account mappings and sending updates to GCM.
......@@ -102,6 +107,9 @@ class GCMAccountMapper : public GCMAppHandler {
// GCMDriver owns GCMAccountMapper.
GCMDriver* gcm_driver_;
// Callback to GCMDriver to dispatch messages sent to Gaia ID.
DispatchMessageCallback dispatch_message_callback_;
// Clock for timestamping status changes.
scoped_ptr<base::Clock> clock_;
......
......@@ -797,7 +797,9 @@ void GCMDriverDesktop::GCMClientReady(
last_token_fetch_time_ = last_token_fetch_time;
GCMDriver::AddAppHandler(kGCMAccountMapperAppId, account_mapper_.get());
account_mapper_->Initialize(account_mappings);
account_mapper_->Initialize(account_mappings,
base::Bind(&GCMDriverDesktop::MessageReceived,
weak_ptr_factory_.GetWeakPtr()));
delayed_task_controller_->SetReady();
}
......
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