| 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 <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <memory> |
| 11 #include <string> | 12 #include <string> |
| 12 #include <vector> | 13 #include <vector> |
| 13 | 14 |
| 14 #include "base/callback.h" | 15 #include "base/callback.h" |
| 15 #include "base/macros.h" | 16 #include "base/macros.h" |
| 16 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 17 #include "base/memory/scoped_ptr.h" | |
| 18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
| 19 #include "base/time/time.h" | 19 #include "base/time/time.h" |
| 20 #include "google_apis/gcm/base/gcm_export.h" | 20 #include "google_apis/gcm/base/gcm_export.h" |
| 21 #include "net/base/backoff_entry.h" | 21 #include "net/base/backoff_entry.h" |
| 22 #include "net/url_request/url_fetcher_delegate.h" | 22 #include "net/url_request/url_fetcher_delegate.h" |
| 23 #include "url/gurl.h" | 23 #include "url/gurl.h" |
| 24 | 24 |
| 25 namespace net { | 25 namespace net { |
| 26 class URLRequestContextGetter; | 26 class URLRequestContextGetter; |
| 27 } | 27 } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 | 92 |
| 93 // Reports various UMAs, including status, retry count and completion time. | 93 // Reports various UMAs, including status, retry count and completion time. |
| 94 virtual void ReportUMAs(Status status, | 94 virtual void ReportUMAs(Status status, |
| 95 int retry_count, | 95 int retry_count, |
| 96 base::TimeDelta complete_time) = 0; | 96 base::TimeDelta complete_time) = 0; |
| 97 }; | 97 }; |
| 98 | 98 |
| 99 RegistrationRequest( | 99 RegistrationRequest( |
| 100 const GURL& registration_url, | 100 const GURL& registration_url, |
| 101 const RequestInfo& request_info, | 101 const RequestInfo& request_info, |
| 102 scoped_ptr<CustomRequestHandler> custom_request_handler, | 102 std::unique_ptr<CustomRequestHandler> custom_request_handler, |
| 103 const net::BackoffEntry::Policy& backoff_policy, | 103 const net::BackoffEntry::Policy& backoff_policy, |
| 104 const RegistrationCallback& callback, | 104 const RegistrationCallback& callback, |
| 105 int max_retry_count, | 105 int max_retry_count, |
| 106 scoped_refptr<net::URLRequestContextGetter> request_context_getter, | 106 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
| 107 GCMStatsRecorder* recorder, | 107 GCMStatsRecorder* recorder, |
| 108 const std::string& source_to_record); | 108 const std::string& source_to_record); |
| 109 ~RegistrationRequest() override; | 109 ~RegistrationRequest() override; |
| 110 | 110 |
| 111 void Start(); | 111 void Start(); |
| 112 | 112 |
| 113 // URLFetcherDelegate implementation. | 113 // URLFetcherDelegate implementation. |
| 114 void OnURLFetchComplete(const net::URLFetcher* source) override; | 114 void OnURLFetchComplete(const net::URLFetcher* source) override; |
| 115 | 115 |
| 116 private: | 116 private: |
| 117 // Schedules a retry attempt with a backoff. | 117 // Schedules a retry attempt with a backoff. |
| 118 void RetryWithBackoff(); | 118 void RetryWithBackoff(); |
| 119 | 119 |
| 120 void BuildRequestHeaders(std::string* extra_headers); | 120 void BuildRequestHeaders(std::string* extra_headers); |
| 121 void BuildRequestBody(std::string* body); | 121 void BuildRequestBody(std::string* body); |
| 122 | 122 |
| 123 // Parse the response returned by the URL fetcher into token, and returns the | 123 // Parse the response returned by the URL fetcher into token, and returns the |
| 124 // status. | 124 // status. |
| 125 Status ParseResponse(const net::URLFetcher* source, std::string* token); | 125 Status ParseResponse(const net::URLFetcher* source, std::string* token); |
| 126 | 126 |
| 127 RegistrationCallback callback_; | 127 RegistrationCallback callback_; |
| 128 RequestInfo request_info_; | 128 RequestInfo request_info_; |
| 129 scoped_ptr<CustomRequestHandler> custom_request_handler_; | 129 std::unique_ptr<CustomRequestHandler> custom_request_handler_; |
| 130 GURL registration_url_; | 130 GURL registration_url_; |
| 131 | 131 |
| 132 net::BackoffEntry backoff_entry_; | 132 net::BackoffEntry backoff_entry_; |
| 133 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 133 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
| 134 scoped_ptr<net::URLFetcher> url_fetcher_; | 134 std::unique_ptr<net::URLFetcher> url_fetcher_; |
| 135 int retries_left_; | 135 int retries_left_; |
| 136 base::TimeTicks request_start_time_; | 136 base::TimeTicks request_start_time_; |
| 137 | 137 |
| 138 // Recorder that records GCM activities for debugging purpose. Not owned. | 138 // Recorder that records GCM activities for debugging purpose. Not owned. |
| 139 GCMStatsRecorder* recorder_; | 139 GCMStatsRecorder* recorder_; |
| 140 std::string source_to_record_; | 140 std::string source_to_record_; |
| 141 | 141 |
| 142 base::WeakPtrFactory<RegistrationRequest> weak_ptr_factory_; | 142 base::WeakPtrFactory<RegistrationRequest> weak_ptr_factory_; |
| 143 | 143 |
| 144 DISALLOW_COPY_AND_ASSIGN(RegistrationRequest); | 144 DISALLOW_COPY_AND_ASSIGN(RegistrationRequest); |
| 145 }; | 145 }; |
| 146 | 146 |
| 147 } // namespace gcm | 147 } // namespace gcm |
| 148 | 148 |
| 149 #endif // GOOGLE_APIS_GCM_ENGINE_REGISTRATION_REQUEST_H_ | 149 #endif // GOOGLE_APIS_GCM_ENGINE_REGISTRATION_REQUEST_H_ |
| OLD | NEW |