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

Unified Diff: chrome/browser/net/gaia/token_service.cc

Issue 3024002: Add IssueAuthToken support to the TokenService. (Closed)
Patch Set: Code review fixes Created 10 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/net/gaia/token_service.h ('k') | chrome/browser/net/gaia/token_service_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/net/gaia/token_service.cc
diff --git a/chrome/browser/net/gaia/token_service.cc b/chrome/browser/net/gaia/token_service.cc
index f514bf7f86f354c0fb04f711230fd50fe55e98a9..16a1ab59995bed383ea2ccc0519cf4696e699671 100644
--- a/chrome/browser/net/gaia/token_service.cc
+++ b/chrome/browser/net/gaia/token_service.cc
@@ -4,15 +4,76 @@
#include "chrome/browser/net/gaia/token_service.h"
-void TokenService::SetClientLoginResult(
+#include "base/string_util.h"
+#include "chrome/common/net/gaia/gaia_authenticator2.h"
+#include "chrome/common/net/gaia/gaia_constants.h"
+#include "chrome/common/notification_service.h"
+
+void TokenService::Initialize(
+ const char* const source,
+ URLRequestContextGetter* getter,
const GaiaAuthConsumer::ClientLoginResult& credentials) {
+
credentials_ = credentials;
+ source_ = std::string(source);
+ sync_token_fetcher_.reset(new GaiaAuthenticator2(this, source_, getter));
+ talk_token_fetcher_.reset(new GaiaAuthenticator2(this, source_, getter));
+}
+
+const bool TokenService::AreCredentialsValid() const {
+ return !credentials_.lsid.empty() && !credentials_.sid.empty();
}
-bool TokenService::HasLsid() {
+const bool TokenService::HasLsid() const {
return !credentials_.lsid.empty();
}
-const std::string& TokenService::GetLsid() {
+const std::string& TokenService::GetLsid() const {
return credentials_.lsid;
}
+
+void TokenService::StartFetchingTokens() {
+ DCHECK(AreCredentialsValid());
+ sync_token_fetcher_->StartIssueAuthToken(credentials_.sid,
+ credentials_.lsid,
+ GaiaConstants::kSyncService);
+ talk_token_fetcher_->StartIssueAuthToken(credentials_.sid,
+ credentials_.lsid,
+ GaiaConstants::kTalkService);
+}
+
+// Services dependent on a token will check if a token is available.
+// If it isn't, they'll go to sleep until they get a token event.
+const bool TokenService::HasTokenForService(const char* const service) const {
+ return token_map_.count(service);
+}
+
+const std::string& TokenService::GetTokenForService(
+ const char* const service) const {
+
+ if (token_map_.count(service) > 0) {
+ // map[key] is not const
+ return (*token_map_.find(service)).second;
+ }
+ return EmptyString();
+}
+
+void TokenService::OnIssueAuthTokenSuccess(const std::string& service,
+ const std::string& auth_token) {
+ LOG(INFO) << "Got an authorization token for " << service;
+ token_map_[service] = auth_token;
+ TokenAvailableDetails details(service, auth_token);
+ NotificationService::current()->Notify(
+ NotificationType::TOKEN_AVAILABLE,
+ Source<TokenService>(this),
+ Details<const TokenAvailableDetails>(&details));
+}
+void TokenService::OnIssueAuthTokenFailure(const std::string& service,
+ const GaiaAuthError& error) {
+ LOG(WARNING) << "Auth token issuing failed for service:" << service;
+ TokenRequestFailedDetails details(service, error);
+ NotificationService::current()->Notify(
+ NotificationType::TOKEN_REQUEST_FAILED,
+ Source<TokenService>(this),
+ Details<const TokenRequestFailedDetails>(&details));
+}
« no previous file with comments | « chrome/browser/net/gaia/token_service.h ('k') | chrome/browser/net/gaia/token_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698