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

Side by Side Diff: chrome/browser/invalidation/gcm_invalidation_bridge.cc

Issue 225403021: Extract Profile-independent GCMService from GCMProfileService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Restore real IO thread in unit tests. Remove sources of flakiness by waiting instead of pumping whe… Created 6 years, 8 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 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
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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 OAuth2TokenService::ScopeSet scopes; 237 OAuth2TokenService::ScopeSet scopes;
238 scopes.insert(GaiaConstants::kChromeSyncOAuth2Scope); 238 scopes.insert(GaiaConstants::kChromeSyncOAuth2Scope);
239 identity_provider_->GetTokenService()->InvalidateToken( 239 identity_provider_->GetTokenService()->InvalidateToken(
240 identity_provider_->GetActiveAccountId(), scopes, token); 240 identity_provider_->GetActiveAccountId(), scopes, token);
241 } 241 }
242 242
243 void GCMInvalidationBridge::Register( 243 void GCMInvalidationBridge::Register(
244 syncer::GCMNetworkChannelDelegate::RegisterCallback callback) { 244 syncer::GCMNetworkChannelDelegate::RegisterCallback callback) {
245 DCHECK(CalledOnValidThread()); 245 DCHECK(CalledOnValidThread());
246 // No-op if GCMClient is disabled. 246 // No-op if GCMClient is disabled.
247 if (gcm_profile_service_ == NULL) 247 if (gcm_service_ == NULL)
248 return; 248 return;
249 249
250 std::vector<std::string> sender_ids; 250 std::vector<std::string> sender_ids;
251 sender_ids.push_back(kInvalidationsSenderId); 251 sender_ids.push_back(kInvalidationsSenderId);
252 gcm_profile_service_->Register( 252 gcm_service_->Register(kInvalidationsAppId,
253 kInvalidationsAppId, 253 sender_ids,
254 sender_ids, 254 base::Bind(&GCMInvalidationBridge::RegisterFinished,
255 base::Bind(&GCMInvalidationBridge::RegisterFinished, 255 weak_factory_.GetWeakPtr(),
256 weak_factory_.GetWeakPtr(), 256 callback));
257 callback));
258 } 257 }
259 258
260 void GCMInvalidationBridge::RegisterFinished( 259 void GCMInvalidationBridge::RegisterFinished(
261 syncer::GCMNetworkChannelDelegate::RegisterCallback callback, 260 syncer::GCMNetworkChannelDelegate::RegisterCallback callback,
262 const std::string& registration_id, 261 const std::string& registration_id,
263 gcm::GCMClient::Result result) { 262 gcm::GCMClient::Result result) {
264 DCHECK(CalledOnValidThread()); 263 DCHECK(CalledOnValidThread());
265 core_thread_task_runner_->PostTask( 264 core_thread_task_runner_->PostTask(
266 FROM_HERE, 265 FROM_HERE,
267 base::Bind(&GCMInvalidationBridge::Core::RegisterFinished, 266 base::Bind(&GCMInvalidationBridge::Core::RegisterFinished,
268 core_, 267 core_,
269 callback, 268 callback,
270 registration_id, 269 registration_id,
271 result)); 270 result));
272 } 271 }
273 272
274 void GCMInvalidationBridge::SubscribeForIncomingMessages() { 273 void GCMInvalidationBridge::SubscribeForIncomingMessages() {
275 // No-op if GCMClient is disabled. 274 // No-op if GCMClient is disabled.
276 if (gcm_profile_service_ == NULL) 275 if (gcm_service_ == NULL)
277 return; 276 return;
278 277
279 DCHECK(!subscribed_for_incoming_messages_); 278 DCHECK(!subscribed_for_incoming_messages_);
280 gcm_profile_service_->AddAppHandler(kInvalidationsAppId, this); 279 gcm_service_->AddAppHandler(kInvalidationsAppId, this);
281 subscribed_for_incoming_messages_ = true; 280 subscribed_for_incoming_messages_ = true;
282 } 281 }
283 282
284 void GCMInvalidationBridge::ShutdownHandler() { 283 void GCMInvalidationBridge::ShutdownHandler() {
285 // Nothing to do. 284 // Nothing to do.
286 } 285 }
287 286
288 void GCMInvalidationBridge::OnMessage( 287 void GCMInvalidationBridge::OnMessage(
289 const std::string& app_id, 288 const std::string& app_id,
290 const gcm::GCMClient::IncomingMessage& message) { 289 const gcm::GCMClient::IncomingMessage& message) {
(...skipping 22 matching lines...) Expand all
313 } 312 }
314 313
315 void GCMInvalidationBridge::OnSendError( 314 void GCMInvalidationBridge::OnSendError(
316 const std::string& app_id, 315 const std::string& app_id,
317 const gcm::GCMClient::SendErrorDetails& send_error_details) { 316 const gcm::GCMClient::SendErrorDetails& send_error_details) {
318 // cacheinvalidation doesn't send messages over GCM. 317 // cacheinvalidation doesn't send messages over GCM.
319 NOTREACHED(); 318 NOTREACHED();
320 } 319 }
321 320
322 } // namespace invalidation 321 } // namespace invalidation
OLDNEW
« no previous file with comments | « chrome/browser/invalidation/gcm_invalidation_bridge.h ('k') | chrome/browser/invalidation/ticl_invalidation_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698