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

Unified Diff: chrome/browser/signin/oauth2_token_service.h

Issue 11038063: Support chrome_to_mobile job receiving Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix format Created 8 years, 1 month 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/chrome_to_mobile_service.cc ('k') | chrome/browser/signin/oauth2_token_service.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/signin/oauth2_token_service.h
diff --git a/chrome/browser/signin/oauth2_token_service.h b/chrome/browser/signin/oauth2_token_service.h
new file mode 100644
index 0000000000000000000000000000000000000000..e33c8cf2740a753fa77376c0d0e8cf57fe9aa713
--- /dev/null
+++ b/chrome/browser/signin/oauth2_token_service.h
@@ -0,0 +1,103 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+// OAuth2TokenService is used to retrieve OAuth2 access tokens for given
+// scopes. To use this service, a consumer will start a Request for a given
+// set of scopes. This request can be started from any thread. It will then be
+// called asynchronously, on the same thread, with either a valid OAuth2 access
+// token, or with an error. Deleting the request object will cancel an
+// in-flight request.
+
+#ifndef CHROME_BROWSER_SIGNIN_OAUTH2_TOKEN_SERVICE_H_
+#define CHROME_BROWSER_SIGNIN_OAUTH2_TOKEN_SERVICE_H_
+
+#include <set>
+#include <string>
+#include <vector>
+
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "chrome/browser/common/cancelable_request.h"
+#include "chrome/browser/profiles/profile_keyed_service.h"
+#include "content/public/browser/notification_observer.h"
+#include "content/public/browser/notification_registrar.h"
+#include "net/url_request/url_request_context_getter.h"
+
+class GoogleServiceAuthError;
+class OAuth2AccessTokenConsumer;
+class Profile;
+
+// The OAuth2TokenService is a Profile keyed service. All calls but
+// |StartRequest()| are expected from the UI thread. CreateRequest can be
+// called from any thread.
+class OAuth2TokenService : public CancelableRequestProvider,
+ public content::NotificationObserver,
+ public ProfileKeyedService {
+ public:
+ // The class represents a request. Deleting an instance of this class will
+ // stop the in-flight request.
+ class Request {
+ public:
+ Request() {}
+ virtual ~Request() {}
+ };
+
+ OAuth2TokenService();
+ virtual ~OAuth2TokenService();
+
+ // Initializes this token service with the profile.
+ void Initialize(Profile* profile);
+
+ // Starts a request for an OAuth2 access token. The ownership of the Request
+ // instance is passed to the caller. |scopes| is the list of scopes to get an
+ // access token for, |consumer| is the object that will be called back with
+ // results. |consumer| has to outlive the returned request. Deleting the
+ // returned object will cancel the in-flight request.
+ virtual Request* StartRequest(const std::vector<std::string>& scopes,
+ OAuth2AccessTokenConsumer* consumer);
+
+ // Clear the currently cached tokens. Can be used by consumers to force a new
+ // token to be fetched.
+ void ClearCache();
+
+ // content::NotificationObserver
+ virtual void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) OVERRIDE;
+
+ private:
+ class RequestImpl;
+ friend class RequestImpl;
+
+ struct CacheEntry {
+ std::string access_token;
+ base::Time expiration_date;
+ };
+
+ // Returns a currently valid |AccessToken| for the given set of scopes, or
+ // NULL if none have been cached.
+ CacheEntry const* GetCacheEntry(const std::set<std::string>& scopes);
+
+ // Register a new access token in the cache.
+ void RegisterCacheEntry(const std::set<std::string>& scopes,
+ const std::string& access_token,
+ const base::Time& expiration_date);
+
+ // The profile with which this instance was initialized, or NULL.
+ Profile* profile_;
+
+ // Getter to use for fetchers.
+ scoped_refptr<net::URLRequestContextGetter> getter_;
+
+ // The cache of currently valid tokens.
+ typedef std::map<std::set<std::string>, CacheEntry> TokensCache;
+ TokensCache tokens_cache_;
+
+ // Registrar for notifications from the TokenService.
+ content::NotificationRegistrar registrar_;
+
+ DISALLOW_COPY_AND_ASSIGN(OAuth2TokenService);
+};
+
+#endif // CHROME_BROWSER_SIGNIN_OAUTH2_TOKEN_SERVICE_H_
« no previous file with comments | « chrome/browser/chrome_to_mobile_service.cc ('k') | chrome/browser/signin/oauth2_token_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698