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

Unified Diff: chrome/browser/services/gcm/gcm_profile_service.cc

Issue 183923006: [GCM] API update to allow only a single sender in registration (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updates based on CR. Changing how the senders/reg_ids are stored to avoid upgrade to multiple sedne… Created 6 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
Index: chrome/browser/services/gcm/gcm_profile_service.cc
diff --git a/chrome/browser/services/gcm/gcm_profile_service.cc b/chrome/browser/services/gcm/gcm_profile_service.cc
index c215192c8df17f593250d6d4f9d6306a0d3b5f73..ec5e0950cc02ee42b535cd77b0027c1cc6fb15f9 100644
--- a/chrome/browser/services/gcm/gcm_profile_service.cc
+++ b/chrome/browser/services/gcm/gcm_profile_service.cc
@@ -46,8 +46,6 @@ namespace gcm {
namespace {
const char kRegistrationKey[] = "gcm.registration";
-const char kSendersKey[] = "senders";
-const char kRegistrationIDKey[] = "reg_id";
checkin_proto::ChromeBuildProto_Platform GetPlatform() {
#if defined(OS_WIN)
@@ -267,7 +265,7 @@ class GCMProfileService::IOWorker
void Load(const base::WeakPtr<GCMProfileService>& service);
void CheckOut();
void Register(const std::string& app_id,
- const std::vector<std::string>& sender_ids,
+ const std::string& sender_id,
const std::string& cert);
void Unregister(const std::string& app_id);
void Send(const std::string& app_id,
@@ -437,11 +435,11 @@ void GCMProfileService::IOWorker::CheckOut() {
void GCMProfileService::IOWorker::Register(
const std::string& app_id,
- const std::vector<std::string>& sender_ids,
+ const std::string& sender_id,
const std::string& cert) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
- gcm_client_->Register(app_id, cert, sender_ids);
+ gcm_client_->Register(app_id, cert, sender_id);
}
void GCMProfileService::IOWorker::Unregister(const std::string& app_id) {
@@ -466,7 +464,7 @@ GCMProfileService::RegistrationInfo::~RegistrationInfo() {
}
bool GCMProfileService::RegistrationInfo::IsValid() const {
- return !sender_ids.empty() && !registration_id.empty();
+ return !sender_id.empty() && !registration_id.empty();
}
// static
@@ -560,11 +558,11 @@ void GCMProfileService::Initialize(
}
void GCMProfileService::Register(const std::string& app_id,
- const std::vector<std::string>& sender_ids,
+ const std::string& sender_id,
const std::string& cert,
RegisterCallback callback) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
- DCHECK(!app_id.empty() && !sender_ids.empty() && !callback.is_null());
+ DCHECK(!app_id.empty() && !sender_id.empty() && !callback.is_null());
// Ensure that check-in has been done.
EnsureLoaded();
@@ -592,16 +590,16 @@ void GCMProfileService::Register(const std::string& app_id,
base::Bind(&GCMProfileService::DoRegister,
weak_ptr_factory_.GetWeakPtr(),
app_id,
- sender_ids,
+ sender_id,
cert));
return;
}
- DoRegister(app_id, sender_ids, cert);
+ DoRegister(app_id, sender_id, cert);
}
void GCMProfileService::DoRegister(const std::string& app_id,
- const std::vector<std::string>& sender_ids,
+ const std::string& sender_id,
const std::string& cert) {
std::map<std::string, RegisterCallback>::iterator callback_iter =
register_callbacks_.find(app_id);
@@ -610,16 +608,12 @@ void GCMProfileService::DoRegister(const std::string& app_id,
return;
}
- // Normalize the sender IDs by making them sorted.
- std::vector<std::string> normalized_sender_ids = sender_ids;
- std::sort(normalized_sender_ids.begin(), normalized_sender_ids.end());
-
// If the same sender ids is provided, return the cached registration ID
// directly.
RegistrationInfoMap::const_iterator registration_info_iter =
registration_info_map_.find(app_id);
if (registration_info_iter != registration_info_map_.end() &&
- registration_info_iter->second.sender_ids == normalized_sender_ids) {
+ registration_info_iter->second.sender_id == sender_id) {
RegisterCallback callback = callback_iter->second;
register_callbacks_.erase(callback_iter);
callback.Run(registration_info_iter->second.registration_id,
@@ -630,7 +624,7 @@ void GCMProfileService::DoRegister(const std::string& app_id,
// Cache the sender IDs. The registration ID will be filled when the
// registration completes.
RegistrationInfo registration_info;
- registration_info.sender_ids = normalized_sender_ids;
+ registration_info.sender_id = sender_id;
registration_info_map_[app_id] = registration_info;
// Save the IDs of all registered apps such that we know what to remove from
@@ -643,7 +637,7 @@ void GCMProfileService::DoRegister(const std::string& app_id,
base::Bind(&GCMProfileService::IOWorker::Register,
io_worker_,
app_id,
- normalized_sender_ids,
+ sender_id,
cert));
}
@@ -996,20 +990,11 @@ void GCMProfileService::WriteRegistrationInfo(const std::string& app_id) {
registration_info_map_.find(app_id);
if (registration_info_iter == registration_info_map_.end())
return;
- const RegistrationInfo& registration_info = registration_info_iter->second;
-
- scoped_ptr<base::ListValue> senders_list(new base::ListValue());
- for (std::vector<std::string>::const_iterator senders_iter =
- registration_info.sender_ids.begin();
- senders_iter != registration_info.sender_ids.end();
- ++senders_iter) {
- senders_list->AppendString(*senders_iter);
- }
+ const RegistrationInfo& registration_info = registration_info_iter->second;
scoped_ptr<base::DictionaryValue> registration_info_dict(
new base::DictionaryValue());
- registration_info_dict->Set(kSendersKey, senders_list.release());
- registration_info_dict->SetString(kRegistrationIDKey,
+ registration_info_dict->SetString(registration_info.sender_id,
registration_info.registration_id);
storage->SetExtensionValue(
@@ -1054,20 +1039,20 @@ bool GCMProfileService::ParsePersistedRegistrationInfo(
if (!value.get() || !value->GetAsDictionary(&dict))
return false;
- if (!dict->GetString(kRegistrationIDKey, &registration_info->registration_id))
- return false;
+ // TODO(fgorski): Remove a DCHECK when more than a single sender is allowed.
+ DCHECK_LE(dict->size(), 1UL);
- const base::ListValue* senders_list = NULL;
- if (!dict->GetList(kSendersKey, &senders_list) || !senders_list->GetSize())
- return false;
- for (size_t i = 0; i < senders_list->GetSize(); ++i) {
- std::string sender;
- if (!senders_list->GetString(i, &sender))
- return false;
- registration_info->sender_ids.push_back(sender);
+ for (base::DictionaryValue::Iterator iter(*dict);
+ !iter.IsAtEnd();
+ iter.Advance()) {
+ registration_info->sender_id = iter.key();
+ if (iter.value().GetAsString(&registration_info->registration_id))
+ return true;
}
- return true;
+ // TODO(fgorski): Switch the return statements when multiple sendres are
jianli 2014/03/04 01:13:53 Probably you only need to add one TODO comment at
+ // allowed.
+ return false;
}
// static
« no previous file with comments | « chrome/browser/services/gcm/gcm_profile_service.h ('k') | chrome/browser/services/gcm/gcm_profile_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698