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

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

Issue 14888003: [Sync] Log age of auth tokens on authentication failure (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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 (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>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/metrics/histogram.h"
14 #include "build/build_config.h" 15 #include "build/build_config.h"
15 #include "googleurl/src/gurl.h" 16 #include "googleurl/src/gurl.h"
16 #include "net/base/net_errors.h" 17 #include "net/base/net_errors.h"
17 #include "net/http/http_status_code.h" 18 #include "net/http/http_status_code.h"
18 #include "sync/engine/net/url_translator.h" 19 #include "sync/engine/net/url_translator.h"
19 #include "sync/engine/syncer.h" 20 #include "sync/engine/syncer.h"
20 #include "sync/protocol/sync.pb.h" 21 #include "sync/protocol/sync.pb.h"
21 #include "sync/syncable/directory.h" 22 #include "sync/syncable/directory.h"
22 23
23 namespace syncer { 24 namespace syncer {
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 // |active_connection_| can be NULL already if it was aborted. Also, 207 // |active_connection_| can be NULL already if it was aborted. Also,
207 // 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
208 // was created after a previous one was Aborted and destroyed. 209 // was created after a previous one was Aborted and destroyed.
209 if (active_connection_ != connection) 210 if (active_connection_ != connection)
210 return; 211 return;
211 212
212 active_connection_ = NULL; 213 active_connection_ = NULL;
213 } 214 }
214 215
215 void ServerConnectionManager::OnInvalidationCredentialsRejected() { 216 void ServerConnectionManager::OnInvalidationCredentialsRejected() {
217 if (!auth_token_time_.is_null()) {
218 base::TimeDelta age = base::Time::Now() - auth_token_time_;
219 if (age < base::TimeDelta::FromHours(1)) {
220 UMA_HISTOGRAM_CUSTOM_TIMES("Sync.InvalidationRejectionAuthAgeShort",
tim (not reviewing) 2013/05/03 00:46:43 nit - might be nice to group auth related things i
Nicolas Zea 2013/05/03 01:31:41 Done.
221 age,
222 base::TimeDelta::FromSeconds(1),
223 base::TimeDelta::FromHours(1),
224 50);
225 }
226 UMA_HISTOGRAM_COUNTS("Sync.InvalidationRejectionAuthAgeLong", age.InDays());
227 }
216 InvalidateAndClearAuthToken(); 228 InvalidateAndClearAuthToken();
217 SetServerStatus(HttpResponse::SYNC_AUTH_ERROR); 229 SetServerStatus(HttpResponse::SYNC_AUTH_ERROR);
218 } 230 }
219 231
220 void ServerConnectionManager::InvalidateAndClearAuthToken() { 232 void ServerConnectionManager::InvalidateAndClearAuthToken() {
221 DCHECK(thread_checker_.CalledOnValidThread()); 233 DCHECK(thread_checker_.CalledOnValidThread());
222 // Copy over the token to previous invalid token. 234 // Copy over the token to previous invalid token.
223 if (!auth_token_.empty()) { 235 if (!auth_token_.empty()) {
224 previously_invalidated_token.assign(auth_token_); 236 previously_invalidated_token.assign(auth_token_);
225 auth_token_ = std::string(); 237 auth_token_ = std::string();
238 auth_token_time_ = base::Time();
226 } 239 }
227 } 240 }
228 241
229 void ServerConnectionManager::SetServerStatus( 242 void ServerConnectionManager::SetServerStatus(
230 HttpResponse::ServerConnectionCode server_status) { 243 HttpResponse::ServerConnectionCode server_status) {
231 if (server_status_ == server_status) 244 if (server_status_ == server_status)
232 return; 245 return;
233 server_status_ = server_status; 246 server_status_ = server_status;
234 NotifyStatusChanged(); 247 NotifyStatusChanged();
235 } 248 }
(...skipping 30 matching lines...) Expand all
266 if (!post.get()) { 279 if (!post.get()) {
267 params->response.server_status = HttpResponse::CONNECTION_UNAVAILABLE; 280 params->response.server_status = HttpResponse::CONNECTION_UNAVAILABLE;
268 return false; 281 return false;
269 } 282 }
270 283
271 // Note that |post| may be aborted by now, which will just cause Init to fail 284 // Note that |post| may be aborted by now, which will just cause Init to fail
272 // with CONNECTION_UNAVAILABLE. 285 // with CONNECTION_UNAVAILABLE.
273 bool ok = post.get()->Init( 286 bool ok = post.get()->Init(
274 path.c_str(), auth_token, params->buffer_in, &params->response); 287 path.c_str(), auth_token, params->buffer_in, &params->response);
275 288
276 if (params->response.server_status == HttpResponse::SYNC_AUTH_ERROR) 289 if (params->response.server_status == HttpResponse::SYNC_AUTH_ERROR) {
290 if (!auth_token_time_.is_null()) {
291 base::TimeDelta age = base::Time::Now() - auth_token_time_;
292 if (age < base::TimeDelta::FromHours(1)) {
293 UMA_HISTOGRAM_CUSTOM_TIMES("Sync.ServerRejectionAuthAgeShort",
294 age,
295 base::TimeDelta::FromSeconds(1),
296 base::TimeDelta::FromHours(1),
297 50);
298 }
299 UMA_HISTOGRAM_COUNTS("Sync.ServerRejectionAuthAgeLong",
tim (not reviewing) 2013/05/03 00:46:43 So no breakdown between 1 hour and 24 hours? I gue
Nicolas Zea 2013/05/03 01:31:41 Well, this is going to cover those, they'll simply
300 age.InDays());
301 }
277 InvalidateAndClearAuthToken(); 302 InvalidateAndClearAuthToken();
303 }
278 304
279 if (!ok || net::HTTP_OK != params->response.response_code) 305 if (!ok || net::HTTP_OK != params->response.response_code)
280 return false; 306 return false;
281 307
282 if (post.get()->ReadBufferResponse( 308 if (post.get()->ReadBufferResponse(
283 &params->buffer_out, &params->response, true)) { 309 &params->buffer_out, &params->response, true)) {
284 params->response.server_status = HttpResponse::SERVER_CONNECTION_OK; 310 params->response.server_status = HttpResponse::SERVER_CONNECTION_OK;
285 return true; 311 return true;
286 } 312 }
287 return false; 313 return false;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 370
345 std::ostream& operator << (std::ostream& s, const struct HttpResponse& hr) { 371 std::ostream& operator << (std::ostream& s, const struct HttpResponse& hr) {
346 s << " Response Code (bogus on error): " << hr.response_code; 372 s << " Response Code (bogus on error): " << hr.response_code;
347 s << " Content-Length (bogus on error): " << hr.content_length; 373 s << " Content-Length (bogus on error): " << hr.content_length;
348 s << " Server Status: " 374 s << " Server Status: "
349 << HttpResponse::GetServerConnectionCodeString(hr.server_status); 375 << HttpResponse::GetServerConnectionCodeString(hr.server_status);
350 return s; 376 return s;
351 } 377 }
352 378
353 } // namespace syncer 379 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698