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

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

Issue 3448028: Implemented VLOG() et al. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Addressed evmar's comments Created 10 years, 2 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
« no previous file with comments | « base/vlog_unittest.cc ('k') | chrome/browser/sync/notifier/chrome_invalidation_client.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 28 matching lines...) Expand all
39 // given callback on them. 39 // given callback on them.
40 class CacheInvalidationListenTask : public buzz::XmppTask { 40 class CacheInvalidationListenTask : public buzz::XmppTask {
41 public: 41 public:
42 // Takes ownership of callback. 42 // Takes ownership of callback.
43 CacheInvalidationListenTask(Task* parent, 43 CacheInvalidationListenTask(Task* parent,
44 Callback1<const std::string&>::Type* callback) 44 Callback1<const std::string&>::Type* callback)
45 : XmppTask(parent, buzz::XmppEngine::HL_TYPE), callback_(callback) {} 45 : XmppTask(parent, buzz::XmppEngine::HL_TYPE), callback_(callback) {}
46 virtual ~CacheInvalidationListenTask() {} 46 virtual ~CacheInvalidationListenTask() {}
47 47
48 virtual int ProcessStart() { 48 virtual int ProcessStart() {
49 LOG(INFO) << "CacheInvalidationListenTask started"; 49 VLOG(2) << "CacheInvalidationListenTask started";
50 return STATE_RESPONSE; 50 return STATE_RESPONSE;
51 } 51 }
52 52
53 virtual int ProcessResponse() { 53 virtual int ProcessResponse() {
54 const buzz::XmlElement* stanza = NextStanza(); 54 const buzz::XmlElement* stanza = NextStanza();
55 if (stanza == NULL) { 55 if (stanza == NULL) {
56 LOG(INFO) << "CacheInvalidationListenTask blocked"; 56 VLOG(2) << "CacheInvalidationListenTask blocked";
57 return STATE_BLOCKED; 57 return STATE_BLOCKED;
58 } 58 }
59 LOG(INFO) << "CacheInvalidationListenTask response received"; 59 VLOG(2) << "CacheInvalidationListenTask response received";
60 std::string data; 60 std::string data;
61 if (GetCacheInvalidationIqPacketData(stanza, &data)) { 61 if (GetCacheInvalidationIqPacketData(stanza, &data)) {
62 callback_->Run(data); 62 callback_->Run(data);
63 } else { 63 } else {
64 LOG(ERROR) << "Could not get packet data"; 64 LOG(ERROR) << "Could not get packet data";
65 } 65 }
66 // Acknowledge receipt of the iq to the buzz server. 66 // Acknowledge receipt of the iq to the buzz server.
67 // TODO(akalin): Send an error response for malformed packets. 67 // TODO(akalin): Send an error response for malformed packets.
68 scoped_ptr<buzz::XmlElement> response_stanza(MakeIqResult(stanza)); 68 scoped_ptr<buzz::XmlElement> response_stanza(MakeIqResult(stanza));
69 SendStanza(response_stanza.get()); 69 SendStanza(response_stanza.get());
70 return STATE_RESPONSE; 70 return STATE_RESPONSE;
71 } 71 }
72 72
73 virtual bool HandleStanza(const buzz::XmlElement* stanza) { 73 virtual bool HandleStanza(const buzz::XmlElement* stanza) {
74 LOG(INFO) << "Stanza received: " 74 VLOG(1) << "Stanza received: "
75 << notifier::XmlElementToString(*stanza); 75 << notifier::XmlElementToString(*stanza);
76 if (IsValidCacheInvalidationIqPacket(stanza)) { 76 if (IsValidCacheInvalidationIqPacket(stanza)) {
77 LOG(INFO) << "Queueing stanza"; 77 VLOG(2) << "Queueing stanza";
78 QueueStanza(stanza); 78 QueueStanza(stanza);
79 return true; 79 return true;
80 } 80 }
81 LOG(INFO) << "Stanza skipped"; 81 VLOG(2) << "Stanza skipped";
82 return false; 82 return false;
83 } 83 }
84 84
85 private: 85 private:
86 bool IsValidCacheInvalidationIqPacket(const buzz::XmlElement* stanza) { 86 bool IsValidCacheInvalidationIqPacket(const buzz::XmlElement* stanza) {
87 // We make sure to compare jids (which are normalized) instead of 87 // We make sure to compare jids (which are normalized) instead of
88 // just strings -- server may use non-normalized jids in 88 // just strings -- server may use non-normalized jids in
89 // attributes. 89 // attributes.
90 // 90 //
91 // TODO(akalin): Add unit tests for this. 91 // TODO(akalin): Add unit tests for this.
(...skipping 29 matching lines...) Expand all
121 int seq, 121 int seq,
122 const std::string& sid) 122 const std::string& sid)
123 : XmppTask(parent, buzz::XmppEngine::HL_SINGLE), 123 : XmppTask(parent, buzz::XmppEngine::HL_SINGLE),
124 to_jid_(to_jid), msg_(msg), seq_(seq), sid_(sid) {} 124 to_jid_(to_jid), msg_(msg), seq_(seq), sid_(sid) {}
125 virtual ~CacheInvalidationSendMessageTask() {} 125 virtual ~CacheInvalidationSendMessageTask() {}
126 126
127 virtual int ProcessStart() { 127 virtual int ProcessStart() {
128 scoped_ptr<buzz::XmlElement> stanza( 128 scoped_ptr<buzz::XmlElement> stanza(
129 MakeCacheInvalidationIqPacket(to_jid_, task_id(), msg_, 129 MakeCacheInvalidationIqPacket(to_jid_, task_id(), msg_,
130 seq_, sid_)); 130 seq_, sid_));
131 LOG(INFO) << "Sending message: " 131 VLOG(1) << "Sending message: "
132 << notifier::XmlElementToString(*stanza.get()); 132 << notifier::XmlElementToString(*stanza.get());
133 if (SendStanza(stanza.get()) != buzz::XMPP_RETURN_OK) { 133 if (SendStanza(stanza.get()) != buzz::XMPP_RETURN_OK) {
134 LOG(INFO) << "Error when sending message"; 134 VLOG(2) << "Error when sending message";
135 return STATE_ERROR; 135 return STATE_ERROR;
136 } 136 }
137 return STATE_RESPONSE; 137 return STATE_RESPONSE;
138 } 138 }
139 139
140 virtual int ProcessResponse() { 140 virtual int ProcessResponse() {
141 const buzz::XmlElement* stanza = NextStanza(); 141 const buzz::XmlElement* stanza = NextStanza();
142 if (stanza == NULL) { 142 if (stanza == NULL) {
143 LOG(INFO) << "CacheInvalidationSendMessageTask blocked..."; 143 VLOG(2) << "CacheInvalidationSendMessageTask blocked...";
144 return STATE_BLOCKED; 144 return STATE_BLOCKED;
145 } 145 }
146 LOG(INFO) << "CacheInvalidationSendMessageTask response received: " 146 VLOG(2) << "CacheInvalidationSendMessageTask response received: "
147 << notifier::XmlElementToString(*stanza); 147 << notifier::XmlElementToString(*stanza);
148 // TODO(akalin): Handle errors here. 148 // TODO(akalin): Handle errors here.
149 return STATE_DONE; 149 return STATE_DONE;
150 } 150 }
151 151
152 virtual bool HandleStanza(const buzz::XmlElement* stanza) { 152 virtual bool HandleStanza(const buzz::XmlElement* stanza) {
153 LOG(INFO) << "Stanza received: " 153 VLOG(1) << "Stanza received: "
154 << notifier::XmlElementToString(*stanza); 154 << notifier::XmlElementToString(*stanza);
155 if (!MatchResponseIq(stanza, to_jid_, task_id())) { 155 if (!MatchResponseIq(stanza, to_jid_, task_id())) {
156 LOG(INFO) << "Stanza skipped"; 156 VLOG(2) << "Stanza skipped";
157 return false; 157 return false;
158 } 158 }
159 LOG(INFO) << "Queueing stanza"; 159 VLOG(2) << "Queueing stanza";
160 QueueStanza(stanza); 160 QueueStanza(stanza);
161 return true; 161 return true;
162 } 162 }
163 163
164 private: 164 private:
165 static buzz::XmlElement* MakeCacheInvalidationIqPacket( 165 static buzz::XmlElement* MakeCacheInvalidationIqPacket(
166 const buzz::Jid& to_jid, 166 const buzz::Jid& to_jid,
167 const std::string& task_id, 167 const std::string& task_id,
168 const std::string& msg, 168 const std::string& msg,
169 int seq, const std::string& sid) { 169 int seq, const std::string& sid) {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 std::string decoded_message; 253 std::string decoded_message;
254 if (!base::Base64Decode(packet, &decoded_message)) { 254 if (!base::Base64Decode(packet, &decoded_message)) {
255 LOG(ERROR) << "Could not base64-decode received message: " 255 LOG(ERROR) << "Could not base64-decode received message: "
256 << packet; 256 << packet;
257 return; 257 return;
258 } 258 }
259 network_endpoint->HandleInboundMessage(decoded_message); 259 network_endpoint->HandleInboundMessage(decoded_message);
260 } 260 }
261 261
262 } // namespace sync_notifier 262 } // namespace sync_notifier
OLDNEW
« no previous file with comments | « base/vlog_unittest.cc ('k') | chrome/browser/sync/notifier/chrome_invalidation_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698