blob: 4a081d89623bf4109940c0244155ee732aaac031 [file] [log] [blame]
[email protected]8b96de122010-02-15 15:15:221// Copyright (c) 2010 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
[email protected]e1d4edb2010-02-17 17:33:565// Defines the Geolocation access token store, and associated factory.
6// An access token store is responsible for providing the API to persist a
7// single network provider's access token. The factory is responsible for
8// first loading tokens when required, and creating the associated token stores.
9// The API is a little more complex than one might wish, due to the need for
10// prefs access to happen asynchronously on the UI thread.
11// These APIs are provided as abstract base classes to allow mocking and testing
12// of clients, without dependency on browser process singleton objects etc.
13
[email protected]8b96de122010-02-15 15:15:2214#ifndef CHROME_BROWSER_GEOLOCATION_ACCESS_TOKEN_STORE_H_
15#define CHROME_BROWSER_GEOLOCATION_ACCESS_TOKEN_STORE_H_
16
[email protected]e1d4edb2010-02-17 17:33:5617#include <map>
18
[email protected]8b96de122010-02-15 15:15:2219#include "base/ref_counted.h"
20#include "base/string16.h"
[email protected]e1d4edb2010-02-17 17:33:5621#include "base/weak_ptr.h"
22#include "googleurl/src/gurl.h"
[email protected]8b96de122010-02-15 15:15:2223
24class GURL;
25class PrefService;
26
27// Provides storage for the access token used in the network request.
[email protected]e1d4edb2010-02-17 17:33:5628class AccessTokenStore : public base::RefCountedThreadSafe<AccessTokenStore> {
[email protected]8b96de122010-02-15 15:15:2229 public:
30 static void RegisterPrefs(PrefService* prefs);
31
[email protected]e1d4edb2010-02-17 17:33:5632 GURL server_url() const;
33 void SetAccessToken(const string16& access_token);
34 bool GetAccessToken(string16* access_token) const;
[email protected]8b96de122010-02-15 15:15:2235
36 protected:
[email protected]e1d4edb2010-02-17 17:33:5637 friend class base::RefCountedThreadSafe<AccessTokenStore>;
38 AccessTokenStore(
39 const GURL& url, bool token_valid, const string16& initial_access_token);
40 virtual ~AccessTokenStore();
41
42 virtual void DoSetAccessToken(const string16& access_token) = 0;
43
44 private:
45 const GURL url_;
46 bool access_token_valid_;
47 string16 access_token_;
48};
49
50// Factory for access token stores. Asynchronously loads all access tokens, and
51// calls back with a set of token stores one per server URL.
52class AccessTokenStoreFactory
53 : public base::RefCountedThreadSafe<AccessTokenStoreFactory> {
54 public:
55 typedef std::map<GURL, scoped_refptr<AccessTokenStore> > TokenStoreSet;
56 class Delegate {
57 public:
58 virtual void OnAccessTokenStoresCreated(
59 const TokenStoreSet& access_token_store) = 0;
60
61 protected:
62 virtual ~Delegate() {}
63 };
64 // delegate will recieve a single callback once existing access tokens have
65 // been loaded from persistent store.
66 // If default_url is valid, this additional URL will be added to the
67 // set of access token stores returned.
68 virtual void CreateAccessTokenStores(
69 const base::WeakPtr<AccessTokenStoreFactory::Delegate>& delegate,
70 const GURL& default_url) = 0;
71
72 protected:
73 friend class base::RefCountedThreadSafe<AccessTokenStoreFactory>;
74 ~AccessTokenStoreFactory();
[email protected]8b96de122010-02-15 15:15:2275};
76
77// Creates a new access token store backed by the global chome prefs.
[email protected]e1d4edb2010-02-17 17:33:5678AccessTokenStoreFactory* NewChromePrefsAccessTokenStoreFactory();
[email protected]8b96de122010-02-15 15:15:2279
80#endif // CHROME_BROWSER_GEOLOCATION_ACCESS_TOKEN_STORE_H_