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

Unified Diff: chrome/browser/sync/notifier/listener/subscribe_task.cc

Issue 194065: Initial commit of sync engine code to browser/sync.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Fixes to gtest include path, reverted syncapi. Created 11 years, 3 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/sync/notifier/listener/subscribe_task.cc
===================================================================
--- chrome/browser/sync/notifier/listener/subscribe_task.cc (revision 0)
+++ chrome/browser/sync/notifier/listener/subscribe_task.cc (revision 0)
@@ -0,0 +1,90 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/sync/notifier/listener/subscribe_task.h"
+
+#include <string>
+
+#include "base/logging.h"
+#include "talk/base/task.h"
+#include "talk/xmllite/qname.h"
+#include "talk/xmllite/xmlelement.h"
+#include "talk/xmpp/constants.h"
+#include "talk/xmpp/xmppclient.h"
+#include "talk/xmpp/xmppengine.h"
+
+namespace browser_sync {
+
+SubscribeTask::SubscribeTask(Task* parent)
+ : XmppTask(parent, buzz::XmppEngine::HL_SINGLE) {
+}
+
+SubscribeTask::~SubscribeTask() {
+}
+
+bool SubscribeTask::HandleStanza(const buzz::XmlElement* stanza) {
+ if (!MatchResponseIq(stanza, GetClient()->jid().BareJid(), task_id()))
+ return false;
+ QueueStanza(stanza);
+ return true;
+}
+
+int SubscribeTask::ProcessStart() {
+ LOG(INFO) << "P2P: Subscription task started.";
+ scoped_ptr<buzz::XmlElement> iq_stanza(NewSubscriptionMessage());
+
+ if (SendStanza(iq_stanza.get()) != buzz::XMPP_RETURN_OK) {
+ SignalStatusUpdate(false);
+ return STATE_DONE;
+ }
+ return STATE_RESPONSE;
+}
+
+int SubscribeTask::ProcessResponse() {
+ LOG(INFO) << "P2P: Subscription response received.";
+ const buzz::XmlElement* stanza = NextStanza();
+ if (stanza == NULL) {
+ return STATE_BLOCKED;
+ }
+ // We've receieved a response to our subscription request.
+ if (stanza->HasAttr(buzz::QN_TYPE) &&
+ stanza->Attr(buzz::QN_TYPE) == buzz::STR_RESULT) {
+ SignalStatusUpdate(true);
+ return STATE_DONE;
+ }
+ // An error response was received.
+ // TODO(brg) : Error handling.
+ SignalStatusUpdate(false);
+ return STATE_DONE;
+}
+
+buzz::XmlElement* SubscribeTask::NewSubscriptionMessage() {
+ static const buzz::QName kQnNotifierGetAll(true, "google:notifier", "getAll");
+ static const buzz::QName kQnNotifierClientActive(true, buzz::STR_EMPTY,
+ "ClientActive");
+ static const buzz::QName kQnBool(true, buzz::STR_EMPTY, "bool");
+ static const std::string kTrueString("true");
+
+ // Create the subscription stanza using the notificaitons protocol.
+ // <iq type='get' from='{fullJid}' to='{bareJid}' id='{#}'>
+ // <gn:getAll xmlns:gn='google:notifier' xmlns=''>
+ // <ClientActive bool='true'/>
+ // </gn:getAll>
+ // </iq>
+ buzz::XmlElement* get_all_request =
+ MakeIq(buzz::STR_GET, GetClient()->jid().BareJid(), task_id());
+
+ buzz::XmlElement* notifier_get =
+ new buzz::XmlElement(kQnNotifierGetAll, true);
+ get_all_request->AddElement(notifier_get);
+
+ buzz::XmlElement* client_active =
+ new buzz::XmlElement(kQnNotifierClientActive, true);
+ client_active->AddAttr(kQnBool, kTrueString);
+ notifier_get->AddElement(client_active);
+
+ return get_all_request;
+}
+
+} // namespace browser_sync
Property changes on: chrome\browser\sync\notifier\listener\subscribe_task.cc
___________________________________________________________________
Added: svn:eol-style
+ LF

Powered by Google App Engine
This is Rietveld 408576698