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

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

Issue 179843002: Make invalidations work for Chrome OS Kiosk Apps. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix sync tests Created 6 years, 9 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/invalidation/invalidation_auth_provider.h"
10 #include "chrome/browser/services/gcm/gcm_profile_service.h" 11 #include "chrome/browser/services/gcm/gcm_profile_service.h"
11 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h"
12 #include "chrome/browser/signin/profile_oauth2_token_service.h" 12 #include "chrome/browser/signin/profile_oauth2_token_service.h"
13 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 13 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
14 #include "chrome/browser/signin/signin_manager.h" 14 #include "chrome/browser/signin/signin_manager.h"
15 #include "chrome/browser/signin/signin_manager_factory.h" 15 #include "chrome/browser/signin/signin_manager_factory.h"
16 #include "google_apis/gaia/gaia_constants.h" 16 #include "google_apis/gaia/gaia_constants.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
21 // server side application is registered with Google. Android invalidations use 21 // server side application is registered with Google. Android invalidations use
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 } 116 }
117 117
118 void GCMInvalidationBridge::Core::RegisterFinished( 118 void GCMInvalidationBridge::Core::RegisterFinished(
119 RegisterCallback callback, 119 RegisterCallback callback,
120 const std::string& registration_id, 120 const std::string& registration_id,
121 gcm::GCMClient::Result result) { 121 gcm::GCMClient::Result result) {
122 DCHECK(CalledOnValidThread()); 122 DCHECK(CalledOnValidThread());
123 callback.Run(registration_id, result); 123 callback.Run(registration_id, result);
124 } 124 }
125 125
126 GCMInvalidationBridge::GCMInvalidationBridge(Profile* profile) 126 GCMInvalidationBridge::GCMInvalidationBridge(
127 gcm::GCMProfileService* gcm_profile_service,
128 InvalidationAuthProvider* auth_provider)
127 : OAuth2TokenService::Consumer("gcm_network_channel"), 129 : OAuth2TokenService::Consumer("gcm_network_channel"),
128 profile_(profile), 130 gcm_profile_service_(gcm_profile_service),
131 auth_provider_(auth_provider),
129 weak_factory_(this) {} 132 weak_factory_(this) {}
130 133
131 GCMInvalidationBridge::~GCMInvalidationBridge() {} 134 GCMInvalidationBridge::~GCMInvalidationBridge() {}
132 135
133 scoped_ptr<syncer::GCMNetworkChannelDelegate> 136 scoped_ptr<syncer::GCMNetworkChannelDelegate>
134 GCMInvalidationBridge::CreateDelegate() { 137 GCMInvalidationBridge::CreateDelegate() {
135 DCHECK(CalledOnValidThread()); 138 DCHECK(CalledOnValidThread());
136 scoped_ptr<syncer::GCMNetworkChannelDelegate> core(new Core( 139 scoped_ptr<syncer::GCMNetworkChannelDelegate> core(new Core(
137 weak_factory_.GetWeakPtr(), base::ThreadTaskRunnerHandle::Get())); 140 weak_factory_.GetWeakPtr(), base::ThreadTaskRunnerHandle::Get()));
138 return core.Pass(); 141 return core.Pass();
(...skipping 15 matching lines...) Expand all
154 GoogleServiceAuthError error(GoogleServiceAuthError::REQUEST_CANCELED); 157 GoogleServiceAuthError error(GoogleServiceAuthError::REQUEST_CANCELED);
155 std::string access_token; 158 std::string access_token;
156 core_thread_task_runner_->PostTask( 159 core_thread_task_runner_->PostTask(
157 FROM_HERE, 160 FROM_HERE,
158 base::Bind(&GCMInvalidationBridge::Core::RequestTokenFinished, 161 base::Bind(&GCMInvalidationBridge::Core::RequestTokenFinished,
159 core_, 162 core_,
160 request_token_callback_, 163 request_token_callback_,
161 error, 164 error,
162 access_token)); 165 access_token));
163 } 166 }
164 ProfileOAuth2TokenService* token_service =
165 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
166 request_token_callback_ = callback; 167 request_token_callback_ = callback;
167 SigninManagerBase* signin_manager =
168 SigninManagerFactory::GetForProfile(profile_);
169 std::string account_id = signin_manager->GetAuthenticatedAccountId();
170 OAuth2TokenService::ScopeSet scopes; 168 OAuth2TokenService::ScopeSet scopes;
171 scopes.insert(GaiaConstants::kGoogleTalkOAuth2Scope); 169 scopes.insert(GaiaConstants::kGoogleTalkOAuth2Scope);
172 access_token_request_ = token_service->StartRequest(account_id, scopes, this); 170 access_token_request_ = auth_provider_->GetTokenService()->StartRequest(
171 auth_provider_->GetAccountId(), scopes, this);
173 } 172 }
174 173
175 void GCMInvalidationBridge::OnGetTokenSuccess( 174 void GCMInvalidationBridge::OnGetTokenSuccess(
176 const OAuth2TokenService::Request* request, 175 const OAuth2TokenService::Request* request,
177 const std::string& access_token, 176 const std::string& access_token,
178 const base::Time& expiration_time) { 177 const base::Time& expiration_time) {
179 DCHECK(CalledOnValidThread()); 178 DCHECK(CalledOnValidThread());
180 DCHECK_EQ(access_token_request_, request); 179 DCHECK_EQ(access_token_request_, request);
181 core_thread_task_runner_->PostTask( 180 core_thread_task_runner_->PostTask(
182 FROM_HERE, 181 FROM_HERE,
(...skipping 16 matching lines...) Expand all
199 base::Bind(&GCMInvalidationBridge::Core::RequestTokenFinished, 198 base::Bind(&GCMInvalidationBridge::Core::RequestTokenFinished,
200 core_, 199 core_,
201 request_token_callback_, 200 request_token_callback_,
202 error, 201 error,
203 std::string())); 202 std::string()));
204 request_token_callback_.Reset(); 203 request_token_callback_.Reset();
205 access_token_request_.reset(); 204 access_token_request_.reset();
206 } 205 }
207 206
208 void GCMInvalidationBridge::InvalidateToken(const std::string& token) { 207 void GCMInvalidationBridge::InvalidateToken(const std::string& token) {
209 ProfileOAuth2TokenService* token_service =
210 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
211 DCHECK(CalledOnValidThread()); 208 DCHECK(CalledOnValidThread());
212 SigninManagerBase* signin_manager =
213 SigninManagerFactory::GetForProfile(profile_);
214 std::string account_id = signin_manager->GetAuthenticatedAccountId();
215 OAuth2TokenService::ScopeSet scopes; 209 OAuth2TokenService::ScopeSet scopes;
216 scopes.insert(GaiaConstants::kGoogleTalkOAuth2Scope); 210 scopes.insert(GaiaConstants::kGoogleTalkOAuth2Scope);
217 token_service->InvalidateToken(account_id, scopes, token); 211 auth_provider_->GetTokenService()->InvalidateToken(
212 auth_provider_->GetAccountId(), scopes, token);
218 } 213 }
219 214
220 void GCMInvalidationBridge::Register( 215 void GCMInvalidationBridge::Register(
221 syncer::GCMNetworkChannelDelegate::RegisterCallback callback) { 216 syncer::GCMNetworkChannelDelegate::RegisterCallback callback) {
222 DCHECK(CalledOnValidThread()); 217 DCHECK(CalledOnValidThread());
223 // No-op if GCMClient is disabled. 218 // No-op if GCMClient is disabled.
224 gcm::GCMProfileService* gcm_profile_service = 219 if (gcm_profile_service_ == NULL)
225 gcm::GCMProfileServiceFactory::GetForProfile(profile_);
226 if (gcm_profile_service == NULL)
227 return; 220 return;
228 221
229 std::vector<std::string> sender_ids; 222 std::vector<std::string> sender_ids;
230 sender_ids.push_back(kInvalidationsSenderId); 223 sender_ids.push_back(kInvalidationsSenderId);
231 gcm_profile_service->Register( 224 gcm_profile_service_->Register(
232 kInvalidationsAppId, 225 kInvalidationsAppId,
233 sender_ids, 226 sender_ids,
234 base::Bind(&GCMInvalidationBridge::RegisterFinished, 227 base::Bind(&GCMInvalidationBridge::RegisterFinished,
235 weak_factory_.GetWeakPtr(), 228 weak_factory_.GetWeakPtr(),
236 callback)); 229 callback));
237 } 230 }
238 231
239 void GCMInvalidationBridge::RegisterFinished( 232 void GCMInvalidationBridge::RegisterFinished(
240 syncer::GCMNetworkChannelDelegate::RegisterCallback callback, 233 syncer::GCMNetworkChannelDelegate::RegisterCallback callback,
241 const std::string& registration_id, 234 const std::string& registration_id,
242 gcm::GCMClient::Result result) { 235 gcm::GCMClient::Result result) {
243 DCHECK(CalledOnValidThread()); 236 DCHECK(CalledOnValidThread());
244 core_thread_task_runner_->PostTask( 237 core_thread_task_runner_->PostTask(
245 FROM_HERE, 238 FROM_HERE,
246 base::Bind(&GCMInvalidationBridge::Core::RegisterFinished, 239 base::Bind(&GCMInvalidationBridge::Core::RegisterFinished,
247 core_, 240 core_,
248 callback, 241 callback,
249 registration_id, 242 registration_id,
250 result)); 243 result));
251 } 244 }
252 245
253 } // namespace invalidation 246 } // namespace invalidation
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698