access_token_store.h revision 5821806d5e7f356e8fa4b058a389a808ea183019
13f8956d82bb40b15acee26017db0d13ddf43c80aPhilip Milne// Copyright (c) 2012 The Chromium Authors. All rights reserved.
23f8956d82bb40b15acee26017db0d13ddf43c80aPhilip Milne// Use of this source code is governed by a BSD-style license that can be
33f8956d82bb40b15acee26017db0d13ddf43c80aPhilip Milne// found in the LICENSE file.
43f8956d82bb40b15acee26017db0d13ddf43c80aPhilip Milne
53f8956d82bb40b15acee26017db0d13ddf43c80aPhilip Milne// Defines the Geolocation access token store, and associated factory function.
63f8956d82bb40b15acee26017db0d13ddf43c80aPhilip Milne// An access token store is responsible for providing the API to persist
73f8956d82bb40b15acee26017db0d13ddf43c80aPhilip Milne// access tokens, one at a time, and to load them back on mass.
83f8956d82bb40b15acee26017db0d13ddf43c80aPhilip Milne// The API is a little more complex than one might wish, due to the need for
93f8956d82bb40b15acee26017db0d13ddf43c80aPhilip Milne// prefs access to happen asynchronously on the UI thread.
103f8956d82bb40b15acee26017db0d13ddf43c80aPhilip Milne// This API is provided as abstract base classes to allow mocking and testing
113f8956d82bb40b15acee26017db0d13ddf43c80aPhilip Milne// of clients, without dependency on browser process singleton objects etc.
123f8956d82bb40b15acee26017db0d13ddf43c80aPhilip Milne
133f8956d82bb40b15acee26017db0d13ddf43c80aPhilip Milne#ifndef CONTENT_PUBLIC_BROWSER_ACCESS_TOKEN_STORE_H_
143f8956d82bb40b15acee26017db0d13ddf43c80aPhilip Milne#define CONTENT_PUBLIC_BROWSER_ACCESS_TOKEN_STORE_H_
153f8956d82bb40b15acee26017db0d13ddf43c80aPhilip Milne
163f8956d82bb40b15acee26017db0d13ddf43c80aPhilip Milne#include <map>
173f8956d82bb40b15acee26017db0d13ddf43c80aPhilip Milne
183f8956d82bb40b15acee26017db0d13ddf43c80aPhilip Milne#include "base/callback.h"
193f8956d82bb40b15acee26017db0d13ddf43c80aPhilip Milne#include "base/memory/ref_counted.h"
203f8956d82bb40b15acee26017db0d13ddf43c80aPhilip Milne#include "base/string16.h"
213f8956d82bb40b15acee26017db0d13ddf43c80aPhilip Milne#include "content/common/content_export.h"
223f8956d82bb40b15acee26017db0d13ddf43c80aPhilip Milne#include "googleurl/src/gurl.h"
233f8956d82bb40b15acee26017db0d13ddf43c80aPhilip Milne
243f8956d82bb40b15acee26017db0d13ddf43c80aPhilip Milneclass GURL;
253f8956d82bb40b15acee26017db0d13ddf43c80aPhilip Milne
263f8956d82bb40b15acee26017db0d13ddf43c80aPhilip Milnenamespace net {
27class URLRequestContextGetter;
28}
29
30namespace content {
31
32// Provides storage for the access token used in the network request.
33class AccessTokenStore : public base::RefCountedThreadSafe<AccessTokenStore> {
34 public:
35  // Map of server URLs to associated access token.
36  typedef std::map<GURL, string16> AccessTokenSet;
37  typedef base::Callback<void(AccessTokenSet, net::URLRequestContextGetter*)>
38      LoadAccessTokensCallbackType;
39
40  // |callback| will be invoked once per LoadAccessTokens call, after existing
41  // access tokens have been loaded from persistent store. As a convenience the
42  // URLRequestContextGetter is also supplied as an argument in |callback|, as
43  // in Chrome the call to obtain this must also be performed on the UI thread
44  // so it is efficient to piggyback it onto this request.
45  // Takes ownership of |callback|.
46  virtual void LoadAccessTokens(
47      const LoadAccessTokensCallbackType& callback) = 0;
48
49  virtual void SaveAccessToken(
50      const GURL& server_url, const string16& access_token) = 0;
51
52 protected:
53  friend class base::RefCountedThreadSafe<AccessTokenStore>;
54  CONTENT_EXPORT AccessTokenStore() {}
55  CONTENT_EXPORT virtual ~AccessTokenStore() {}
56};
57
58}  // namespace content
59
60#endif  // CONTENT_PUBLIC_BROWSER_ACCESS_TOKEN_STORE_H_
61