OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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 | |
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. | |
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. | |
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. | |
12 | |
13 #ifndef DEVICE_GEOLOCATION_ACCESS_TOKEN_STORE_H_ | |
14 #define DEVICE_GEOLOCATION_ACCESS_TOKEN_STORE_H_ | |
15 | |
16 #include <map> | |
17 | |
18 #include "base/callback.h" | |
19 #include "base/memory/ref_counted.h" | |
20 #include "base/strings/string16.h" | |
21 #include "device/geolocation/geolocation_export.h" | |
22 #include "net/url_request/url_request_context_getter.h" | |
23 #include "url/gurl.h" | |
24 | |
25 class GURL; | |
26 | |
27 namespace device { | |
28 | |
29 // Provides storage for the access token used in the network request. | |
30 class AccessTokenStore : public base::RefCountedThreadSafe<AccessTokenStore> { | |
31 public: | |
32 // Map of server URLs to associated access token. | |
33 typedef std::map<GURL, base::string16> AccessTokenMap; | |
34 typedef base::Callback< | |
35 void(AccessTokenMap, const scoped_refptr<net::URLRequestContextGetter>&)> | |
36 LoadAccessTokensCallback; | |
37 | |
38 // |callback| will be invoked once per LoadAccessTokens call, after existing | |
39 // access tokens have been loaded from persistent store. As a convenience the | |
40 // URLRequestContextGetter is also supplied as an argument in |callback|, as | |
41 // in Chrome the call to obtain this must also be performed on the UI thread | |
42 // so it is efficient to piggyback it onto this request. | |
43 virtual void LoadAccessTokens(const LoadAccessTokensCallback& callback) = 0; | |
44 | |
45 virtual void SaveAccessToken( | |
46 const GURL& server_url, const base::string16& access_token) = 0; | |
47 | |
48 protected: | |
49 friend class base::RefCountedThreadSafe<AccessTokenStore>; | |
50 DEVICE_GEOLOCATION_EXPORT AccessTokenStore() {} | |
51 DEVICE_GEOLOCATION_EXPORT virtual ~AccessTokenStore() {} | |
52 }; | |
53 | |
54 } // namespace device | |
55 | |
56 #endif // DEVICE_GEOLOCATION_ACCESS_TOKEN_STORE_H_ | |
OLD | NEW |