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

Side by Side Diff: sync/engine/net/server_connection_manager.cc

Issue 15421011: Use OAuth2 token for sync (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove token prefetch. Move UMA counters. Fix some tests. Etc. Created 7 years, 6 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "sync/engine/net/server_connection_manager.h" 5 #include "sync/engine/net/server_connection_manager.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 8
9 #include <ostream> 9 #include <ostream>
10 #include <string> 10 #include <string>
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 base::AutoLock lock(terminate_connection_lock_); 206 base::AutoLock lock(terminate_connection_lock_);
207 // |active_connection_| can be NULL already if it was aborted. Also, 207 // |active_connection_| can be NULL already if it was aborted. Also,
208 // it can legitimately be a different Connection object if a new Connection 208 // it can legitimately be a different Connection object if a new Connection
209 // was created after a previous one was Aborted and destroyed. 209 // was created after a previous one was Aborted and destroyed.
210 if (active_connection_ != connection) 210 if (active_connection_ != connection)
211 return; 211 return;
212 212
213 active_connection_ = NULL; 213 active_connection_ = NULL;
214 } 214 }
215 215
216 bool ServerConnectionManager::SetAuthToken(const std::string& auth_token, 216 bool ServerConnectionManager::SetAuthToken(const std::string& auth_token) {
217 const base::Time& auth_token_time) {
218 DCHECK(thread_checker_.CalledOnValidThread()); 217 DCHECK(thread_checker_.CalledOnValidThread());
219 if (previously_invalidated_token != auth_token) { 218 if (previously_invalidated_token != auth_token) {
220 auth_token_.assign(auth_token); 219 auth_token_.assign(auth_token);
221 auth_token_time_ = auth_token_time;
222 previously_invalidated_token = std::string(); 220 previously_invalidated_token = std::string();
223 return true; 221 return true;
224 } 222 }
225 return false; 223 return false;
226 } 224 }
227 225
228 void ServerConnectionManager::OnInvalidationCredentialsRejected() { 226 void ServerConnectionManager::OnInvalidationCredentialsRejected() {
229 if (!auth_token_time_.is_null()) {
230 base::TimeDelta age = base::Time::Now() - auth_token_time_;
231 if (age < base::TimeDelta::FromHours(1)) {
232 UMA_HISTOGRAM_CUSTOM_TIMES("Sync.AuthInvalidationRejectedTokenAgeShort",
Nicolas Zea 2013/06/04 20:13:59 Is this histogram completely unnecessary now?
pavely 2013/06/04 21:30:45 SetServerStatus(AuthError) will trigger PSS::OnCon
Nicolas Zea 2013/06/04 21:33:29 Note that this was a different histogram measuring
233 age,
234 base::TimeDelta::FromSeconds(1),
235 base::TimeDelta::FromHours(1),
236 50);
237 }
238 UMA_HISTOGRAM_COUNTS("Sync.AuthInvalidationRejectedTokenAgeLong",
239 age.InDays());
240 }
241 InvalidateAndClearAuthToken(); 227 InvalidateAndClearAuthToken();
242 SetServerStatus(HttpResponse::SYNC_AUTH_ERROR); 228 SetServerStatus(HttpResponse::SYNC_AUTH_ERROR);
243 } 229 }
244 230
245 void ServerConnectionManager::InvalidateAndClearAuthToken() { 231 void ServerConnectionManager::InvalidateAndClearAuthToken() {
246 DCHECK(thread_checker_.CalledOnValidThread()); 232 DCHECK(thread_checker_.CalledOnValidThread());
247 // Copy over the token to previous invalid token. 233 // Copy over the token to previous invalid token.
248 if (!auth_token_.empty()) { 234 if (!auth_token_.empty()) {
249 previously_invalidated_token.assign(auth_token_); 235 previously_invalidated_token.assign(auth_token_);
250 auth_token_ = std::string(); 236 auth_token_ = std::string();
251 auth_token_time_ = base::Time();
252 } 237 }
253 } 238 }
254 239
255 void ServerConnectionManager::SetServerStatus( 240 void ServerConnectionManager::SetServerStatus(
256 HttpResponse::ServerConnectionCode server_status) { 241 HttpResponse::ServerConnectionCode server_status) {
257 if (server_status_ == server_status) 242 if (server_status_ == server_status)
258 return; 243 return;
259 server_status_ = server_status; 244 server_status_ = server_status;
260 NotifyStatusChanged(); 245 NotifyStatusChanged();
261 } 246 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 params->response.server_status = HttpResponse::CONNECTION_UNAVAILABLE; 278 params->response.server_status = HttpResponse::CONNECTION_UNAVAILABLE;
294 return false; 279 return false;
295 } 280 }
296 281
297 // Note that |post| may be aborted by now, which will just cause Init to fail 282 // Note that |post| may be aborted by now, which will just cause Init to fail
298 // with CONNECTION_UNAVAILABLE. 283 // with CONNECTION_UNAVAILABLE.
299 bool ok = post.get()->Init( 284 bool ok = post.get()->Init(
300 path.c_str(), auth_token, params->buffer_in, &params->response); 285 path.c_str(), auth_token, params->buffer_in, &params->response);
301 286
302 if (params->response.server_status == HttpResponse::SYNC_AUTH_ERROR) { 287 if (params->response.server_status == HttpResponse::SYNC_AUTH_ERROR) {
303 if (!auth_token_time_.is_null()) {
304 base::TimeDelta age = base::Time::Now() - auth_token_time_;
305 if (age < base::TimeDelta::FromHours(1)) {
306 UMA_HISTOGRAM_CUSTOM_TIMES("Sync.AuthServerRejectedTokenAgeShort",
307 age,
308 base::TimeDelta::FromSeconds(1),
309 base::TimeDelta::FromHours(1),
310 50);
311 }
312 UMA_HISTOGRAM_COUNTS("Sync.AuthServerRejectedTokenAgeLong",
313 age.InDays());
314 }
315 InvalidateAndClearAuthToken(); 288 InvalidateAndClearAuthToken();
316 } 289 }
317 290
318 if (!ok || net::HTTP_OK != params->response.response_code) 291 if (!ok || net::HTTP_OK != params->response.response_code)
319 return false; 292 return false;
320 293
321 if (post.get()->ReadBufferResponse( 294 if (post.get()->ReadBufferResponse(
322 &params->buffer_out, &params->response, true)) { 295 &params->buffer_out, &params->response, true)) {
323 params->response.server_status = HttpResponse::SERVER_CONNECTION_OK; 296 params->response.server_status = HttpResponse::SERVER_CONNECTION_OK;
324 return true; 297 return true;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 356
384 std::ostream& operator << (std::ostream& s, const struct HttpResponse& hr) { 357 std::ostream& operator << (std::ostream& s, const struct HttpResponse& hr) {
385 s << " Response Code (bogus on error): " << hr.response_code; 358 s << " Response Code (bogus on error): " << hr.response_code;
386 s << " Content-Length (bogus on error): " << hr.content_length; 359 s << " Content-Length (bogus on error): " << hr.content_length;
387 s << " Server Status: " 360 s << " Server Status: "
388 << HttpResponse::GetServerConnectionCodeString(hr.server_status); 361 << HttpResponse::GetServerConnectionCodeString(hr.server_status);
389 return s; 362 return s;
390 } 363 }
391 364
392 } // namespace syncer 365 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698