Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef GOOGLE_APIS_GCM_ENGINE_REGISTRATION_REQUEST_H_ | 5 #ifndef GOOGLE_APIS_GCM_ENGINE_REGISTRATION_REQUEST_H_ |
| 6 #define GOOGLE_APIS_GCM_ENGINE_REGISTRATION_REQUEST_H_ | 6 #define GOOGLE_APIS_GCM_ENGINE_REGISTRATION_REQUEST_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 52 // immediately above this line. Make sure to update the corresponding | 52 // immediately above this line. Make sure to update the corresponding |
| 53 // histogram enum accordingly. | 53 // histogram enum accordingly. |
| 54 STATUS_COUNT | 54 STATUS_COUNT |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 // Callback completing the registration request. | 57 // Callback completing the registration request. |
| 58 typedef base::Callback<void(Status status, | 58 typedef base::Callback<void(Status status, |
| 59 const std::string& registration_id)> | 59 const std::string& registration_id)> |
| 60 RegistrationCallback; | 60 RegistrationCallback; |
| 61 | 61 |
| 62 // Details of the of the Registration Request. Only user's android ID and | 62 // Encapsulates the common info about a registration/token request. |
| 63 // its serial number are optional and can be set to 0. All other parameters | |
| 64 // have to be specified to successfully complete the call. | |
| 65 struct GCM_EXPORT RequestInfo { | 63 struct GCM_EXPORT RequestInfo { |
| 66 RequestInfo(uint64 android_id, | 64 RequestInfo(); |
| 67 uint64 security_token, | 65 virtual ~RequestInfo(); |
| 68 const std::string& app_id, | |
| 69 const std::vector<std::string>& sender_ids); | |
| 70 ~RequestInfo(); | |
| 71 | 66 |
| 67 virtual void BuildRequestHeaders(std::string* extra_headers); | |
| 68 virtual void BuildRequestBody(std::string* body); | |
| 69 virtual std::string GetSenders() const = 0; | |
| 70 | |
| 71 // Version to pass. | |
| 72 std::string chrome_version; | |
| 72 // Android ID of the device. | 73 // Android ID of the device. |
| 73 uint64 android_id; | 74 uint64 android_id; |
| 74 // Security token of the device. | 75 // Security token of the device. |
| 75 uint64 security_token; | 76 uint64 security_token; |
| 76 // Application ID. | 77 // Application ID. |
| 77 std::string app_id; | 78 std::string app_id; |
| 78 // Certificate of the application. | 79 }; |
| 79 std::string cert; | 80 |
| 81 // GCM registration request. | |
| 82 struct GCM_EXPORT GCMRequestInfo : public RequestInfo { | |
| 83 GCMRequestInfo(); | |
| 84 ~GCMRequestInfo() override; | |
| 85 | |
| 86 // RequestInfo overrides: | |
| 87 void BuildRequestBody(std::string* body) override; | |
| 88 std::string GetSenders() const override; | |
| 89 | |
| 80 // List of IDs of senders. Allowed up to 100. | 90 // List of IDs of senders. Allowed up to 100. |
| 81 std::vector<std::string> sender_ids; | 91 std::vector<std::string> sender_ids; |
| 82 }; | 92 }; |
| 83 | 93 |
| 94 // GCM token request. | |
|
fgorski
2015/05/13 18:32:41
Instance ID token request
jianli
2015/05/13 22:42:56
Done.
| |
| 95 struct GCM_EXPORT InstanceIDRequestInfo : public RequestInfo { | |
| 96 InstanceIDRequestInfo(); | |
| 97 ~InstanceIDRequestInfo() override; | |
| 98 | |
| 99 // RequestInfo overrides: | |
| 100 void BuildRequestBody(std::string* body) override; | |
| 101 std::string GetSenders() const override; | |
| 102 | |
| 103 std::string instance_id; | |
| 104 std::string authorized_entity; | |
| 105 std::string scope; | |
| 106 std::map<std::string, std::string> options; | |
| 107 }; | |
| 108 | |
| 84 RegistrationRequest( | 109 RegistrationRequest( |
| 85 const GURL& registration_url, | 110 const GURL& registration_url, |
| 86 const RequestInfo& request_info, | 111 scoped_ptr<RequestInfo> request_info, |
| 87 const net::BackoffEntry::Policy& backoff_policy, | 112 const net::BackoffEntry::Policy& backoff_policy, |
| 88 const RegistrationCallback& callback, | 113 const RegistrationCallback& callback, |
| 89 int max_retry_count, | 114 int max_retry_count, |
| 90 scoped_refptr<net::URLRequestContextGetter> request_context_getter, | 115 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
| 91 GCMStatsRecorder* recorder); | 116 GCMStatsRecorder* recorder); |
| 92 ~RegistrationRequest() override; | 117 ~RegistrationRequest() override; |
| 93 | 118 |
| 94 void Start(); | 119 void Start(); |
| 95 | 120 |
| 96 // URLFetcherDelegate implementation. | 121 // URLFetcherDelegate implementation. |
| 97 void OnURLFetchComplete(const net::URLFetcher* source) override; | 122 void OnURLFetchComplete(const net::URLFetcher* source) override; |
| 98 | 123 |
| 99 private: | 124 private: |
| 100 // Schedules a retry attempt, informs the backoff of a previous request's | 125 // Schedules a retry attempt, informs the backoff of a previous request's |
| 101 // failure, when |update_backoff| is true. | 126 // failure, when |update_backoff| is true. |
| 102 void RetryWithBackoff(bool update_backoff); | 127 void RetryWithBackoff(bool update_backoff); |
| 103 | 128 |
| 104 // Parse the response returned by the URL fetcher into token, and returns the | 129 // Parse the response returned by the URL fetcher into token, and returns the |
| 105 // status. | 130 // status. |
| 106 Status ParseResponse(const net::URLFetcher* source, std::string* token); | 131 Status ParseResponse(const net::URLFetcher* source, std::string* token); |
| 107 | 132 |
| 108 RegistrationCallback callback_; | 133 RegistrationCallback callback_; |
| 109 RequestInfo request_info_; | 134 scoped_ptr<RequestInfo> request_info_; |
| 110 GURL registration_url_; | 135 GURL registration_url_; |
| 111 | 136 |
| 112 net::BackoffEntry backoff_entry_; | 137 net::BackoffEntry backoff_entry_; |
| 113 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 138 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
| 114 scoped_ptr<net::URLFetcher> url_fetcher_; | 139 scoped_ptr<net::URLFetcher> url_fetcher_; |
| 115 int retries_left_; | 140 int retries_left_; |
| 116 base::TimeTicks request_start_time_; | 141 base::TimeTicks request_start_time_; |
| 117 | 142 |
| 118 // Recorder that records GCM activities for debugging purpose. Not owned. | 143 // Recorder that records GCM activities for debugging purpose. Not owned. |
| 119 GCMStatsRecorder* recorder_; | 144 GCMStatsRecorder* recorder_; |
| 120 | 145 |
| 121 base::WeakPtrFactory<RegistrationRequest> weak_ptr_factory_; | 146 base::WeakPtrFactory<RegistrationRequest> weak_ptr_factory_; |
| 122 | 147 |
| 123 DISALLOW_COPY_AND_ASSIGN(RegistrationRequest); | 148 DISALLOW_COPY_AND_ASSIGN(RegistrationRequest); |
| 124 }; | 149 }; |
| 125 | 150 |
| 126 } // namespace gcm | 151 } // namespace gcm |
| 127 | 152 |
| 128 #endif // GOOGLE_APIS_GCM_ENGINE_REGISTRATION_REQUEST_H_ | 153 #endif // GOOGLE_APIS_GCM_ENGINE_REGISTRATION_REQUEST_H_ |
| OLD | NEW |