| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/sync/notifier/cache_invalidation_packet_handler.h" | 5 #include "chrome/browser/sync/notifier/cache_invalidation_packet_handler.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/compiler_specific.h" |
| 11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 12 #include "base/rand_util.h" | 13 #include "base/rand_util.h" |
| 13 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
| 14 //#include "base/string_util.h" | 15 //#include "base/string_util.h" |
| 15 #include "chrome/browser/sync/sync_constants.h" | 16 #include "chrome/browser/sync/sync_constants.h" |
| 16 #include "google/cacheinvalidation/invalidation-client.h" | 17 #include "google/cacheinvalidation/invalidation-client.h" |
| 17 #include "jingle/notifier/listener/xml_element_util.h" | 18 #include "jingle/notifier/listener/xml_element_util.h" |
| 18 #include "talk/xmpp/constants.h" | 19 #include "talk/xmpp/constants.h" |
| 19 #include "talk/xmpp/jid.h" | 20 #include "talk/xmpp/jid.h" |
| 20 #include "talk/xmpp/xmppclient.h" | 21 #include "talk/xmpp/xmppclient.h" |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 std::string MakeSid() { | 191 std::string MakeSid() { |
| 191 uint64 sid = base::RandUint64(); | 192 uint64 sid = base::RandUint64(); |
| 192 return std::string("chrome-sync-") + base::Uint64ToString(sid); | 193 return std::string("chrome-sync-") + base::Uint64ToString(sid); |
| 193 } | 194 } |
| 194 | 195 |
| 195 } // namespace | 196 } // namespace |
| 196 | 197 |
| 197 CacheInvalidationPacketHandler::CacheInvalidationPacketHandler( | 198 CacheInvalidationPacketHandler::CacheInvalidationPacketHandler( |
| 198 buzz::XmppClient* xmpp_client, | 199 buzz::XmppClient* xmpp_client, |
| 199 invalidation::InvalidationClient* invalidation_client) | 200 invalidation::InvalidationClient* invalidation_client) |
| 200 : xmpp_client_(xmpp_client), | 201 : scoped_callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 202 xmpp_client_(xmpp_client), |
| 201 invalidation_client_(invalidation_client), | 203 invalidation_client_(invalidation_client), |
| 202 seq_(0), | 204 seq_(0), |
| 203 sid_(MakeSid()) { | 205 sid_(MakeSid()) { |
| 204 CHECK(xmpp_client_); | 206 CHECK(xmpp_client_); |
| 205 CHECK(invalidation_client_); | 207 CHECK(invalidation_client_); |
| 206 invalidation::NetworkEndpoint* network_endpoint = | 208 invalidation::NetworkEndpoint* network_endpoint = |
| 207 invalidation_client_->network_endpoint(); | 209 invalidation_client_->network_endpoint(); |
| 208 CHECK(network_endpoint); | 210 CHECK(network_endpoint); |
| 209 network_endpoint->RegisterOutboundListener( | 211 network_endpoint->RegisterOutboundListener( |
| 210 invalidation::NewPermanentCallback( | 212 scoped_callback_factory_.NewCallback( |
| 211 this, | |
| 212 &CacheInvalidationPacketHandler::HandleOutboundPacket)); | 213 &CacheInvalidationPacketHandler::HandleOutboundPacket)); |
| 213 // Owned by xmpp_client. | 214 // Owned by xmpp_client. |
| 214 CacheInvalidationListenTask* listen_task = | 215 CacheInvalidationListenTask* listen_task = |
| 215 new CacheInvalidationListenTask( | 216 new CacheInvalidationListenTask( |
| 216 xmpp_client, NewCallback( | 217 xmpp_client, scoped_callback_factory_.NewCallback( |
| 217 this, &CacheInvalidationPacketHandler::HandleInboundPacket)); | 218 &CacheInvalidationPacketHandler::HandleInboundPacket)); |
| 218 listen_task->Start(); | 219 listen_task->Start(); |
| 219 } | 220 } |
| 220 | 221 |
| 221 CacheInvalidationPacketHandler::~CacheInvalidationPacketHandler() { | 222 CacheInvalidationPacketHandler::~CacheInvalidationPacketHandler() { |
| 222 invalidation::NetworkEndpoint* network_endpoint = | 223 invalidation::NetworkEndpoint* network_endpoint = |
| 223 invalidation_client_->network_endpoint(); | 224 invalidation_client_->network_endpoint(); |
| 224 CHECK(network_endpoint); | 225 CHECK(network_endpoint); |
| 225 network_endpoint->RegisterOutboundListener(NULL); | 226 network_endpoint->RegisterOutboundListener(NULL); |
| 226 } | 227 } |
| 227 | 228 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 253 std::string decoded_message; | 254 std::string decoded_message; |
| 254 if (!base::Base64Decode(packet, &decoded_message)) { | 255 if (!base::Base64Decode(packet, &decoded_message)) { |
| 255 LOG(ERROR) << "Could not base64-decode received message: " | 256 LOG(ERROR) << "Could not base64-decode received message: " |
| 256 << packet; | 257 << packet; |
| 257 return; | 258 return; |
| 258 } | 259 } |
| 259 network_endpoint->HandleInboundMessage(decoded_message); | 260 network_endpoint->HandleInboundMessage(decoded_message); |
| 260 } | 261 } |
| 261 | 262 |
| 262 } // namespace sync_notifier | 263 } // namespace sync_notifier |
| OLD | NEW |