| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/api/push_messaging/push_messaging_invalidati
on_handler.h" | 5 #include "chrome/browser/extensions/api/push_messaging/push_messaging_invalidati
on_handler.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/strings/string_split.h" | 11 #include "base/strings/string_split.h" |
| 12 #include "chrome/browser/extensions/api/push_messaging/push_messaging_invalidati
on_handler_delegate.h" | 12 #include "chrome/browser/extensions/api/push_messaging/push_messaging_invalidati
on_handler_delegate.h" |
| 13 #include "chrome/browser/invalidation/invalidation_service.h" | 13 #include "chrome/browser/invalidation/invalidation_service.h" |
| 14 #include "chrome/common/extensions/extension.h" | 14 #include "chrome/common/extensions/extension.h" |
| 15 #include "google/cacheinvalidation/types.pb.h" | 15 #include "google/cacheinvalidation/types.pb.h" |
| 16 #include "sync/notifier/object_id_invalidation_map.h" |
| 16 | 17 |
| 17 namespace extensions { | 18 namespace extensions { |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 const int kNumberOfSubchannels = 4; | 22 const int kNumberOfSubchannels = 4; |
| 22 | 23 |
| 23 // Chrome push messaging object IDs currently have the following format: | 24 // Chrome push messaging object IDs currently have the following format: |
| 24 // <format type>/<GAIA ID>/<extension ID>/<subchannel> | 25 // <format type>/<GAIA ID>/<extension ID>/<subchannel> |
| 25 // <format type> must be 'U', and <GAIA ID> is handled server-side so the client | 26 // <format type> must be 'U', and <GAIA ID> is handled server-side so the client |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 | 118 |
| 118 void PushMessagingInvalidationHandler::OnInvalidatorStateChange( | 119 void PushMessagingInvalidationHandler::OnInvalidatorStateChange( |
| 119 syncer::InvalidatorState state) { | 120 syncer::InvalidatorState state) { |
| 120 DCHECK(thread_checker_.CalledOnValidThread()); | 121 DCHECK(thread_checker_.CalledOnValidThread()); |
| 121 // Nothing to do. | 122 // Nothing to do. |
| 122 } | 123 } |
| 123 | 124 |
| 124 void PushMessagingInvalidationHandler::OnIncomingInvalidation( | 125 void PushMessagingInvalidationHandler::OnIncomingInvalidation( |
| 125 const syncer::ObjectIdInvalidationMap& invalidation_map) { | 126 const syncer::ObjectIdInvalidationMap& invalidation_map) { |
| 126 DCHECK(thread_checker_.CalledOnValidThread()); | 127 DCHECK(thread_checker_.CalledOnValidThread()); |
| 127 for (syncer::ObjectIdInvalidationMap::const_iterator it = | 128 syncer::ObjectIdSet ids = invalidation_map.GetObjectIds(); |
| 128 invalidation_map.begin(); it != invalidation_map.end(); ++it) { | 129 for (syncer::ObjectIdSet::const_iterator it = ids.begin(); |
| 129 service_->AcknowledgeInvalidation(it->first, it->second.ack_handle); | 130 it != ids.end(); ++it) { |
| 131 const syncer::OrderedInvalidationList& list = |
| 132 invalidation_map.ForObject(*it); |
| 133 const syncer::Invalidation& invalidation = list.back(); |
| 134 service_->AcknowledgeInvalidation(*it, invalidation.GetAckHandle()); |
| 135 |
| 136 std::string payload; |
| 137 if (invalidation.IsUnknownVersion()) { |
| 138 payload = std::string(); |
| 139 } else { |
| 140 payload = list.back().GetPayload(); |
| 141 } |
| 130 | 142 |
| 131 syncer::ObjectIdSet::iterator suppressed_id = | 143 syncer::ObjectIdSet::iterator suppressed_id = |
| 132 suppressed_ids_.find(it->first); | 144 suppressed_ids_.find(*it); |
| 133 if (suppressed_id != suppressed_ids_.end()) { | 145 if (suppressed_id != suppressed_ids_.end()) { |
| 134 suppressed_ids_.erase(suppressed_id); | 146 suppressed_ids_.erase(suppressed_id); |
| 135 continue; | 147 continue; |
| 136 } | 148 } |
| 137 DVLOG(2) << "Incoming push message, id is: " | 149 DVLOG(2) << "Incoming push message, id is: " |
| 138 << syncer::ObjectIdToString(it->first) | 150 << syncer::ObjectIdToString(*it) |
| 139 << " and payload is:" << it->second.payload; | 151 << " and payload is:" << payload; |
| 140 | 152 |
| 141 std::string extension_id; | 153 std::string extension_id; |
| 142 int subchannel; | 154 int subchannel; |
| 143 if (ObjectIdToExtensionAndSubchannel(it->first, | 155 if (ObjectIdToExtensionAndSubchannel(*it, &extension_id, &subchannel)) { |
| 144 &extension_id, | |
| 145 &subchannel)) { | |
| 146 DVLOG(2) << "Sending push message to reciever, extension is " | 156 DVLOG(2) << "Sending push message to reciever, extension is " |
| 147 << extension_id << ", subchannel is " << subchannel | 157 << extension_id << ", subchannel is " << subchannel |
| 148 << ", and payload is " << it->second.payload; | 158 << ", and payload is " << payload; |
| 149 delegate_->OnMessage(extension_id, subchannel, it->second.payload); | 159 delegate_->OnMessage(extension_id, subchannel, payload); |
| 150 } | 160 } |
| 151 } | 161 } |
| 152 } | 162 } |
| 153 | 163 |
| 154 void PushMessagingInvalidationHandler::UpdateRegistrations() { | 164 void PushMessagingInvalidationHandler::UpdateRegistrations() { |
| 155 syncer::ObjectIdSet ids; | 165 syncer::ObjectIdSet ids; |
| 156 for (std::set<std::string>::const_iterator it = | 166 for (std::set<std::string>::const_iterator it = |
| 157 registered_extensions_.begin(); it != registered_extensions_.end(); | 167 registered_extensions_.begin(); it != registered_extensions_.end(); |
| 158 ++it) { | 168 ++it) { |
| 159 const syncer::ObjectIdSet& object_ids = ExtensionIdToObjectIds(*it); | 169 const syncer::ObjectIdSet& object_ids = ExtensionIdToObjectIds(*it); |
| 160 ids.insert(object_ids.begin(), object_ids.end()); | 170 ids.insert(object_ids.begin(), object_ids.end()); |
| 161 } | 171 } |
| 162 service_->UpdateRegisteredInvalidationIds(this, ids); | 172 service_->UpdateRegisteredInvalidationIds(this, ids); |
| 163 } | 173 } |
| 164 | 174 |
| 165 } // namespace extensions | 175 } // namespace extensions |
| OLD | NEW |