#ifndef CHROME_BROWSER_POLICY_USER_POLICY_TOKEN_CACHE_H_
#define CHROME_BROWSER_POLICY_USER_POLICY_TOKEN_CACHE_H_
#include <string>
#include "base/basictypes.h"
#include "base/file_path.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/policy/cloud_policy_data_store.h"
namespace policy {
class UserPolicyTokenLoader
: public base::RefCountedThreadSafe<UserPolicyTokenLoader> {
public:
class Delegate {
public:
virtual ~Delegate();
virtual void OnTokenLoaded(const std::string& token,
const std::string& device_id) = 0;
};
UserPolicyTokenLoader(const base::WeakPtr<Delegate>& delegate,
const FilePath& cache_file);
void Load();
void Store(const std::string& token, const std::string& device_id);
private:
friend class base::RefCountedThreadSafe<UserPolicyTokenLoader>;
~UserPolicyTokenLoader();
void LoadOnFileThread();
void NotifyOnUIThread(const std::string& token,
const std::string& device_id);
void StoreOnFileThread(const std::string& token,
const std::string& device_id);
const base::WeakPtr<Delegate> delegate_;
const FilePath cache_file_;
DISALLOW_COPY_AND_ASSIGN(UserPolicyTokenLoader);
};
class UserPolicyTokenCache : public CloudPolicyDataStore::Observer,
public UserPolicyTokenLoader::Delegate {
public:
UserPolicyTokenCache(CloudPolicyDataStore* data_store,
const FilePath& cache_file);
virtual ~UserPolicyTokenCache();
void Load();
virtual void OnTokenLoaded(const std::string& token,
const std::string& device_id) OVERRIDE;
virtual void OnDeviceTokenChanged() OVERRIDE;
virtual void OnCredentialsChanged() OVERRIDE;
private:
base::WeakPtrFactory<UserPolicyTokenLoader::Delegate> weak_ptr_factory_;
CloudPolicyDataStore* data_store_;
scoped_refptr<UserPolicyTokenLoader> loader_;
std::string token_;
DISALLOW_COPY_AND_ASSIGN(UserPolicyTokenCache);
};
}
#endif