Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / google_apis / gcm / engine / registration_request.h
index 47cce76..2936350 100644 (file)
@@ -12,7 +12,9 @@
 #include "base/callback.h"
 #include "base/memory/ref_counted.h"
 #include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
 #include "google_apis/gcm/base/gcm_export.h"
+#include "net/base/backoff_entry.h"
 #include "net/url_request/url_fetcher_delegate.h"
 
 namespace net {
@@ -27,8 +29,26 @@ namespace gcm {
 // be authorized to address the application using it's assigned registration ID.
 class GCM_EXPORT RegistrationRequest : public net::URLFetcherDelegate {
  public:
+  // This enum is also used in an UMA histogram (GCMRegistrationRequestStatus
+  // enum defined in tools/metrics/histograms/histogram.xml). Hence the entries
+  // here shouldn't be deleted or re-ordered and new ones should be added to
+  // the end.
+  enum Status {
+    SUCCESS,                    // Registration completed successfully.
+    INVALID_PARAMETERS,         // One of request paramteres was invalid.
+    INVALID_SENDER,             // One of the provided senders was invalid.
+    AUTHENTICATION_FAILED,      // Authentication failed.
+    DEVICE_REGISTRATION_ERROR,  // Chrome is not properly registered.
+    UNKNOWN_ERROR,              // Unknown error.
+    // NOTE: always keep this entry at the end. Add new status types only
+    // immediately above this line. Make sure to update the corresponding
+    // histogram enum accordingly.
+    STATUS_COUNT
+  };
+
   // Callback completing the registration request.
-  typedef base::Callback<void(const std::string& registration_id)>
+  typedef base::Callback<void(Status status,
+                              const std::string& registration_id)>
       RegistrationCallback;
 
   // Details of the of the Registration Request. Only user's android ID and
@@ -37,8 +57,6 @@ class GCM_EXPORT RegistrationRequest : public net::URLFetcherDelegate {
   struct GCM_EXPORT RequestInfo {
     RequestInfo(uint64 android_id,
                 uint64 security_token,
-                uint64 user_android_id,
-                int64 user_serial_number,
                 const std::string& app_id,
                 const std::string& cert,
                 const std::vector<std::string>& sender_ids);
@@ -48,10 +66,6 @@ class GCM_EXPORT RegistrationRequest : public net::URLFetcherDelegate {
     uint64 android_id;
     // Security token of the device.
     uint64 security_token;
-    // User's android ID. (Can be omitted in a single user scenario.)
-    uint64 user_android_id;
-    // User's serial number. (Can be omitted in a single user scenario.)
-    int64 user_serial_number;
     // Application ID.
     std::string app_id;
     // Certificate of the application.
@@ -62,6 +76,7 @@ class GCM_EXPORT RegistrationRequest : public net::URLFetcherDelegate {
 
   RegistrationRequest(
       const RequestInfo& request_info,
+      const net::BackoffEntry::Policy& backoff_policy,
       const RegistrationCallback& callback,
       scoped_refptr<net::URLRequestContextGetter> request_context_getter);
   virtual ~RegistrationRequest();
@@ -72,12 +87,19 @@ class GCM_EXPORT RegistrationRequest : public net::URLFetcherDelegate {
   virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
 
  private:
+  // Schedules a retry attempt, informs the backoff of a previous request's
+  // failure, when |update_backoff| is true.
+  void RetryWithBackoff(bool update_backoff);
+
   RegistrationCallback callback_;
   RequestInfo request_info_;
 
+  net::BackoffEntry backoff_entry_;
   scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
   scoped_ptr<net::URLFetcher> url_fetcher_;
 
+  base::WeakPtrFactory<RegistrationRequest> weak_ptr_factory_;
+
   DISALLOW_COPY_AND_ASSIGN(RegistrationRequest);
 };