Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Unified Diff: components/gcm_driver/gcm_account_mapper.cc

Issue 961533002: Adding Send to Gaia ID feature (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing feedback Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/gcm_driver/gcm_account_mapper.h ('k') | components/gcm_driver/gcm_account_mapper_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/gcm_driver/gcm_account_mapper.cc
diff --git a/components/gcm_driver/gcm_account_mapper.cc b/components/gcm_driver/gcm_account_mapper.cc
index 820ced04139383aeaba717a3617c7bc0e90756d2..7caeaba8597b655c2e0704fac5898ead0519ba71 100644
--- a/components/gcm_driver/gcm_account_mapper.cc
+++ b/components/gcm_driver/gcm_account_mapper.cc
@@ -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) {
« no previous file with comments | « components/gcm_driver/gcm_account_mapper.h ('k') | components/gcm_driver/gcm_account_mapper_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698