#ifndef GOOGLE_APIS_GAIA_MERGE_SESSION_HELPER_H_
#define GOOGLE_APIS_GAIA_MERGE_SESSION_HELPER_H_
#include <deque>
#include "base/observer_list.h"
#include "google_apis/gaia/gaia_auth_consumer.h"
#include "google_apis/gaia/ubertoken_fetcher.h"
#include "net/url_request/url_fetcher_delegate.h"
class GaiaAuthFetcher;
class GoogleServiceAuthError;
class OAuth2TokenService;
namespace net {
class URLRequestContextGetter;
}
class MergeSessionHelper : public GaiaAuthConsumer,
public UbertokenConsumer,
public net::URLFetcherDelegate {
public:
class Observer {
public:
virtual void MergeSessionCompleted(const std::string& account_id,
const GoogleServiceAuthError& error) = 0;
protected:
virtual ~Observer() {}
};
MergeSessionHelper(OAuth2TokenService* token_service,
net::URLRequestContextGetter* request_context,
Observer* observer);
virtual ~MergeSessionHelper();
void LogIn(const std::string& account_id);
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
void CancelAll();
void LogOut(const std::string& account_id,
const std::vector<std::string>& accounts);
void LogOutAllAccounts();
private:
virtual void OnUbertokenSuccess(const std::string& token) OVERRIDE;
virtual void OnUbertokenFailure(const GoogleServiceAuthError& error) OVERRIDE;
virtual void OnMergeSessionSuccess(const std::string& data) OVERRIDE;
virtual void OnMergeSessionFailure(const GoogleServiceAuthError& error)
OVERRIDE;
void LogOutInternal(const std::string& account_id,
const std::vector<std::string>& accounts);
virtual void StartFetching();
virtual void StartLogOutUrlFetch();
void SignalComplete(const std::string& account_id,
const GoogleServiceAuthError& error);
void HandleNextAccount();
virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
OAuth2TokenService* token_service_;
net::URLRequestContextGetter* request_context_;
scoped_ptr<GaiaAuthFetcher> gaia_auth_fetcher_;
scoped_ptr<UbertokenFetcher> uber_token_fetcher_;
std::deque<std::string> accounts_;
ObserverList<Observer, true> observer_list_;
DISALLOW_COPY_AND_ASSIGN(MergeSessionHelper);
};
#endif