Chromium Code Reviews| 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..17bbbd1683977c101231da43847c4b72dd427a5c 100644 |
| --- a/chrome/browser/services/gcm/gcm_profile_service.cc |
| +++ b/chrome/browser/services/gcm/gcm_profile_service.cc |
| @@ -46,7 +46,7 @@ namespace gcm { |
| namespace { |
| const char kRegistrationKey[] = "gcm.registration"; |
| -const char kSendersKey[] = "senders"; |
| +const char kSenderKey[] = "sender"; |
| const char kRegistrationIDKey[] = "reg_id"; |
| checkin_proto::ChromeBuildProto_Platform GetPlatform() { |
| @@ -267,7 +267,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 +437,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 +466,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 +560,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 +592,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 +610,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 +626,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 +639,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,19 +992,12 @@ 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(kSenderKey, |
|
jianli
2014/03/03 21:29:31
Do we want to make it be compatible with future mu
fgorski
2014/03/03 23:14:16
Done. Modified the write and read code to simply s
|
| + registration_info.sender_id); |
| registration_info_dict->SetString(kRegistrationIDKey, |
| registration_info.registration_id); |
| @@ -1057,15 +1046,8 @@ bool GCMProfileService::ParsePersistedRegistrationInfo( |
| if (!dict->GetString(kRegistrationIDKey, ®istration_info->registration_id)) |
| return false; |
| - const base::ListValue* senders_list = NULL; |
| - if (!dict->GetList(kSendersKey, &senders_list) || !senders_list->GetSize()) |
| + if (!dict->GetString(kSenderKey, ®istration_info->sender_id)) |
| 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); |
| - } |
| return true; |
| } |