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> |
Nicolas Zea
2015/05/26 16:39:15
#include string
jianli
2015/05/26 20:49:39
Done.
| |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
17 #include "google_apis/gcm/base/gcm_export.h" | 17 #include "google_apis/gcm/base/gcm_export.h" |
18 #include "net/base/backoff_entry.h" | 18 #include "net/base/backoff_entry.h" |
19 #include "net/url_request/url_fetcher_delegate.h" | 19 #include "net/url_request/url_fetcher_delegate.h" |
(...skipping 32 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 // Defines the common info about a registration/token request. All parameters |
63 // its serial number are optional and can be set to 0. All other parameters | 63 // are mandatory. |
64 // have to be specified to successfully complete the call. | |
65 struct GCM_EXPORT RequestInfo { | 64 struct GCM_EXPORT RequestInfo { |
66 RequestInfo(uint64 android_id, | 65 RequestInfo(uint64 android_id, |
67 uint64 security_token, | 66 uint64 security_token, |
68 const std::string& app_id, | 67 const std::string& app_id); |
69 const std::vector<std::string>& sender_ids); | |
70 ~RequestInfo(); | 68 ~RequestInfo(); |
71 | 69 |
72 // Android ID of the device. | 70 // Android ID of the device. |
73 uint64 android_id; | 71 uint64 android_id; |
74 // Security token of the device. | 72 // Security token of the device. |
75 uint64 security_token; | 73 uint64 security_token; |
76 // Application ID. | 74 // Application ID. |
77 std::string app_id; | 75 std::string app_id; |
78 // Certificate of the application. | 76 }; |
79 std::string cert; | 77 |
80 // List of IDs of senders. Allowed up to 100. | 78 // Encapsulates the custom logic that is needed to build and process the |
81 std::vector<std::string> sender_ids; | 79 // registration request. |
80 class GCM_EXPORT CustomRequestHandler { | |
81 public: | |
82 CustomRequestHandler(); | |
83 virtual ~CustomRequestHandler(); | |
84 | |
85 virtual void BuildRequestBody(std::string* body) = 0; | |
Nicolas Zea
2015/05/26 16:39:15
Comment describing what this method does and when
jianli
2015/05/26 20:49:39
Done.
| |
82 }; | 86 }; |
83 | 87 |
84 RegistrationRequest( | 88 RegistrationRequest( |
85 const GURL& registration_url, | 89 const GURL& registration_url, |
86 const RequestInfo& request_info, | 90 const RequestInfo& request_info, |
91 scoped_ptr<CustomRequestHandler> custom_request_handler, | |
87 const net::BackoffEntry::Policy& backoff_policy, | 92 const net::BackoffEntry::Policy& backoff_policy, |
88 const RegistrationCallback& callback, | 93 const RegistrationCallback& callback, |
89 int max_retry_count, | 94 int max_retry_count, |
90 scoped_refptr<net::URLRequestContextGetter> request_context_getter, | 95 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
91 GCMStatsRecorder* recorder); | 96 GCMStatsRecorder* recorder, |
97 const std::string& source_to_record); | |
92 ~RegistrationRequest() override; | 98 ~RegistrationRequest() override; |
93 | 99 |
94 void Start(); | 100 void Start(); |
95 | 101 |
96 // URLFetcherDelegate implementation. | 102 // URLFetcherDelegate implementation. |
97 void OnURLFetchComplete(const net::URLFetcher* source) override; | 103 void OnURLFetchComplete(const net::URLFetcher* source) override; |
98 | 104 |
99 private: | 105 private: |
100 // Schedules a retry attempt, informs the backoff of a previous request's | 106 // Schedules a retry attempt, informs the backoff of a previous request's |
101 // failure, when |update_backoff| is true. | 107 // failure, when |update_backoff| is true. |
102 void RetryWithBackoff(bool update_backoff); | 108 void RetryWithBackoff(bool update_backoff); |
103 | 109 |
110 void BuildRequestHeaders(std::string* extra_headers); | |
111 void BuildRequestBody(std::string* body); | |
112 | |
104 // Parse the response returned by the URL fetcher into token, and returns the | 113 // Parse the response returned by the URL fetcher into token, and returns the |
105 // status. | 114 // status. |
106 Status ParseResponse(const net::URLFetcher* source, std::string* token); | 115 Status ParseResponse(const net::URLFetcher* source, std::string* token); |
107 | 116 |
108 RegistrationCallback callback_; | 117 RegistrationCallback callback_; |
109 RequestInfo request_info_; | 118 RequestInfo request_info_; |
119 scoped_ptr<CustomRequestHandler> custom_request_handler_; | |
110 GURL registration_url_; | 120 GURL registration_url_; |
111 | 121 |
112 net::BackoffEntry backoff_entry_; | 122 net::BackoffEntry backoff_entry_; |
113 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 123 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
114 scoped_ptr<net::URLFetcher> url_fetcher_; | 124 scoped_ptr<net::URLFetcher> url_fetcher_; |
115 int retries_left_; | 125 int retries_left_; |
116 base::TimeTicks request_start_time_; | 126 base::TimeTicks request_start_time_; |
117 | 127 |
118 // Recorder that records GCM activities for debugging purpose. Not owned. | 128 // Recorder that records GCM activities for debugging purpose. Not owned. |
119 GCMStatsRecorder* recorder_; | 129 GCMStatsRecorder* recorder_; |
130 std::string source_to_record_; | |
120 | 131 |
121 base::WeakPtrFactory<RegistrationRequest> weak_ptr_factory_; | 132 base::WeakPtrFactory<RegistrationRequest> weak_ptr_factory_; |
122 | 133 |
123 DISALLOW_COPY_AND_ASSIGN(RegistrationRequest); | 134 DISALLOW_COPY_AND_ASSIGN(RegistrationRequest); |
124 }; | 135 }; |
125 | 136 |
126 } // namespace gcm | 137 } // namespace gcm |
127 | 138 |
128 #endif // GOOGLE_APIS_GCM_ENGINE_REGISTRATION_REQUEST_H_ | 139 #endif // GOOGLE_APIS_GCM_ENGINE_REGISTRATION_REQUEST_H_ |
OLD | NEW |