#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 {
// 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
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);
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.
RegistrationRequest(
const RequestInfo& request_info,
+ const net::BackoffEntry::Policy& backoff_policy,
const RegistrationCallback& callback,
scoped_refptr<net::URLRequestContextGetter> request_context_getter);
virtual ~RegistrationRequest();
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);
};