[email protected] | 8b96de12 | 2010-02-15 15:15:22 | [diff] [blame] | 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 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] | 8b96de12 | 2010-02-15 15:15:22 | [diff] [blame] | 13 | #ifndef CHROME_BROWSER_GEOLOCATION_ACCESS_TOKEN_STORE_H_ |
| 14 | #define CHROME_BROWSER_GEOLOCATION_ACCESS_TOKEN_STORE_H_ |
| 15 | |
[email protected] | e1d4edb | 2010-02-17 17:33:56 | [diff] [blame] | 16 | #include <map> |
| 17 | |
[email protected] | 8b96de12 | 2010-02-15 15:15:22 | [diff] [blame] | 18 | #include "base/ref_counted.h" |
| 19 | #include "base/string16.h" |
[email protected] | 93526f9 | 2010-02-19 16:37:42 | [diff] [blame^] | 20 | #include "base/task.h" |
| 21 | #include "chrome/browser/cancelable_request.h" |
[email protected] | e1d4edb | 2010-02-17 17:33:56 | [diff] [blame] | 22 | #include "googleurl/src/gurl.h" |
[email protected] | 8b96de12 | 2010-02-15 15:15:22 | [diff] [blame] | 23 | |
| 24 | class GURL; |
| 25 | class PrefService; |
| 26 | |
| 27 | // Provides storage for the access token used in the network request. |
[email protected] | 93526f9 | 2010-02-19 16:37:42 | [diff] [blame^] | 28 | class AccessTokenStore : public base::RefCountedThreadSafe<AccessTokenStore>, |
| 29 | public CancelableRequestProvider { |
[email protected] | 8b96de12 | 2010-02-15 15:15:22 | [diff] [blame] | 30 | public: |
| 31 | static void RegisterPrefs(PrefService* prefs); |
| 32 | |
[email protected] | 93526f9 | 2010-02-19 16:37:42 | [diff] [blame^] | 33 | // Map of server URLs to associated access token. |
| 34 | typedef std::map<GURL, string16> AccessTokenSet; |
| 35 | typedef Callback1<AccessTokenSet>::Type LoadAccessTokensCallbackType; |
| 36 | // callback will be invoked once, after existing access tokens have |
| 37 | // been loaded from persistent store. Takes ownership of callback. |
| 38 | // Returns a handle which can subsequently be used with CancelRequest(). |
| 39 | Handle LoadAccessTokens(CancelableRequestConsumerBase* consumer, |
| 40 | LoadAccessTokensCallbackType* callback); |
| 41 | |
| 42 | virtual void SaveAccessToken( |
| 43 | const GURL& server_url, const string16& access_token) = 0; |
[email protected] | 8b96de12 | 2010-02-15 15:15:22 | [diff] [blame] | 44 | |
| 45 | protected: |
[email protected] | e1d4edb | 2010-02-17 17:33:56 | [diff] [blame] | 46 | friend class base::RefCountedThreadSafe<AccessTokenStore>; |
[email protected] | 93526f9 | 2010-02-19 16:37:42 | [diff] [blame^] | 47 | AccessTokenStore(); |
[email protected] | e1d4edb | 2010-02-17 17:33:56 | [diff] [blame] | 48 | virtual ~AccessTokenStore(); |
| 49 | |
[email protected] | 93526f9 | 2010-02-19 16:37:42 | [diff] [blame^] | 50 | virtual void DoLoadAccessTokens( |
| 51 | scoped_refptr<CancelableRequest<LoadAccessTokensCallbackType> > req) = 0; |
[email protected] | e1d4edb | 2010-02-17 17:33:56 | [diff] [blame] | 52 | |
| 53 | private: |
[email protected] | 93526f9 | 2010-02-19 16:37:42 | [diff] [blame^] | 54 | DISALLOW_COPY_AND_ASSIGN(AccessTokenStore); |
[email protected] | 8b96de12 | 2010-02-15 15:15:22 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | // Creates a new access token store backed by the global chome prefs. |
[email protected] | 93526f9 | 2010-02-19 16:37:42 | [diff] [blame^] | 58 | AccessTokenStore* NewChromePrefsAccessTokenStore(); |
[email protected] | 8b96de12 | 2010-02-15 15:15:22 | [diff] [blame] | 59 | |
| 60 | #endif // CHROME_BROWSER_GEOLOCATION_ACCESS_TOKEN_STORE_H_ |