[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] | 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] | 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] | 8d128d6 | 2011-09-13 22:11:57 | [diff] [blame] | 22 | #include "content/common/content_export.h" |
[email protected] | e1d4edb | 2010-02-17 17:33:56 | [diff] [blame] | 23 | #include "googleurl/src/gurl.h" |
[email protected] | 8b96de12 | 2010-02-15 15:15:22 | [diff] [blame] | 24 | |
| 25 | class GURL; |
[email protected] | 8b96de12 | 2010-02-15 15:15:22 | [diff] [blame] | 26 | |
[email protected] | 60349d9 | 2011-09-06 11:00:41 | [diff] [blame] | 27 | namespace net { |
| 28 | class URLRequestContextGetter; |
| 29 | } |
| 30 | |
[email protected] | c8c7718 | 2011-12-21 15:04:47 | [diff] [blame^] | 31 | namespace content { |
| 32 | |
[email protected] | 8b96de12 | 2010-02-15 15:15:22 | [diff] [blame] | 33 | // Provides storage for the access token used in the network request. |
[email protected] | 0e034f7 | 2011-12-21 13:41:19 | [diff] [blame] | 34 | class AccessTokenStore : public base::RefCountedThreadSafe<AccessTokenStore> { |
[email protected] | 8b96de12 | 2010-02-15 15:15:22 | [diff] [blame] | 35 | public: |
[email protected] | 93526f9 | 2010-02-19 16:37:42 | [diff] [blame] | 36 | // Map of server URLs to associated access token. |
| 37 | typedef std::map<GURL, string16> AccessTokenSet; |
[email protected] | 81b14e7 | 2011-10-07 21:18:36 | [diff] [blame] | 38 | typedef base::Callback<void(AccessTokenSet, net::URLRequestContextGetter*)> |
[email protected] | 60349d9 | 2011-09-06 11:00:41 | [diff] [blame] | 39 | LoadAccessTokensCallbackType; |
[email protected] | 81b14e7 | 2011-10-07 21:18:36 | [diff] [blame] | 40 | |
[email protected] | 60349d9 | 2011-09-06 11:00:41 | [diff] [blame] | 41 | // |callback| will be invoked once per LoadAccessTokens call, after existing |
| 42 | // access tokens have been loaded from persistent store. As a convenience the |
| 43 | // URLRequestContextGetter is also supplied as an argument in |callback|, as |
| 44 | // in Chrome the call to obtain this must also be performed on the UI thread |
| 45 | // so it is efficient to piggyback it onto this request. |
| 46 | // Takes ownership of |callback|. |
[email protected] | 0e034f7 | 2011-12-21 13:41:19 | [diff] [blame] | 47 | CONTENT_EXPORT virtual void LoadAccessTokens( |
| 48 | const LoadAccessTokensCallbackType& callback) = 0; |
[email protected] | 93526f9 | 2010-02-19 16:37:42 | [diff] [blame] | 49 | |
| 50 | virtual void SaveAccessToken( |
| 51 | const GURL& server_url, const string16& access_token) = 0; |
[email protected] | 8b96de12 | 2010-02-15 15:15:22 | [diff] [blame] | 52 | |
| 53 | protected: |
[email protected] | e1d4edb | 2010-02-17 17:33:56 | [diff] [blame] | 54 | friend class base::RefCountedThreadSafe<AccessTokenStore>; |
[email protected] | 8d128d6 | 2011-09-13 22:11:57 | [diff] [blame] | 55 | CONTENT_EXPORT AccessTokenStore(); |
| 56 | CONTENT_EXPORT virtual ~AccessTokenStore(); |
[email protected] | e1d4edb | 2010-02-17 17:33:56 | [diff] [blame] | 57 | |
[email protected] | e1d4edb | 2010-02-17 17:33:56 | [diff] [blame] | 58 | private: |
[email protected] | 93526f9 | 2010-02-19 16:37:42 | [diff] [blame] | 59 | DISALLOW_COPY_AND_ASSIGN(AccessTokenStore); |
[email protected] | 8b96de12 | 2010-02-15 15:15:22 | [diff] [blame] | 60 | }; |
| 61 | |
[email protected] | c8c7718 | 2011-12-21 15:04:47 | [diff] [blame^] | 62 | } // namespace content |
| 63 | |
| 64 | #endif // CONTENT_PUBLIC_BROWSER_ACCESS_TOKEN_STORE_H_ |