com.facebook
Class TokenCachingStrategy

java.lang.Object
  extended by com.facebook.TokenCachingStrategy
Direct Known Subclasses:
NonCachingTokenCachingStrategy, SharedPreferencesTokenCachingStrategy

public abstract class TokenCachingStrategy
extends Object

A base class for implementations of a Session token cache.

The Session constructor optionally takes a TokenCachingStrategy, from which it will attempt to load a cached token during construction. Also, whenever the Session updates its token, it will also save the token and associated state to the TokenCachingStrategy.

This is the only mechanism supported for an Android service to use Session. The service can create a custom TokenCachingStrategy that returns the Session provided by an Activity through which the user logged in to Facebook.


Field Summary
static String EXPIRATION_DATE_KEY
          The key used by Session to store the expiration date value in the Bundle during load and save.
static String LAST_REFRESH_DATE_KEY
          The key used by Session to store the last refresh date value in the Bundle during load and save.
static String PERMISSIONS_KEY
          The key used by Session to store the list of permissions granted by the token in the Bundle during load and save.
static String TOKEN_KEY
          The key used by Session to store the token value in the Bundle during load and save.
static String TOKEN_SOURCE_KEY
          The key used by Session to store an enum indicating the source of the token in the Bundle during load and save.
static String USER_FBID_KEY
          The key used by Session to store the user's id value in the Bundle during load and save.
 
Constructor Summary
TokenCachingStrategy()
           
 
Method Summary
abstract  void clear()
          Called when a Session learns its token is no longer valid or during a call to closeAndClearTokenInformation to clear the durable state associated with the token.
static Date getExpirationDate(Bundle bundle)
          Gets the cached expiration date from a Bundle.
static long getExpirationMilliseconds(Bundle bundle)
          Gets the cached expiration date from a Bundle.
static Date getLastRefreshDate(Bundle bundle)
          Gets the cached last refresh date from a Bundle.
static long getLastRefreshMilliseconds(Bundle bundle)
          Gets the cached last refresh date from a Bundle.
static List<String> getPermissions(Bundle bundle)
          Gets the cached list of permissions from a Bundle.
static AccessTokenSource getSource(Bundle bundle)
          Gets the cached enum indicating the source of the token from the Bundle.
static String getToken(Bundle bundle)
          Gets the cached token value from a Bundle.
static boolean hasTokenInformation(Bundle bundle)
          Returns a boolean indicating whether a Bundle contains properties that could be a valid saved token.
abstract  Bundle load()
          Called during Session construction to get the token state.
static void putExpirationDate(Bundle bundle, Date value)
          Puts the expiration date into a Bundle.
static void putExpirationMilliseconds(Bundle bundle, long value)
          Puts the expiration date into a Bundle.
static void putLastRefreshDate(Bundle bundle, Date value)
          Puts the last refresh date into a Bundle.
static void putLastRefreshMilliseconds(Bundle bundle, long value)
          Puts the last refresh date into a Bundle.
static void putPermissions(Bundle bundle, List<String> value)
          Puts the list of permissions into a Bundle.
static void putSource(Bundle bundle, AccessTokenSource value)
          Puts the enum indicating the source of the token into a Bundle.
static void putToken(Bundle bundle, String value)
          Puts the token value into a Bundle.
abstract  void save(Bundle bundle)
          Called when a Session updates its token.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TOKEN_KEY

public static final String TOKEN_KEY
The key used by Session to store the token value in the Bundle during load and save.

See Also:
Constant Field Values

EXPIRATION_DATE_KEY

public static final String EXPIRATION_DATE_KEY
The key used by Session to store the expiration date value in the Bundle during load and save.

See Also:
Constant Field Values

LAST_REFRESH_DATE_KEY

public static final String LAST_REFRESH_DATE_KEY
The key used by Session to store the last refresh date value in the Bundle during load and save.

See Also:
Constant Field Values

USER_FBID_KEY

public static final String USER_FBID_KEY
The key used by Session to store the user's id value in the Bundle during load and save.

See Also:
Constant Field Values

TOKEN_SOURCE_KEY

public static final String TOKEN_SOURCE_KEY
The key used by Session to store an enum indicating the source of the token in the Bundle during load and save.

See Also:
Constant Field Values

PERMISSIONS_KEY

public static final String PERMISSIONS_KEY
The key used by Session to store the list of permissions granted by the token in the Bundle during load and save.

See Also:
Constant Field Values
Constructor Detail

TokenCachingStrategy

public TokenCachingStrategy()
Method Detail

load

public abstract Bundle load()
Called during Session construction to get the token state. Typically this is loaded from a persistent store that was previously initialized via save. The caller may choose to keep a reference to the returned Bundle indefinitely. Therefore the TokenCachingStrategy should not store the returned Bundle and should return a new Bundle on every call to this method.

Returns:
A Bundle that represents the token state that was loaded.

save

