[email protected] | f786717 | 2012-07-11 07:04:07 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 8b96de12 | 2010-02-15 15:15:22 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 93526f9 | 2010-02-19 16:37:42 | [diff] [blame] | 5 | // Defines the Geolocation access token store, and associated factory function. |
| 6 | // An access token store is responsible for providing the API to persist |
| 7 | // access tokens, one at a time, and to load them back on mass. |
[email protected] | e1d4edb | 2010-02-17 17:33:56 | [diff] [blame] | 8 | // The API is a little more complex than one might wish, due to the need for |
| 9 | // prefs access to happen asynchronously on the UI thread. |
[email protected] | 93526f9 | 2010-02-19 16:37:42 | [diff] [blame] | 10 | // This API is provided as abstract base classes to allow mocking and testing |
[email protected] | e1d4edb | 2010-02-17 17:33:56 | [diff] [blame] | 11 | // of clients, without dependency on browser process singleton objects etc. |
| 12 | |
[email protected] | c8c7718 | 2011-12-21 15:04:47 | [diff] [blame] | 13 | #ifndef CONTENT_PUBLIC_BROWSER_ACCESS_TOKEN_STORE_H_ |
| 14 | #define CONTENT_PUBLIC_BROWSER_ACCESS_TOKEN_STORE_H_ |
[email protected] | 8b96de12 | 2010-02-15 15:15:22 | [diff] [blame] | 15 | |
[email protected] | e1d4edb | 2010-02-17 17:33:56 | [diff] [blame] | 16 | #include <map> |
| 17 | |
[email protected] | 81b14e7 | 2011-10-07 21:18:36 | [diff] [blame] | 18 | #include "base/callback.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 19 | #include "base/memory/ref_counted.h" |
[email protected] | 26dd01c | 2013-06-12 13:52:13 | [diff] [blame] | 20 | #include "base/strings/string16.h" |
[email protected] | 8d128d6 | 2011-09-13 22:11:57 | [diff] [blame] | 21 | #include "content/common/content_export.h" |
[email protected] | 707e1c4 | 2013-07-09 21:18:58 | [diff] [blame] | 22 | #include "url/gurl.h" |
[email protected] | 8b96de12 | 2010-02-15 15:15:22 | [diff] [blame] | 23 | |
| 24 | class GURL; |
[email protected] | 8b96de12 | 2010-02-15 15:15:22 | [diff] [blame] | 25 | |
[email protected] | 60349d9 | 2011-09-06 11:00:41 | [diff] [blame] | 26 | namespace net { |
| 27 | class URLRequestContextGetter; |
| 28 | } |
| 29 | |
[email protected] | c8c7718 | 2011-12-21 15:04:47 | [diff] [blame] | 30 | namespace content { |
| 31 | |
[email protected] | 8b96de12 | 2010-02-15 15:15:22 | [diff] [blame] | 32 | // Provides storage for the access token used in the network request. |
[email protected] | 0e034f7 | 2011-12-21 13:41:19 | [diff] [blame] | 33 | class AccessTokenStore : public base::RefCountedThreadSafe<AccessTokenStore> { |
[email protected] | 8b96de12 | 2010-02-15 15:15:22 | [diff] [blame] | 34 | public: |
[email protected] | 93526f9 | 2010-02-19 16:37:42 | [diff] [blame] | 35 | // Map of server URLs to associated access token. |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 36 | typedef std::map<GURL, base::string16> AccessTokenSet; |
[email protected] | 81b14e7 | 2011-10-07 21:18:36 | [diff] [blame] | 37 | typedef base::Callback<void(AccessTokenSet, net::URLRequestContextGetter*)> |
[email protected] | 60349d9 | 2011-09-06 11:00:41 | [diff] [blame] | 38 | LoadAccessTokensCallbackType; |
[email protected] | 81b14e7 | 2011-10-07 21:18:36 | [diff] [blame] | 39 | |
[email protected] | 60349d9 | 2011-09-06 11:00:41 | [diff] [blame] | 40 | // |callback| will be invoked once per LoadAccessTokens call, after existing |
| 41 | // access tokens have been loaded from persistent store. As a convenience the |
| 42 | // URLRequestContextGetter is also supplied as an argument in |callback|, as |
| 43 | // in Chrome the call to obtain this must also be performed on the UI thread |
| 44 | // so it is efficient to piggyback it onto this request. |
| 45 | // Takes ownership of |callback|. |
[email protected] | f7f9819 | 2012-01-24 17:10:26 | [diff] [blame] | 46 | virtual void LoadAccessTokens( |
[email protected] | 0e034f7 | 2011-12-21 13:41:19 | [diff] [blame] | 47 | const LoadAccessTokensCallbackType& callback) = 0; |
[email protected] | 93526f9 | 2010-02-19 16:37:42 | [diff] [blame] | 48 | |
| 49 | virtual void SaveAccessToken( |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 50 | const GURL& server_url, const base::string16& access_token) = 0; |
[email protected] | 8b96de12 | 2010-02-15 15:15:22 | [diff] [blame] | 51 | |
| 52 | protected: |
[email protected] | e1d4edb | 2010-02-17 17:33:56 | [diff] [blame] | 53 | friend class base::RefCountedThreadSafe<AccessTokenStore>; |
[email protected] | f7f9819 | 2012-01-24 17:10:26 | [diff] [blame] | 54 | CONTENT_EXPORT AccessTokenStore() {} |
| 55 | CONTENT_EXPORT virtual ~AccessTokenStore() {} |
[email protected] | 8b96de12 | 2010-02-15 15:15:22 | [diff] [blame] | 56 | }; |
| 57 | |
[email protected] | c8c7718 | 2011-12-21 15:04:47 | [diff] [blame] | 58 | } // namespace content |
| 59 | |
| 60 | #endif // CONTENT_PUBLIC_BROWSER_ACCESS_TOKEN_STORE_H_ |