summaryrefslogtreecommitdiffstats
path: root/sync/notifier/gcm_network_channel.h
diff options
context:
space:
mode:
Diffstat (limited to 'sync/notifier/gcm_network_channel.h')
-rw-r--r--sync/notifier/gcm_network_channel.h45
1 files changed, 42 insertions, 3 deletions
diff --git a/sync/notifier/gcm_network_channel.h b/sync/notifier/gcm_network_channel.h
index b7d97fb..b8bd0a4 100644
--- a/sync/notifier/gcm_network_channel.h
+++ b/sync/notifier/gcm_network_channel.h
@@ -10,26 +10,65 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
+#include "base/threading/non_thread_safe.h"
+#include "net/url_request/url_fetcher_delegate.h"
#include "sync/base/sync_export.h"
+#include "sync/notifier/gcm_network_channel_delegate.h"
#include "sync/notifier/sync_system_resources.h"
+#include "url/gurl.h"
+
+class GoogleServiceAuthError;
namespace syncer {
// GCMNetworkChannel is an implementation of SyncNetworkChannel that routes
// messages through GCMProfileService.
class SYNC_EXPORT_PRIVATE GCMNetworkChannel
- : public SyncNetworkChannel {
+ : public SyncNetworkChannel,
+ public net::URLFetcherDelegate,
+ public base::NonThreadSafe {
public:
- explicit GCMNetworkChannel();
+ GCMNetworkChannel(
+ scoped_refptr<net::URLRequestContextGetter> request_context_getter,
+ scoped_ptr<GCMNetworkChannelDelegate> delegate);
virtual ~GCMNetworkChannel();
// SyncNetworkChannel implementation.
virtual void SendEncodedMessage(const std::string& encoded_message) OVERRIDE;
virtual void UpdateCredentials(const std::string& email,
- const std::string& token) OVERRIDE;
+ const std::string& token) OVERRIDE;
+
+ // URLFetcherDelegate implementation.
+ virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
private:
+ void OnRegisterComplete(const std::string& registration_id,
+ gcm::GCMClient::Result result);
+ void RequestAccessToken();
+ void OnGetTokenComplete(const GoogleServiceAuthError& error,
+ const std::string& token);
+ GURL BuildUrl();
+
+ scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
+ scoped_ptr<GCMNetworkChannelDelegate> delegate_;
+
+ // Message is saved until all conditions are met: there is valid
+ // registration_id and access_token.
+ std::string encoded_message_;
+
+ // Access token is saved because in case of auth failure from server we need
+ // to invalidate it.
+ std::string access_token_;
+
+ // GCM registration_id is requested one at startup and never refreshed until
+ // next restart.
+ std::string registration_id_;
+
+ scoped_ptr<net::URLFetcher> fetcher_;
+
+ base::WeakPtrFactory<GCMNetworkChannel> weak_factory_;
+
DISALLOW_COPY_AND_ASSIGN(GCMNetworkChannel);
};