blob: 2089dfbc43c4e02f176ea6071ef1a482a64a93c9 [file] [log] [blame]
[email protected]3b63f8f42011-03-28 01:54:151// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]8b96de122010-02-15 15:15:222// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]93526f92010-02-19 16:37:425// 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]e1d4edb2010-02-17 17:33:568// 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]93526f92010-02-19 16:37:4210// This API is provided as abstract base classes to allow mocking and testing
[email protected]e1d4edb2010-02-17 17:33:5611// of clients, without dependency on browser process singleton objects etc.
12
[email protected]87678d992011-02-28 17:33:3013#ifndef CONTENT_BROWSER_GEOLOCATION_ACCESS_TOKEN_STORE_H_
14#define CONTENT_BROWSER_GEOLOCATION_ACCESS_TOKEN_STORE_H_
[email protected]32b76ef2010-07-26 23:08:2415#pragma once
[email protected]8b96de122010-02-15 15:15:2216
[email protected]e1d4edb2010-02-17 17:33:5617#include <map>
18
[email protected]81b14e72011-10-07 21:18:3619#include "base/callback.h"
[email protected]3b63f8f42011-03-28 01:54:1520#include "base/memory/ref_counted.h"
[email protected]8b96de122010-02-15 15:15:2221#include "base/string16.h"
[email protected]a01efd22011-03-01 00:38:3222#include "content/browser/cancelable_request.h"
[email protected]8d128d62011-09-13 22:11:5723#include "content/common/content_export.h"
[email protected]e1d4edb2010-02-17 17:33:5624#include "googleurl/src/gurl.h"
[email protected]8b96de122010-02-15 15:15:2225
26class GURL;
[email protected]8b96de122010-02-15 15:15:2227
[email protected]60349d92011-09-06 11:00:4128namespace net {
29class URLRequestContextGetter;
30}
31
[email protected]8b96de122010-02-15 15:15:2232// Provides storage for the access token used in the network request.
[email protected]93526f92010-02-19 16:37:4233class AccessTokenStore : public base::RefCountedThreadSafe<AccessTokenStore>,
34 public CancelableRequestProvider {
[email protected]8b96de122010-02-15 15:15:2235 public:
[email protected]8b96de122010-02-15 15:15:2236
[email protected]93526f92010-02-19 16:37:4237 // Map of server URLs to associated access token.
38 typedef std::map<GURL, string16> AccessTokenSet;
[email protected]81b14e72011-10-07 21:18:3639 typedef base::Callback<void(AccessTokenSet, net::URLRequestContextGetter*)>
[email protected]60349d92011-09-06 11:00:4140 LoadAccessTokensCallbackType;
[email protected]81b14e72011-10-07 21:18:3641
[email protected]60349d92011-09-06 11:00:4142 // |callback| will be invoked once per LoadAccessTokens call, after existing
43 // access tokens have been loaded from persistent store. As a convenience the
44 // URLRequestContextGetter is also supplied as an argument in |callback|, as
45 // in Chrome the call to obtain this must also be performed on the UI thread
46 // so it is efficient to piggyback it onto this request.
47 // Takes ownership of |callback|.
[email protected]93526f92010-02-19 16:37:4248 // Returns a handle which can subsequently be used with CancelRequest().
[email protected]f3112a52011-09-30 23:47:4949 CONTENT_EXPORT Handle LoadAccessTokens(
50 CancelableRequestConsumerBase* consumer,
[email protected]81b14e72011-10-07 21:18:3651 const LoadAccessTokensCallbackType& callback);
[email protected]93526f92010-02-19 16:37:4252
53 virtual void SaveAccessToken(
54 const GURL& server_url, const string16& access_token) = 0;
[email protected]8b96de122010-02-15 15:15:2255
56 protected:
[email protected]e1d4edb2010-02-17 17:33:5657 friend class base::RefCountedThreadSafe<AccessTokenStore>;
[email protected]8d128d62011-09-13 22:11:5758 CONTENT_EXPORT AccessTokenStore();
59 CONTENT_EXPORT virtual ~AccessTokenStore();
[email protected]e1d4edb2010-02-17 17:33:5660
[email protected]93526f92010-02-19 16:37:4261 virtual void DoLoadAccessTokens(
62 scoped_refptr<CancelableRequest<LoadAccessTokensCallbackType> > req) = 0;
[email protected]e1d4edb2010-02-17 17:33:5663
64 private:
[email protected]93526f92010-02-19 16:37:4265 DISALLOW_COPY_AND_ASSIGN(AccessTokenStore);
[email protected]8b96de122010-02-15 15:15:2266};
67
[email protected]87678d992011-02-28 17:33:3068#endif // CONTENT_BROWSER_GEOLOCATION_ACCESS_TOKEN_STORE_H_