• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #include "sync/notifier/push_client_channel.h"
6 
7 #include "base/stl_util.h"
8 #include "google/cacheinvalidation/client_gateway.pb.h"
9 #include "jingle/notifier/listener/push_client.h"
10 
11 namespace syncer {
12 
13 namespace {
14 
15 const char kBotJid[] = "tango@bot.talk.google.com";
16 const char kChannelName[] = "tango_raw";
17 
18 }  // namespace
19 
PushClientChannel(scoped_ptr<notifier::PushClient> push_client)20 PushClientChannel::PushClientChannel(
21     scoped_ptr<notifier::PushClient> push_client)
22     : push_client_(push_client.Pass()) {
23   push_client_->AddObserver(this);
24   notifier::Subscription subscription;
25   subscription.channel = kChannelName;
26   subscription.from = "";
27   notifier::SubscriptionList subscriptions;
28   subscriptions.push_back(subscription);
29   push_client_->UpdateSubscriptions(subscriptions);
30 }
31 
~PushClientChannel()32 PushClientChannel::~PushClientChannel() {
33   push_client_->RemoveObserver(this);
34 }
35 
UpdateCredentials(const std::string & email,const std::string & token)36 void PushClientChannel::UpdateCredentials(
37     const std::string& email, const std::string& token) {
38   push_client_->UpdateCredentials(email, token);
39 }
40 
SendEncodedMessage(const std::string & encoded_message)41 void PushClientChannel::SendEncodedMessage(const std::string& encoded_message) {
42   notifier::Recipient recipient;
43   recipient.to = kBotJid;
44   notifier::Notification notification;
45   notification.channel = kChannelName;
46   notification.recipients.push_back(recipient);
47   notification.data = encoded_message;
48   push_client_->SendNotification(notification);
49 }
50 
OnNotificationsEnabled()51 void PushClientChannel::OnNotificationsEnabled() {
52   NotifyStateChange(INVALIDATIONS_ENABLED);
53 }
54 
OnNotificationsDisabled(notifier::NotificationsDisabledReason reason)55 void PushClientChannel::OnNotificationsDisabled(
56     notifier::NotificationsDisabledReason reason) {
57   NotifyStateChange(FromNotifierReason(reason));
58 }
59 
OnIncomingNotification(const notifier::Notification & notification)60 void PushClientChannel::OnIncomingNotification(
61     const notifier::Notification& notification) {
62   DeliverIncomingMessage(notification.data);
63 }
64 
65 }  // namespace syncer
66