OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/net/gaia/token_service.h" | 5 #include "chrome/browser/net/gaia/token_service.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/common/chrome_notification_types.h" | 10 #include "chrome/common/chrome_notification_types.h" |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 // come from a DB read or from IssueAuthToken. Since we should never | 323 // come from a DB read or from IssueAuthToken. Since we should never |
324 // fetch from the DB twice in a browser session, it must be from | 324 // fetch from the DB twice in a browser session, it must be from |
325 // OnIssueAuthTokenSuccess, which is a live fetcher. | 325 // OnIssueAuthTokenSuccess, which is a live fetcher. |
326 // | 326 // |
327 // Network fetched tokens take priority over DB tokens, so exclude tokens | 327 // Network fetched tokens take priority over DB tokens, so exclude tokens |
328 // which have already been loaded by the fetcher. | 328 // which have already been loaded by the fetcher. |
329 if (!in_memory_tokens->count(kServices[i]) && | 329 if (!in_memory_tokens->count(kServices[i]) && |
330 db_tokens.count(kServices[i])) { | 330 db_tokens.count(kServices[i])) { |
331 std::string db_token = db_tokens.find(kServices[i])->second; | 331 std::string db_token = db_tokens.find(kServices[i])->second; |
332 if (!db_token.empty()) { | 332 if (!db_token.empty()) { |
333 VLOG(1) << "Loading " << kServices[i] << "token from DB: " << db_token; | 333 VLOG(1) << "Loading " << kServices[i] << " token from DB: " << db_token; |
334 (*in_memory_tokens)[kServices[i]] = db_token; | 334 (*in_memory_tokens)[kServices[i]] = db_token; |
335 FireTokenAvailableNotification(kServices[i], db_token); | 335 FireTokenAvailableNotification(kServices[i], db_token); |
336 // Failures are only for network errors. | 336 // Failures are only for network errors. |
337 } | 337 } |
338 } | 338 } |
339 } | 339 } |
340 | 340 |
341 if (credentials_.lsid.empty() && credentials_.sid.empty()) { | 341 if (credentials_.lsid.empty() && credentials_.sid.empty()) { |
342 // Look for GAIA SID and LSID tokens. If we have both, and the current | 342 // Look for GAIA SID and LSID tokens. If we have both, and the current |
343 // crendentials are empty, update the credentials. | 343 // crendentials are empty, update the credentials. |
(...skipping 20 matching lines...) Expand all Loading... |
364 // come from a DB read or from IssueAuthToken. Since we should never | 364 // come from a DB read or from IssueAuthToken. Since we should never |
365 // fetch from the DB twice in a browser session, it must be from | 365 // fetch from the DB twice in a browser session, it must be from |
366 // OnIssueAuthTokenSuccess, which is a live fetcher. | 366 // OnIssueAuthTokenSuccess, which is a live fetcher. |
367 // | 367 // |
368 // Network fetched tokens take priority over DB tokens, so exclude tokens | 368 // Network fetched tokens take priority over DB tokens, so exclude tokens |
369 // which have already been loaded by the fetcher. | 369 // which have already been loaded by the fetcher. |
370 if (!in_memory_tokens->count(kOAuthServices[i]) && | 370 if (!in_memory_tokens->count(kOAuthServices[i]) && |
371 db_tokens.count(kOAuthServices[i])) { | 371 db_tokens.count(kOAuthServices[i])) { |
372 std::string db_token = db_tokens.find(kOAuthServices[i])->second; | 372 std::string db_token = db_tokens.find(kOAuthServices[i])->second; |
373 if (!db_token.empty()) { | 373 if (!db_token.empty()) { |
374 VLOG(1) << "Loading " << kOAuthServices[i] << "token from DB: " | 374 VLOG(1) << "Loading " << kOAuthServices[i] << " OAuth token from DB: " |
375 << db_token; | 375 << db_token; |
376 (*in_memory_tokens)[kOAuthServices[i]] = db_token; | 376 (*in_memory_tokens)[kOAuthServices[i]] = db_token; |
377 FireTokenAvailableNotification(kOAuthServices[i], db_token); | 377 FireTokenAvailableNotification(kOAuthServices[i], db_token); |
378 // Failures are only for network errors. | 378 // Failures are only for network errors. |
379 } | 379 } |
380 } | 380 } |
381 } | 381 } |
382 | 382 |
383 if (oauth_token_.empty() && oauth_secret_.empty()) { | 383 if (oauth_token_.empty() && oauth_secret_.empty()) { |
384 // Look for GAIA OAuth1 access token and secret. If we have both, and the | 384 // Look for GAIA OAuth1 access token and secret. If we have both, and the |
(...skipping 14 matching lines...) Expand all Loading... |
399 } | 399 } |
400 | 400 |
401 void TokenService::Observe(int type, | 401 void TokenService::Observe(int type, |
402 const NotificationSource& source, | 402 const NotificationSource& source, |
403 const NotificationDetails& details) { | 403 const NotificationDetails& details) { |
404 DCHECK_EQ(type, chrome::NOTIFICATION_TOKEN_UPDATED); | 404 DCHECK_EQ(type, chrome::NOTIFICATION_TOKEN_UPDATED); |
405 TokenAvailableDetails* tok_details = | 405 TokenAvailableDetails* tok_details = |
406 Details<TokenAvailableDetails>(details).ptr(); | 406 Details<TokenAvailableDetails>(details).ptr(); |
407 OnIssueAuthTokenSuccess(tok_details->service(), tok_details->token()); | 407 OnIssueAuthTokenSuccess(tok_details->service(), tok_details->token()); |
408 } | 408 } |
OLD | NEW |