OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/location.h" | 6 #include "base/location.h" |
7 #include "base/single_thread_task_runner.h" | 7 #include "base/single_thread_task_runner.h" |
8 #include "base/thread_task_runner_handle.h" | 8 #include "base/thread_task_runner_handle.h" |
9 #include "chrome/browser/invalidation/gcm_invalidation_bridge.h" | 9 #include "chrome/browser/invalidation/gcm_invalidation_bridge.h" |
10 #include "chrome/browser/services/gcm/gcm_service.h" | 10 #include "chrome/browser/services/gcm/gcm_service.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 virtual void InvalidateToken(const std::string& token) OVERRIDE; | 48 virtual void InvalidateToken(const std::string& token) OVERRIDE; |
49 virtual void Register(RegisterCallback callback) OVERRIDE; | 49 virtual void Register(RegisterCallback callback) OVERRIDE; |
50 virtual void SetMessageReceiver(MessageCallback callback) OVERRIDE; | 50 virtual void SetMessageReceiver(MessageCallback callback) OVERRIDE; |
51 | 51 |
52 void RequestTokenFinished(RequestTokenCallback callback, | 52 void RequestTokenFinished(RequestTokenCallback callback, |
53 const GoogleServiceAuthError& error, | 53 const GoogleServiceAuthError& error, |
54 const std::string& token); | 54 const std::string& token); |
55 | 55 |
56 void RegisterFinished(RegisterCallback callback, | 56 void RegisterFinished(RegisterCallback callback, |
57 const std::string& registration_id, | 57 const std::string& registration_id, |
58 gcm::GCMClient::Result result); | 58 gcm::Result result); |
59 | 59 |
60 void OnIncomingMessage(const std::string& message, | 60 void OnIncomingMessage(const std::string& message, |
61 const std::string& echo_token); | 61 const std::string& echo_token); |
62 | 62 |
63 private: | 63 private: |
64 base::WeakPtr<GCMInvalidationBridge> bridge_; | 64 base::WeakPtr<GCMInvalidationBridge> bridge_; |
65 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner_; | 65 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner_; |
66 | 66 |
67 MessageCallback message_callback_; | 67 MessageCallback message_callback_; |
68 | 68 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 RequestTokenCallback callback, | 128 RequestTokenCallback callback, |
129 const GoogleServiceAuthError& error, | 129 const GoogleServiceAuthError& error, |
130 const std::string& token) { | 130 const std::string& token) { |
131 DCHECK(CalledOnValidThread()); | 131 DCHECK(CalledOnValidThread()); |
132 callback.Run(error, token); | 132 callback.Run(error, token); |
133 } | 133 } |
134 | 134 |
135 void GCMInvalidationBridge::Core::RegisterFinished( | 135 void GCMInvalidationBridge::Core::RegisterFinished( |
136 RegisterCallback callback, | 136 RegisterCallback callback, |
137 const std::string& registration_id, | 137 const std::string& registration_id, |
138 gcm::GCMClient::Result result) { | 138 gcm::Result result) { |
139 DCHECK(CalledOnValidThread()); | 139 DCHECK(CalledOnValidThread()); |
140 callback.Run(registration_id, result); | 140 callback.Run(registration_id, result); |
141 } | 141 } |
142 | 142 |
143 void GCMInvalidationBridge::Core::OnIncomingMessage( | 143 void GCMInvalidationBridge::Core::OnIncomingMessage( |
144 const std::string& message, | 144 const std::string& message, |
145 const std::string& echo_token) { | 145 const std::string& echo_token) { |
146 DCHECK(!message_callback_.is_null()); | 146 DCHECK(!message_callback_.is_null()); |
147 message_callback_.Run(message, echo_token); | 147 message_callback_.Run(message, echo_token); |
148 } | 148 } |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 gcm_service_->Register(kInvalidationsAppId, | 252 gcm_service_->Register(kInvalidationsAppId, |
253 sender_ids, | 253 sender_ids, |
254 base::Bind(&GCMInvalidationBridge::RegisterFinished, | 254 base::Bind(&GCMInvalidationBridge::RegisterFinished, |
255 weak_factory_.GetWeakPtr(), | 255 weak_factory_.GetWeakPtr(), |
256 callback)); | 256 callback)); |
257 } | 257 } |
258 | 258 |
259 void GCMInvalidationBridge::RegisterFinished( | 259 void GCMInvalidationBridge::RegisterFinished( |
260 syncer::GCMNetworkChannelDelegate::RegisterCallback callback, | 260 syncer::GCMNetworkChannelDelegate::RegisterCallback callback, |
261 const std::string& registration_id, | 261 const std::string& registration_id, |
262 gcm::GCMClient::Result result) { | 262 gcm::Result result) { |
263 DCHECK(CalledOnValidThread()); | 263 DCHECK(CalledOnValidThread()); |
264 core_thread_task_runner_->PostTask( | 264 core_thread_task_runner_->PostTask( |
265 FROM_HERE, | 265 FROM_HERE, |
266 base::Bind(&GCMInvalidationBridge::Core::RegisterFinished, | 266 base::Bind(&GCMInvalidationBridge::Core::RegisterFinished, |
267 core_, | 267 core_, |
268 callback, | 268 callback, |
269 registration_id, | 269 registration_id, |
270 result)); | 270 result)); |
271 } | 271 } |
272 | 272 |
273 void GCMInvalidationBridge::SubscribeForIncomingMessages() { | 273 void GCMInvalidationBridge::SubscribeForIncomingMessages() { |
274 // No-op if GCMClient is disabled. | 274 // No-op if GCMClient is disabled. |
275 if (gcm_service_ == NULL) | 275 if (gcm_service_ == NULL) |
276 return; | 276 return; |
277 | 277 |
278 DCHECK(!subscribed_for_incoming_messages_); | 278 DCHECK(!subscribed_for_incoming_messages_); |
279 gcm_service_->AddAppHandler(kInvalidationsAppId, this); | 279 gcm_service_->AddAppHandler(kInvalidationsAppId, this); |
280 subscribed_for_incoming_messages_ = true; | 280 subscribed_for_incoming_messages_ = true; |
281 } | 281 } |
282 | 282 |
283 void GCMInvalidationBridge::ShutdownHandler() { | 283 void GCMInvalidationBridge::ShutdownHandler() { |
284 // Nothing to do. | 284 // Nothing to do. |
285 } | 285 } |
286 | 286 |
287 void GCMInvalidationBridge::OnMessage( | 287 void GCMInvalidationBridge::OnMessage( |
288 const std::string& app_id, | 288 const std::string& app_id, |
289 const gcm::GCMClient::IncomingMessage& message) { | 289 const gcm::IncomingMessage& message) { |
290 gcm::GCMClient::MessageData::const_iterator it; | 290 gcm::MessageData::const_iterator it; |
291 std::string content; | 291 std::string content; |
292 std::string echo_token; | 292 std::string echo_token; |
293 it = message.data.find(kContentKey); | 293 it = message.data.find(kContentKey); |
294 if (it != message.data.end()) | 294 if (it != message.data.end()) |
295 content = it->second; | 295 content = it->second; |
296 it = message.data.find(kEchoTokenKey); | 296 it = message.data.find(kEchoTokenKey); |
297 if (it != message.data.end()) | 297 if (it != message.data.end()) |
298 echo_token = it->second; | 298 echo_token = it->second; |
299 | 299 |
300 core_thread_task_runner_->PostTask( | 300 core_thread_task_runner_->PostTask( |
301 FROM_HERE, | 301 FROM_HERE, |
302 base::Bind(&GCMInvalidationBridge::Core::OnIncomingMessage, | 302 base::Bind(&GCMInvalidationBridge::Core::OnIncomingMessage, |
303 core_, | 303 core_, |
304 content, | 304 content, |
305 echo_token)); | 305 echo_token)); |
306 } | 306 } |
307 | 307 |
308 void GCMInvalidationBridge::OnMessagesDeleted(const std::string& app_id) { | 308 void GCMInvalidationBridge::OnMessagesDeleted(const std::string& app_id) { |
309 // Cacheinvalidation doesn't use long lived non-collapsable messages with GCM. | 309 // Cacheinvalidation doesn't use long lived non-collapsable messages with GCM. |
310 // Android implementation of cacheinvalidation doesn't handle MessagesDeleted | 310 // Android implementation of cacheinvalidation doesn't handle MessagesDeleted |
311 // callback so this should be no-op in desktop version as well. | 311 // callback so this should be no-op in desktop version as well. |
312 } | 312 } |
313 | 313 |
314 void GCMInvalidationBridge::OnSendError( | 314 void GCMInvalidationBridge::OnSendError( |
315 const std::string& app_id, | 315 const std::string& app_id, |
316 const gcm::GCMClient::SendErrorDetails& send_error_details) { | 316 const gcm::SendErrorDetails& send_error_details) { |
317 // cacheinvalidation doesn't send messages over GCM. | 317 // cacheinvalidation doesn't send messages over GCM. |
318 NOTREACHED(); | 318 NOTREACHED(); |
319 } | 319 } |
320 | 320 |
321 } // namespace invalidation | 321 } // namespace invalidation |
OLD | NEW |