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_profile_service.h" | 10 #include "chrome/browser/services/gcm/gcm_service.h" |
11 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 11 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
12 #include "chrome/browser/signin/signin_manager_factory.h" | 12 #include "chrome/browser/signin/signin_manager_factory.h" |
13 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 13 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
14 #include "components/signin/core/browser/signin_manager.h" | 14 #include "components/signin/core/browser/signin_manager.h" |
15 #include "google_apis/gaia/gaia_constants.h" | 15 #include "google_apis/gaia/gaia_constants.h" |
16 #include "google_apis/gaia/identity_provider.h" | 16 #include "google_apis/gaia/identity_provider.h" |
17 | 17 |
18 namespace invalidation { | 18 namespace invalidation { |
19 namespace { | 19 namespace { |
20 // For 3rd party developers SenderId should come from application dashboard when | 20 // For 3rd party developers SenderId should come from application dashboard when |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 } |
149 | 149 |
150 GCMInvalidationBridge::GCMInvalidationBridge( | 150 GCMInvalidationBridge::GCMInvalidationBridge( |
151 gcm::GCMProfileService* gcm_profile_service, | 151 gcm::GCMService* gcm_service, |
152 IdentityProvider* identity_provider) | 152 IdentityProvider* identity_provider) |
153 : OAuth2TokenService::Consumer("gcm_network_channel"), | 153 : OAuth2TokenService::Consumer("gcm_network_channel"), |
154 gcm_profile_service_(gcm_profile_service), | 154 gcm_service_(gcm_service), |
155 identity_provider_(identity_provider), | 155 identity_provider_(identity_provider), |
156 subscribed_for_incoming_messages_(false), | 156 subscribed_for_incoming_messages_(false), |
157 weak_factory_(this) {} | 157 weak_factory_(this) {} |
158 | 158 |
159 GCMInvalidationBridge::~GCMInvalidationBridge() { | 159 GCMInvalidationBridge::~GCMInvalidationBridge() { |
160 if (subscribed_for_incoming_messages_) | 160 if (subscribed_for_incoming_messages_) |
161 gcm_profile_service_->RemoveAppHandler(kInvalidationsAppId); | 161 gcm_service_->RemoveAppHandler(kInvalidationsAppId); |
162 } | 162 } |
163 | 163 |
164 scoped_ptr<syncer::GCMNetworkChannelDelegate> | 164 scoped_ptr<syncer::GCMNetworkChannelDelegate> |
165 GCMInvalidationBridge::CreateDelegate() { | 165 GCMInvalidationBridge::CreateDelegate() { |
166 DCHECK(CalledOnValidThread()); | 166 DCHECK(CalledOnValidThread()); |
167 scoped_ptr<syncer::GCMNetworkChannelDelegate> core(new Core( | 167 scoped_ptr<syncer::GCMNetworkChannelDelegate> core(new Core( |
168 weak_factory_.GetWeakPtr(), base::ThreadTaskRunnerHandle::Get())); | 168 weak_factory_.GetWeakPtr(), base::ThreadTaskRunnerHandle::Get())); |
169 return core.Pass(); | 169 return core.Pass(); |
170 } | 170 } |
171 | 171 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 DCHECK(CalledOnValidThread()); | 235 DCHECK(CalledOnValidThread()); |
236 OAuth2TokenService::ScopeSet scopes; | 236 OAuth2TokenService::ScopeSet scopes; |
237 scopes.insert(GaiaConstants::kChromeSyncOAuth2Scope); | 237 scopes.insert(GaiaConstants::kChromeSyncOAuth2Scope); |
238 identity_provider_->InvalidateAccessToken(scopes, token); | 238 identity_provider_->InvalidateAccessToken(scopes, token); |
239 } | 239 } |
240 | 240 |
241 void GCMInvalidationBridge::Register( | 241 void GCMInvalidationBridge::Register( |
242 syncer::GCMNetworkChannelDelegate::RegisterCallback callback) { | 242 syncer::GCMNetworkChannelDelegate::RegisterCallback callback) { |
243 DCHECK(CalledOnValidThread()); | 243 DCHECK(CalledOnValidThread()); |
244 // No-op if GCMClient is disabled. | 244 // No-op if GCMClient is disabled. |
245 if (gcm_profile_service_ == NULL) | 245 if (gcm_service_ == NULL) |
246 return; | 246 return; |
247 | 247 |
248 std::vector<std::string> sender_ids; | 248 std::vector<std::string> sender_ids; |
249 sender_ids.push_back(kInvalidationsSenderId); | 249 sender_ids.push_back(kInvalidationsSenderId); |
250 gcm_profile_service_->Register( | 250 gcm_service_->Register(kInvalidationsAppId, |
251 kInvalidationsAppId, | 251 sender_ids, |
252 sender_ids, | 252 base::Bind(&GCMInvalidationBridge::RegisterFinished, |
253 base::Bind(&GCMInvalidationBridge::RegisterFinished, | 253 weak_factory_.GetWeakPtr(), |
254 weak_factory_.GetWeakPtr(), | 254 callback)); |
255 callback)); | |
256 } | 255 } |
257 | 256 |
258 void GCMInvalidationBridge::RegisterFinished( | 257 void GCMInvalidationBridge::RegisterFinished( |
259 syncer::GCMNetworkChannelDelegate::RegisterCallback callback, | 258 syncer::GCMNetworkChannelDelegate::RegisterCallback callback, |
260 const std::string& registration_id, | 259 const std::string& registration_id, |
261 gcm::GCMClient::Result result) { | 260 gcm::GCMClient::Result result) { |
262 DCHECK(CalledOnValidThread()); | 261 DCHECK(CalledOnValidThread()); |
263 core_thread_task_runner_->PostTask( | 262 core_thread_task_runner_->PostTask( |
264 FROM_HERE, | 263 FROM_HERE, |
265 base::Bind(&GCMInvalidationBridge::Core::RegisterFinished, | 264 base::Bind(&GCMInvalidationBridge::Core::RegisterFinished, |
266 core_, | 265 core_, |
267 callback, | 266 callback, |
268 registration_id, | 267 registration_id, |
269 result)); | 268 result)); |
270 } | 269 } |
271 | 270 |
272 void GCMInvalidationBridge::SubscribeForIncomingMessages() { | 271 void GCMInvalidationBridge::SubscribeForIncomingMessages() { |
273 // No-op if GCMClient is disabled. | 272 // No-op if GCMClient is disabled. |
274 if (gcm_profile_service_ == NULL) | 273 if (gcm_service_ == NULL) |
275 return; | 274 return; |
276 | 275 |
277 DCHECK(!subscribed_for_incoming_messages_); | 276 DCHECK(!subscribed_for_incoming_messages_); |
278 gcm_profile_service_->AddAppHandler(kInvalidationsAppId, this); | 277 gcm_service_->AddAppHandler(kInvalidationsAppId, this); |
279 subscribed_for_incoming_messages_ = true; | 278 subscribed_for_incoming_messages_ = true; |
280 } | 279 } |
281 | 280 |
282 void GCMInvalidationBridge::ShutdownHandler() { | 281 void GCMInvalidationBridge::ShutdownHandler() { |
283 // Nothing to do. | 282 // Nothing to do. |
284 } | 283 } |
285 | 284 |
286 void GCMInvalidationBridge::OnMessage( | 285 void GCMInvalidationBridge::OnMessage( |
287 const std::string& app_id, | 286 const std::string& app_id, |
288 const gcm::GCMClient::IncomingMessage& message) { | 287 const gcm::GCMClient::IncomingMessage& message) { |
(...skipping 22 matching lines...) Expand all Loading... |
311 } | 310 } |
312 | 311 |
313 void GCMInvalidationBridge::OnSendError( | 312 void GCMInvalidationBridge::OnSendError( |
314 const std::string& app_id, | 313 const std::string& app_id, |
315 const gcm::GCMClient::SendErrorDetails& send_error_details) { | 314 const gcm::GCMClient::SendErrorDetails& send_error_details) { |
316 // cacheinvalidation doesn't send messages over GCM. | 315 // cacheinvalidation doesn't send messages over GCM. |
317 NOTREACHED(); | 316 NOTREACHED(); |
318 } | 317 } |
319 | 318 |
320 } // namespace invalidation | 319 } // namespace invalidation |
OLD | NEW |