1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef GOOGLE_APIS_GCM_ENGINE_REGISTRATION_REQUEST_H_
6 #define GOOGLE_APIS_GCM_ENGINE_REGISTRATION_REQUEST_H_
11 #include "base/basictypes.h"
12 #include "base/callback.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h"
16 #include "google_apis/gcm/base/gcm_export.h"
17 #include "net/base/backoff_entry.h"
18 #include "net/url_request/url_fetcher_delegate.h"
21 class URLRequestContextGetter;
26 // Registration request is used to obtain registration IDs for applications that
27 // want to use GCM. It requires a set of parameters to be specified to identify
28 // the Chrome instance, the user, the application and a set of senders that will
29 // be authorized to address the application using it's assigned registration ID.
30 class GCM_EXPORT RegistrationRequest : public net::URLFetcherDelegate {
32 // This enum is also used in an UMA histogram (GCMRegistrationRequestStatus
33 // enum defined in tools/metrics/histograms/histogram.xml). Hence the entries
34 // here shouldn't be deleted or re-ordered and new ones should be added to
37 SUCCESS, // Registration completed successfully.
38 INVALID_PARAMETERS, // One of request paramteres was invalid.
39 INVALID_SENDER, // One of the provided senders was invalid.
40 AUTHENTICATION_FAILED, // Authentication failed.
41 DEVICE_REGISTRATION_ERROR, // Chrome is not properly registered.
42 UNKNOWN_ERROR, // Unknown error.
43 // NOTE: always keep this entry at the end. Add new status types only
44 // immediately above this line. Make sure to update the corresponding
45 // histogram enum accordingly.
49 // Callback completing the registration request.
50 typedef base::Callback<void(Status status,
51 const std::string& registration_id)>
54 // Details of the of the Registration Request. Only user's android ID and
55 // its serial number are optional and can be set to 0. All other parameters
56 // have to be specified to successfully complete the call.
57 struct GCM_EXPORT RequestInfo {
58 RequestInfo(uint64 android_id,
59 uint64 security_token,
60 const std::string& app_id,
61 const std::string& cert,
62 const std::vector<std::string>& sender_ids);
65 // Android ID of the device.
67 // Security token of the device.
68 uint64 security_token;
71 // Certificate of the application.
73 // List of IDs of senders. Allowed up to 100.
74 std::vector<std::string> sender_ids;
78 const RequestInfo& request_info,
79 const net::BackoffEntry::Policy& backoff_policy,
80 const RegistrationCallback& callback,
81 scoped_refptr<net::URLRequestContextGetter> request_context_getter);
82 virtual ~RegistrationRequest();
86 // URLFetcherDelegate implementation.
87 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
90 // Schedules a retry attempt, informs the backoff of a previous request's
91 // failure, when |update_backoff| is true.
92 void RetryWithBackoff(bool update_backoff);
94 RegistrationCallback callback_;
95 RequestInfo request_info_;
97 net::BackoffEntry backoff_entry_;
98 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
99 scoped_ptr<net::URLFetcher> url_fetcher_;
101 base::WeakPtrFactory<RegistrationRequest> weak_ptr_factory_;
103 DISALLOW_COPY_AND_ASSIGN(RegistrationRequest);
108 #endif // GOOGLE_APIS_GCM_ENGINE_REGISTRATION_REQUEST_H_