#ifndef CHROME_BROWSER_INVALIDATION_GCM_INVALIDATION_BRIDGE_H_
#define CHROME_BROWSER_INVALIDATION_GCM_INVALIDATION_BRIDGE_H_
#include "base/callback.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/threading/non_thread_safe.h"
#include "chrome/browser/services/gcm/gcm_app_handler.h"
#include "google_apis/gaia/oauth2_token_service.h"
#include "google_apis/gcm/gcm_client.h"
#include "sync/notifier/gcm_network_channel_delegate.h"
namespace base {
class SingleThreadTaskRunner;
}
namespace gcm {
class GCMProfileService;
}
namespace invalidation {
class InvalidationAuthProvider;
class GCMInvalidationBridge : public gcm::GCMAppHandler,
public OAuth2TokenService::Consumer,
public base::NonThreadSafe {
public:
class Core;
GCMInvalidationBridge(gcm::GCMProfileService* gcm_profile_service,
InvalidationAuthProvider* auth_provider);
virtual ~GCMInvalidationBridge();
virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
const std::string& access_token,
const base::Time& expiration_time) OVERRIDE;
virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request,
const GoogleServiceAuthError& error) OVERRIDE;
virtual void ShutdownHandler() OVERRIDE;
virtual void OnMessage(const std::string& app_id,
const gcm::GCMClient::IncomingMessage& message)
OVERRIDE;
virtual void OnMessagesDeleted(const std::string& app_id) OVERRIDE;
virtual void OnSendError(
const std::string& app_id,
const gcm::GCMClient::SendErrorDetails& send_error_details) OVERRIDE;
scoped_ptr<syncer::GCMNetworkChannelDelegate> CreateDelegate();
void CoreInitializationDone(
base::WeakPtr<Core> core,
scoped_refptr<base::SingleThreadTaskRunner> core_thread_task_runner);
void RequestToken(
syncer::GCMNetworkChannelDelegate::RequestTokenCallback callback);
void InvalidateToken(const std::string& token);
void Register(syncer::GCMNetworkChannelDelegate::RegisterCallback callback);
void SubscribeForIncomingMessages();
void RegisterFinished(
syncer::GCMNetworkChannelDelegate::RegisterCallback callback,
const std::string& registration_id,
gcm::GCMClient::Result result);
private:
gcm::GCMProfileService* const gcm_profile_service_;
InvalidationAuthProvider* const auth_provider_;
base::WeakPtr<Core> core_;
scoped_refptr<base::SingleThreadTaskRunner> core_thread_task_runner_;
scoped_ptr<OAuth2TokenService::Request> access_token_request_;
syncer::GCMNetworkChannelDelegate::RequestTokenCallback
request_token_callback_;
bool subscribed_for_incoming_messages_;
base::WeakPtrFactory<GCMInvalidationBridge> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(GCMInvalidationBridge);
};
}
#endif