| 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_UNREGISTRATION_REQUEST_H_ | 5 #ifndef GOOGLE_APIS_GCM_ENGINE_UNREGISTRATION_REQUEST_H_ |
| 6 #define GOOGLE_APIS_GCM_ENGINE_UNREGISTRATION_REQUEST_H_ | 6 #define GOOGLE_APIS_GCM_ENGINE_UNREGISTRATION_REQUEST_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> |
| 11 |
| 10 #include "base/callback.h" | 12 #include "base/callback.h" |
| 11 #include "base/macros.h" | 13 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 16 #include "google_apis/gcm/base/gcm_export.h" | 17 #include "google_apis/gcm/base/gcm_export.h" |
| 17 #include "net/base/backoff_entry.h" | 18 #include "net/base/backoff_entry.h" |
| 18 #include "net/url_request/url_fetcher_delegate.h" | 19 #include "net/url_request/url_fetcher_delegate.h" |
| 19 #include "url/gurl.h" | 20 #include "url/gurl.h" |
| 20 | 21 |
| 21 namespace net { | 22 namespace net { |
| 22 class URLRequestContextGetter; | 23 class URLRequestContextGetter; |
| 23 } | 24 } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 int retry_count, | 96 int retry_count, |
| 96 base::TimeDelta complete_time) = 0; | 97 base::TimeDelta complete_time) = 0; |
| 97 }; | 98 }; |
| 98 | 99 |
| 99 // Creates an instance of UnregistrationRequest. |callback| will be called | 100 // Creates an instance of UnregistrationRequest. |callback| will be called |
| 100 // once registration has been revoked or there has been an error that makes | 101 // once registration has been revoked or there has been an error that makes |
| 101 // further retries pointless. | 102 // further retries pointless. |
| 102 UnregistrationRequest( | 103 UnregistrationRequest( |
| 103 const GURL& registration_url, | 104 const GURL& registration_url, |
| 104 const RequestInfo& request_info, | 105 const RequestInfo& request_info, |
| 105 scoped_ptr<CustomRequestHandler> custom_request_handler, | 106 std::unique_ptr<CustomRequestHandler> custom_request_handler, |
| 106 const net::BackoffEntry::Policy& backoff_policy, | 107 const net::BackoffEntry::Policy& backoff_policy, |
| 107 const UnregistrationCallback& callback, | 108 const UnregistrationCallback& callback, |
| 108 int max_retry_count, | 109 int max_retry_count, |
| 109 scoped_refptr<net::URLRequestContextGetter> request_context_getter, | 110 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
| 110 GCMStatsRecorder* recorder, | 111 GCMStatsRecorder* recorder, |
| 111 const std::string& source_to_record); | 112 const std::string& source_to_record); |
| 112 ~UnregistrationRequest() override; | 113 ~UnregistrationRequest() override; |
| 113 | 114 |
| 114 // Starts an unregistration request. | 115 // Starts an unregistration request. |
| 115 void Start(); | 116 void Start(); |
| 116 | 117 |
| 117 private: | 118 private: |
| 118 // URLFetcherDelegate implementation. | 119 // URLFetcherDelegate implementation. |
| 119 void OnURLFetchComplete(const net::URLFetcher* source) override; | 120 void OnURLFetchComplete(const net::URLFetcher* source) override; |
| 120 | 121 |
| 121 void BuildRequestHeaders(std::string* extra_headers); | 122 void BuildRequestHeaders(std::string* extra_headers); |
| 122 void BuildRequestBody(std::string* body); | 123 void BuildRequestBody(std::string* body); |
| 123 Status ParseResponse(const net::URLFetcher* source); | 124 Status ParseResponse(const net::URLFetcher* source); |
| 124 | 125 |
| 125 // Schedules a retry attempt with a backoff. | 126 // Schedules a retry attempt with a backoff. |
| 126 void RetryWithBackoff(); | 127 void RetryWithBackoff(); |
| 127 | 128 |
| 128 UnregistrationCallback callback_; | 129 UnregistrationCallback callback_; |
| 129 RequestInfo request_info_; | 130 RequestInfo request_info_; |
| 130 scoped_ptr<CustomRequestHandler> custom_request_handler_; | 131 std::unique_ptr<CustomRequestHandler> custom_request_handler_; |
| 131 GURL registration_url_; | 132 GURL registration_url_; |
| 132 | 133 |
| 133 net::BackoffEntry backoff_entry_; | 134 net::BackoffEntry backoff_entry_; |
| 134 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 135 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
| 135 scoped_ptr<net::URLFetcher> url_fetcher_; | 136 std::unique_ptr<net::URLFetcher> url_fetcher_; |
| 136 base::TimeTicks request_start_time_; | 137 base::TimeTicks request_start_time_; |
| 137 int retries_left_; | 138 int retries_left_; |
| 138 | 139 |
| 139 // Recorder that records GCM activities for debugging purpose. Not owned. | 140 // Recorder that records GCM activities for debugging purpose. Not owned. |
| 140 GCMStatsRecorder* recorder_; | 141 GCMStatsRecorder* recorder_; |
| 141 std::string source_to_record_; | 142 std::string source_to_record_; |
| 142 | 143 |
| 143 base::WeakPtrFactory<UnregistrationRequest> weak_ptr_factory_; | 144 base::WeakPtrFactory<UnregistrationRequest> weak_ptr_factory_; |
| 144 | 145 |
| 145 DISALLOW_COPY_AND_ASSIGN(UnregistrationRequest); | 146 DISALLOW_COPY_AND_ASSIGN(UnregistrationRequest); |
| 146 }; | 147 }; |
| 147 | 148 |
| 148 } // namespace gcm | 149 } // namespace gcm |
| 149 | 150 |
| 150 #endif // GOOGLE_APIS_GCM_ENGINE_UNREGISTRATION_REQUEST_H_ | 151 #endif // GOOGLE_APIS_GCM_ENGINE_UNREGISTRATION_REQUEST_H_ |
| OLD | NEW |