public abstract void save(Bundle bundle)
Called when a Session updates its token. This is passed a Bundle of values that should be stored durably for the purpose of being returned from a later call to load. Some implementations may choose to store bundle beyond the scope of this call, so the caller should keep no references to the bundle to ensure that it is not modified later.

Parameters:
bundle - A Bundle that represents the token state to be saved.

clear

public abstract void clear()
Called when a Session learns its token is no longer valid or during a call to closeAndClearTokenInformation to clear the durable state associated with the token.


hasTokenInformation

public static boolean hasTokenInformation(Bundle bundle)
Returns a boolean indicating whether a Bundle contains properties that could be a valid saved token.

Parameters:
bundle - A Bundle to check for token information.
Returns:
a boolean indicating whether a Bundle contains properties that could be a valid saved token.

getToken

public static String getToken(Bundle bundle)
Gets the cached token value from a Bundle.

Parameters:
bundle - A Bundle in which the token value was stored.
Returns:
the cached token value, or null.
Throws:
NullPointerException - if the passed in Bundle is null

putToken

public static void putToken(Bundle bundle,
                            String value)
Puts the token value into a Bundle.

Parameters:
bundle - A Bundle in which the token value should be stored.
value - The String representing the token value, or null.
Throws:
NullPointerException - if the passed in Bundle or token value are null

getExpirationDate

public static Date getExpirationDate(Bundle bundle)
Gets the cached expiration date from a Bundle.

Parameters:
bundle - A Bundle in which the expiration date was stored.
Returns:
the cached expiration date, or null.
Throws:
NullPointerException - if the passed in Bundle is null

putExpirationDate

public static void putExpirationDate(Bundle bundle,
                                     Date value)
Puts the expiration date into a Bundle.

Parameters:
bundle - A Bundle in which the expiration date should be stored.
value - The Date representing the expiration date.
Throws:
NullPointerException - if the passed in Bundle or date value are null

getExpirationMilliseconds

public static long getExpirationMilliseconds(Bundle bundle)
Gets the cached expiration date from a Bundle.

Parameters:
bundle - A Bundle in which the expiration date was stored.
Returns:
the long representing the cached expiration date in milliseconds since the epoch, or 0.
Throws:
NullPointerException - if the passed in Bundle is null

putExpirationMilliseconds

public static void putExpirationMilliseconds(Bundle bundle,
                                             long value)
Puts the expiration date into a Bundle.

Parameters:
bundle - A Bundle in which the expiration date should be stored.
value - The long representing the expiration date in milliseconds since the epoch.
Throws:
NullPointerException - if the passed in Bundle is null

getPermissions

public static List<String> getPermissions(Bundle bundle)
Gets the cached list of permissions from a Bundle.

Parameters:
bundle - A Bundle in which the list of permissions was stored.
Returns:
the cached list of permissions.
Throws:
NullPointerException - if the passed in Bundle is null

putPermissions

public static void putPermissions(Bundle bundle,
                                  List<String> value)
Puts the list of permissions into a Bundle.

Parameters:
bundle - A Bundle in which the list of permissions should be stored.
value - The List<String> representing the list of permissions, or null.
Throws:
NullPointerException - if the passed in Bundle or permissions list are null

getSource

public static AccessTokenSource getSource(Bundle bundle)
Gets the cached enum indicating the source of the token from the Bundle.

Parameters:
bundle - A Bundle in which the enum was stored.
Returns:
enum indicating the source of the token
Throws:
NullPointerException - if the passed in Bundle is null

putSource

public static void putSource(Bundle bundle,
                             AccessTokenSource value)
Puts the enum indicating the source of the token into a Bundle.

Parameters:
bundle - A Bundle in which the enum should be stored.
value - enum indicating the source of the token
Throws:
NullPointerException - if the passed in Bundle is null

getLastRefreshDate

public static Date getLastRefreshDate(Bundle bundle)
Gets the cached last refresh date from a Bundle.

Parameters:
bundle - A Bundle in which the last refresh date was stored.
Returns:
the cached last refresh Date, or null.
Throws:
NullPointerException - if the passed in Bundle is null

putLastRefreshDate

public static void putLastRefreshDate(Bundle bundle,
                                      Date value)
Puts the last refresh date into a Bundle.

Parameters:
bundle - A Bundle in which the last refresh date should be stored.
value - The Date representing the last refresh date, or null.
Throws:
NullPointerException - if the passed in Bundle or date value are null

getLastRefreshMilliseconds

public static long getLastRefreshMilliseconds(Bundle bundle)
Gets the cached last refresh date from a Bundle.

Parameters:
bundle - A Bundle in which the last refresh date was stored.
Returns:
the cached last refresh date in milliseconds since the epoch.
Throws:
NullPointerException - if the passed in Bundle is null

putLastRefreshMilliseconds

public static void putLastRefreshMilliseconds(Bundle bundle,
                                              long value)
Puts the last refresh date into a Bundle.

Parameters:
bundle - A Bundle in which the last refresh date should be stored.
value - The long representing the last refresh date in milliseconds since the epoch.
Throws:
NullPointerException - if the passed in Bundle is null