OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Defines the Geolocation access token store, and associated factory function. | 5 // Defines the Geolocation access token store, and associated factory function. |
6 // An access token store is responsible for providing the API to persist | 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. | 7 // access tokens, one at a time, and to load them back on mass. |
8 // The API is a little more complex than one might wish, due to the need for | 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. | 9 // prefs access to happen asynchronously on the UI thread. |
10 // This API is provided as abstract base classes to allow mocking and testing | 10 // This API is provided as abstract base classes to allow mocking and testing |
11 // of clients, without dependency on browser process singleton objects etc. | 11 // of clients, without dependency on browser process singleton objects etc. |
12 | 12 |
13 #ifndef CONTENT_BROWSER_GEOLOCATION_ACCESS_TOKEN_STORE_H_ | 13 #ifndef CONTENT_BROWSER_GEOLOCATION_ACCESS_TOKEN_STORE_H_ |
14 #define CONTENT_BROWSER_GEOLOCATION_ACCESS_TOKEN_STORE_H_ | 14 #define CONTENT_BROWSER_GEOLOCATION_ACCESS_TOKEN_STORE_H_ |
15 #pragma once | 15 #pragma once |
16 | 16 |
17 #include <map> | 17 #include <map> |
18 | 18 |
19 #include "base/callback_old.h" | 19 #include "base/callback_old.h" |
20 #include "base/memory/ref_counted.h" | 20 #include "base/memory/ref_counted.h" |
21 #include "base/string16.h" | 21 #include "base/string16.h" |
22 #include "content/browser/cancelable_request.h" | 22 #include "content/browser/cancelable_request.h" |
23 #include "googleurl/src/gurl.h" | 23 #include "googleurl/src/gurl.h" |
24 | 24 |
25 class GURL; | 25 class GURL; |
26 class PrefService; | |
27 | 26 |
28 // Provides storage for the access token used in the network request. | 27 // Provides storage for the access token used in the network request. |
29 class AccessTokenStore : public base::RefCountedThreadSafe<AccessTokenStore>, | 28 class AccessTokenStore : public base::RefCountedThreadSafe<AccessTokenStore>, |
30 public CancelableRequestProvider { | 29 public CancelableRequestProvider { |
31 public: | 30 public: |
32 static void RegisterPrefs(PrefService* prefs); | |
33 | 31 |
34 // Map of server URLs to associated access token. | 32 // Map of server URLs to associated access token. |
35 typedef std::map<GURL, string16> AccessTokenSet; | 33 typedef std::map<GURL, string16> AccessTokenSet; |
36 typedef Callback1<AccessTokenSet>::Type LoadAccessTokensCallbackType; | 34 typedef Callback1<AccessTokenSet>::Type LoadAccessTokensCallbackType; |
37 // callback will be invoked once, after existing access tokens have | 35 // callback will be invoked once, after existing access tokens have |
38 // been loaded from persistent store. Takes ownership of callback. | 36 // been loaded from persistent store. Takes ownership of callback. |
39 // Returns a handle which can subsequently be used with CancelRequest(). | 37 // Returns a handle which can subsequently be used with CancelRequest(). |
40 Handle LoadAccessTokens(CancelableRequestConsumerBase* consumer, | 38 Handle LoadAccessTokens(CancelableRequestConsumerBase* consumer, |
41 LoadAccessTokensCallbackType* callback); | 39 LoadAccessTokensCallbackType* callback); |
42 | 40 |
43 virtual void SaveAccessToken( | 41 virtual void SaveAccessToken( |
44 const GURL& server_url, const string16& access_token) = 0; | 42 const GURL& server_url, const string16& access_token) = 0; |
45 | 43 |
46 protected: | 44 protected: |
47 friend class base::RefCountedThreadSafe<AccessTokenStore>; | 45 friend class base::RefCountedThreadSafe<AccessTokenStore>; |
48 AccessTokenStore(); | 46 AccessTokenStore(); |
49 virtual ~AccessTokenStore(); | 47 virtual ~AccessTokenStore(); |
50 | 48 |
51 virtual void DoLoadAccessTokens( | 49 virtual void DoLoadAccessTokens( |
52 scoped_refptr<CancelableRequest<LoadAccessTokensCallbackType> > req) = 0; | 50 scoped_refptr<CancelableRequest<LoadAccessTokensCallbackType> > req) = 0; |
53 | 51 |
54 private: | 52 private: |
55 DISALLOW_COPY_AND_ASSIGN(AccessTokenStore); | 53 DISALLOW_COPY_AND_ASSIGN(AccessTokenStore); |
56 }; | 54 }; |
57 | 55 |
58 // Creates a new access token store backed by the global chome prefs. | |
59 AccessTokenStore* NewChromePrefsAccessTokenStore(); | |
60 | |
61 #endif // CONTENT_BROWSER_GEOLOCATION_ACCESS_TOKEN_STORE_H_ | 56 #endif // CONTENT_BROWSER_GEOLOCATION_ACCESS_TOKEN_STORE_H_ |
OLD | NEW |