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

Side by Side Diff: chrome/browser/sync/notifier/cache_invalidation_packet_handler.cc

Issue 7822008: [Sync] Remove static initializers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync to head Created 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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"
(...skipping 10 matching lines...) Expand all
21 #include "talk/xmpp/xmppclient.h" 21 #include "talk/xmpp/xmppclient.h"
22 #include "talk/xmpp/xmpptask.h" 22 #include "talk/xmpp/xmpptask.h"
23 23
24 namespace sync_notifier { 24 namespace sync_notifier {
25 25
26 namespace { 26 namespace {
27 27
28 const char kBotJid[] = "tango@bot.talk.google.com"; 28 const char kBotJid[] = "tango@bot.talk.google.com";
29 const char kServiceUrl[] = "http://www.google.com/chrome/sync"; 29 const char kServiceUrl[] = "http://www.google.com/chrome/sync";
30 30
31 const buzz::QName kQnData("google:notifier", "data"); 31 buzz::QName GetQnData() { return buzz::QName("google:notifier", "data"); }
32 const buzz::QName kQnSeq("", "seq"); 32 buzz::QName GetQnSeq() { return buzz::QName("", "seq"); }
33 const buzz::QName kQnSid("", "sid"); 33 buzz::QName GetQnSid() { return buzz::QName("", "sid"); }
34 const buzz::QName kQnServiceUrl("", "serviceUrl"); 34 buzz::QName GetQnServiceUrl() { return buzz::QName("", "serviceUrl"); }
35 const buzz::QName kQnProtocolVersion("", "protocolVersion"); 35 buzz::QName GetQnProtocolVersion() {
36 const buzz::QName kQnChannelContext("", "channelContext"); 36 return buzz::QName("", "protocolVersion");
37 }
38 buzz::QName GetQnChannelContext() {
39 return buzz::QName("", "channelContext");
40 }
37 41
38 // TODO(akalin): Move these task classes out so that they can be 42 // TODO(akalin): Move these task classes out so that they can be
39 // unit-tested. This'll probably be done easier once we consolidate 43 // unit-tested. This'll probably be done easier once we consolidate
40 // all the packet sending/receiving classes. 44 // all the packet sending/receiving classes.
41 45
42 // A task that listens for ClientInvalidation messages and calls the 46 // A task that listens for ClientInvalidation messages and calls the
43 // given callback on them. 47 // given callback on them.
44 class CacheInvalidationListenTask : public buzz::XmppTask { 48 class CacheInvalidationListenTask : public buzz::XmppTask {
45 public: 49 public:
46 // Takes ownership of callback. 50 // Takes ownership of callback.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 return true; 91 return true;
88 } 92 }
89 VLOG(2) << "Stanza skipped"; 93 VLOG(2) << "Stanza skipped";
90 return false; 94 return false;
91 } 95 }
92 96
93 private: 97 private:
94 bool IsValidCacheInvalidationIqPacket(const buzz::XmlElement* stanza) { 98 bool IsValidCacheInvalidationIqPacket(const buzz::XmlElement* stanza) {
95 // We deliberately minimize the verification we do here: see 99 // We deliberately minimize the verification we do here: see
96 // http://crbug.com/71285 . 100 // http://crbug.com/71285 .
97 return MatchRequestIq(stanza, buzz::STR_SET, kQnData); 101 return MatchRequestIq(stanza, buzz::STR_SET, GetQnData());
98 } 102 }
99 103
100 bool GetCacheInvalidationIqPacketData(const buzz::XmlElement* stanza, 104 bool GetCacheInvalidationIqPacketData(const buzz::XmlElement* stanza,
101 std::string* data) { 105 std::string* data) {
102 DCHECK(IsValidCacheInvalidationIqPacket(stanza)); 106 DCHECK(IsValidCacheInvalidationIqPacket(stanza));
103 const buzz::XmlElement* cache_invalidation_iq_packet = 107 const buzz::XmlElement* cache_invalidation_iq_packet =
104 stanza->FirstNamed(kQnData); 108 stanza->FirstNamed(GetQnData());
105 if (!cache_invalidation_iq_packet) { 109 if (!cache_invalidation_iq_packet) {
106 LOG(ERROR) << "Could not find cache invalidation IQ packet element"; 110 LOG(ERROR) << "Could not find cache invalidation IQ packet element";
107 return false; 111 return false;
108 } 112 }
109 // Look for a channelContext attribute in the content of the stanza. If 113 // Look for a channelContext attribute in the content of the stanza. If
110 // present, remember it so it can be echoed back. 114 // present, remember it so it can be echoed back.
111 if (cache_invalidation_iq_packet->HasAttr(kQnChannelContext)) { 115 if (cache_invalidation_iq_packet->HasAttr(GetQnChannelContext())) {
112 context_change_callback_->Run( 116 context_change_callback_->Run(
113 cache_invalidation_iq_packet->Attr(kQnChannelContext)); 117 cache_invalidation_iq_packet->Attr(GetQnChannelContext()));
114 } 118 }
115 *data = cache_invalidation_iq_packet->BodyText(); 119 *data = cache_invalidation_iq_packet->BodyText();
116 return true; 120 return true;
117 } 121 }
118 122
119 std::string* channel_context_; 123 std::string* channel_context_;
120 scoped_ptr<Callback1<const std::string&>::Type> callback_; 124 scoped_ptr<Callback1<const std::string&>::Type> callback_;
121 scoped_ptr<Callback1<const std::string&>::Type> context_change_callback_; 125 scoped_ptr<Callback1<const std::string&>::Type> context_change_callback_;
122 DISALLOW_COPY_AND_ASSIGN(CacheInvalidationListenTask); 126 DISALLOW_COPY_AND_ASSIGN(CacheInvalidationListenTask);
123 }; 127 };
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 } 184 }
181 185
182 private: 186 private:
183 static buzz::XmlElement* MakeCacheInvalidationIqPacket( 187 static buzz::XmlElement* MakeCacheInvalidationIqPacket(
184 const buzz::Jid& to_jid, 188 const buzz::Jid& to_jid,
185 const std::string& task_id, 189 const std::string& task_id,
186 const std::string& msg, 190 const std::string& msg,
187 int seq, const std::string& sid, const std::string& channel_context) { 191 int seq, const std::string& sid, const std::string& channel_context) {
188 buzz::XmlElement* iq = MakeIq(buzz::STR_SET, to_jid, task_id); 192 buzz::XmlElement* iq = MakeIq(buzz::STR_SET, to_jid, task_id);
189 buzz::XmlElement* cache_invalidation_iq_packet = 193 buzz::XmlElement* cache_invalidation_iq_packet =
190 new buzz::XmlElement(kQnData, true); 194 new buzz::XmlElement(GetQnData(), true);
191 iq->AddElement(cache_invalidation_iq_packet); 195 iq->AddElement(cache_invalidation_iq_packet);
192 cache_invalidation_iq_packet->SetAttr(kQnSeq, base::IntToString(seq)); 196 cache_invalidation_iq_packet->SetAttr(GetQnSeq(), base::IntToString(seq));
193 cache_invalidation_iq_packet->SetAttr(kQnSid, sid); 197 cache_invalidation_iq_packet->SetAttr(GetQnSid(), sid);
194 cache_invalidation_iq_packet->SetAttr(kQnServiceUrl, kServiceUrl); 198 cache_invalidation_iq_packet->SetAttr(GetQnServiceUrl(), kServiceUrl);
195 cache_invalidation_iq_packet->SetAttr( 199 cache_invalidation_iq_packet->SetAttr(
196 kQnProtocolVersion, MakeProtocolVersion()); 200 GetQnProtocolVersion(), MakeProtocolVersion());
197 if (!channel_context.empty()) { 201 if (!channel_context.empty()) {
198 cache_invalidation_iq_packet->SetAttr(kQnChannelContext, 202 cache_invalidation_iq_packet->SetAttr(GetQnChannelContext(),
199 channel_context); 203 channel_context);
200 } 204 }
201 cache_invalidation_iq_packet->SetBodyText(msg); 205 cache_invalidation_iq_packet->SetBodyText(msg);
202 return iq; 206 return iq;
203 } 207 }
204 208
205 const buzz::Jid to_jid_; 209 const buzz::Jid to_jid_;
206 std::string msg_; 210 std::string msg_;
207 int seq_; 211 int seq_;
208 std::string sid_; 212 std::string sid_;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 incoming_receiver_->Run(decoded_message); 282 incoming_receiver_->Run(decoded_message);
279 } 283 }
280 284
281 void CacheInvalidationPacketHandler::HandleChannelContextChange( 285 void CacheInvalidationPacketHandler::HandleChannelContextChange(
282 const std::string& context) { 286 const std::string& context) {
283 DCHECK(non_thread_safe_.CalledOnValidThread()); 287 DCHECK(non_thread_safe_.CalledOnValidThread());
284 channel_context_ = context; 288 channel_context_ = context;
285 } 289 }
286 290
287 } // namespace sync_notifier 291 } // namespace sync_notifier
OLDNEW
« no previous file with comments | « chrome/browser/sync/internal_api/syncapi_unittest.cc ('k') | chrome/browser/sync/syncable/syncable_id.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698