[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 1 | // Copyright (c) 2011 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] | 87678d99 | 2011-02-28 17:33:30 | [diff] [blame] | 13 | #ifndef CONTENT_BROWSER_GEOLOCATION_ACCESS_TOKEN_STORE_H_ |
| 14 | #define CONTENT_BROWSER_GEOLOCATION_ACCESS_TOKEN_STORE_H_ |
[email protected] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 15 | #pragma once |
[email protected] | 8b96de12 | 2010-02-15 15:15:22 | [diff] [blame] | 16 | |
[email protected] | e1d4edb | 2010-02-17 17:33:56 | [diff] [blame] | 17 | #include <map> |
| 18 | |
[email protected] | 81b14e7 | 2011-10-07 21:18:36 | [diff] [blame^] | 19 | #include "base/callback.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 20 | #include "base/memory/ref_counted.h" |
[email protected] | 8b96de12 | 2010-02-15 15:15:22 | [diff] [blame] | 21 | #include "base/string16.h" |
[email protected] | a01efd2 | 2011-03-01 00:38:32 | [diff] [blame] | 22 | #include "content/browser/cancelable_request.h" |
[email protected] | 8d128d6 | 2011-09-13 22:11:57 | [diff] [blame] | 23 | #include "content/common/content_export.h" |
[email protected] | e1d4edb | 2010-02-17 17:33:56 | [diff] [blame] | 24 | #include "googleurl/src/gurl.h" |
[email protected] | 8b96de12 | 2010-02-15 15:15:22 | [diff] [blame] | 25 | |
| 26 | class GURL; |
[email protected] | 8b96de12 | 2010-02-15 15:15:22 | [diff] [blame] | 27 | |
[email protected] | 60349d9 | 2011-09-06 11:00:41 | [diff] [blame] | 28 | namespace net { |
| 29 | class URLRequestContextGetter; |
| 30 | } |
| 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] | 93526f9 | 2010-02-19 16:37:42 | [diff] [blame] | 33 | class AccessTokenStore : public base::RefCountedThreadSafe<AccessTokenStore>, |
| 34 | public CancelableRequestProvider { |
[email protected] | 8b96de12 | 2010-02-15 15:15:22 | [diff] [blame] | 35 | public: |
[email protected] | 8b96de12 | 2010-02-15 15:15:22 | [diff] [blame] | 36 | |
[email protected] | 93526f9 | 2010-02-19 16:37:42 | [diff] [blame] | 37 | // Map of server URLs to associated access token. |
| 38 | typedef std::map<GURL, string16> AccessTokenSet; |
[email protected] | 81b14e7 | 2011-10-07 21:18:36 | [diff] [blame^] | 39 | typedef base::Callback<void(AccessTokenSet, net::URLRequestContextGetter*)> |
[email protected] | 60349d9 | 2011-09-06 11:00:41 | [diff] [blame] | 40 | LoadAccessTokensCallbackType; |
[email protected] | 81b14e7 | 2011-10-07 21:18:36 | [diff] [blame^] | 41 | |
[email protected] | 60349d9 | 2011-09-06 11:00:41 | [diff] [blame] | 42 | // |callback| will be invoked once per LoadAccessTokens call, after existing |
| 43 | // access tokens have been loaded from persistent store. As a convenience the |
| 44 | // URLRequestContextGetter is also supplied as an argument in |callback|, as |
| 45 | // in Chrome the call to obtain this must also be performed on the UI thread |
| 46 | // so it is efficient to piggyback it onto this request. |
| 47 | // Takes ownership of |callback|. |
[email protected] | 93526f9 | 2010-02-19 16:37:42 | [diff] [blame] | 48 | // Returns a handle which can subsequently be used with CancelRequest(). |
[email protected] | f3112a5 | 2011-09-30 23:47:49 | [diff] [blame] | 49 | CONTENT_EXPORT Handle LoadAccessTokens( |
| 50 | CancelableRequestConsumerBase* consumer, |
[email protected] | 81b14e7 | 2011-10-07 21:18:36 | [diff] [blame^] | 51 | const LoadAccessTokensCallbackType& callback); |
[email protected] | 93526f9 | 2010-02-19 16:37:42 | [diff] [blame] | 52 | |
| 53 | virtual void SaveAccessToken( |
| 54 | const GURL& server_url, const string16& access_token) = 0; |
[email protected] | 8b96de12 | 2010-02-15 15:15:22 | [diff] [blame] | 55 | |
| 56 | protected: |
[email protected] | e1d4edb | 2010-02-17 17:33:56 | [diff] [blame] | 57 | friend class base::RefCountedThreadSafe<AccessTokenStore>; |
[email protected] | 8d128d6 | 2011-09-13 22:11:57 | [diff] [blame] | 58 | CONTENT_EXPORT AccessTokenStore(); |
| 59 | CONTENT_EXPORT virtual ~AccessTokenStore(); |
[email protected] | e1d4edb | 2010-02-17 17:33:56 | [diff] [blame] | 60 | |
[email protected] | 93526f9 | 2010-02-19 16:37:42 | [diff] [blame] | 61 | virtual void DoLoadAccessTokens( |
| 62 | scoped_refptr<CancelableRequest<LoadAccessTokensCallbackType> > req) = 0; |
[email protected] | e1d4edb | 2010-02-17 17:33:56 | [diff] [blame] | 63 | |
| 64 | private: |
[email protected] | 93526f9 | 2010-02-19 16:37:42 | [diff] [blame] | 65 | DISALLOW_COPY_AND_ASSIGN(AccessTokenStore); |
[email protected] | 8b96de12 | 2010-02-15 15:15:22 | [diff] [blame] | 66 | }; |
| 67 | |
[email protected] | 87678d99 | 2011-02-28 17:33:30 | [diff] [blame] | 68 | #endif // CONTENT_BROWSER_GEOLOCATION_ACCESS_TOKEN_STORE_H_ |