| 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 "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "google_apis/gcm/base/gcm_export.h" | 13 #include "google_apis/gcm/base/gcm_export.h" |
| 14 #include "net/base/backoff_entry.h" | 14 #include "net/base/backoff_entry.h" |
| 15 #include "net/url_request/url_fetcher_delegate.h" | 15 #include "net/url_request/url_fetcher_delegate.h" |
| 16 | 16 |
| 17 namespace net { | 17 namespace net { |
| 18 class URLRequestContextGetter; | 18 class URLRequestContextGetter; |
| 19 } | 19 } |
| 20 | 20 |
| 21 namespace gcm { | 21 namespace gcm { |
| 22 | 22 |
| 23 class GCMStatsRecorder; |
| 24 |
| 23 // Unregistration request is used to revoke registration IDs for applications | 25 // Unregistration request is used to revoke registration IDs for applications |
| 24 // that were uninstalled and should no longer receive GCM messages. In case an | 26 // that were uninstalled and should no longer receive GCM messages. In case an |
| 25 // attempt to unregister fails, it will retry using the backoff policy. | 27 // attempt to unregister fails, it will retry using the backoff policy. |
| 26 // TODO(fgorski): Consider sharing code with RegistrationRequest if possible. | 28 // TODO(fgorski): Consider sharing code with RegistrationRequest if possible. |
| 27 class GCM_EXPORT UnregistrationRequest : public net::URLFetcherDelegate { | 29 class GCM_EXPORT UnregistrationRequest : public net::URLFetcherDelegate { |
| 28 public: | 30 public: |
| 29 // Outcome of the response parsing. Note that these enums are consumed by a | 31 // Outcome of the response parsing. Note that these enums are consumed by a |
| 30 // histogram, so ordering should not be modified. | 32 // histogram, so ordering should not be modified. |
| 31 enum Status { | 33 enum Status { |
| 32 SUCCESS, // Unregistration completed successfully. | 34 SUCCESS, // Unregistration completed successfully. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 std::string app_id; | 68 std::string app_id; |
| 67 }; | 69 }; |
| 68 | 70 |
| 69 // Creates an instance of UnregistrationRequest. |callback| will be called | 71 // Creates an instance of UnregistrationRequest. |callback| will be called |
| 70 // once registration has been revoked or there has been an error that makes | 72 // once registration has been revoked or there has been an error that makes |
| 71 // further retries pointless. | 73 // further retries pointless. |
| 72 UnregistrationRequest( | 74 UnregistrationRequest( |
| 73 const RequestInfo& request_info, | 75 const RequestInfo& request_info, |
| 74 const net::BackoffEntry::Policy& backoff_policy, | 76 const net::BackoffEntry::Policy& backoff_policy, |
| 75 const UnregistrationCallback& callback, | 77 const UnregistrationCallback& callback, |
| 76 scoped_refptr<net::URLRequestContextGetter> request_context_getter); | 78 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
| 79 GCMStatsRecorder* recorder); |
| 77 virtual ~UnregistrationRequest(); | 80 virtual ~UnregistrationRequest(); |
| 78 | 81 |
| 79 // Starts an unregistration request. | 82 // Starts an unregistration request. |
| 80 void Start(); | 83 void Start(); |
| 81 | 84 |
| 82 // URLFetcherDelegate implementation. | 85 // URLFetcherDelegate implementation. |
| 83 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 86 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 84 | 87 |
| 85 private: | 88 private: |
| 86 // Schedules a retry attempt and informs the backoff of previous request's | 89 // Schedules a retry attempt and informs the backoff of previous request's |
| 87 // failure, when |update_backoff| is true. | 90 // failure, when |update_backoff| is true. |
| 88 void RetryWithBackoff(bool update_backoff); | 91 void RetryWithBackoff(bool update_backoff); |
| 89 | 92 |
| 90 UnregistrationCallback callback_; | 93 UnregistrationCallback callback_; |
| 91 RequestInfo request_info_; | 94 RequestInfo request_info_; |
| 92 | 95 |
| 93 net::BackoffEntry backoff_entry_; | 96 net::BackoffEntry backoff_entry_; |
| 94 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 97 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
| 95 scoped_ptr<net::URLFetcher> url_fetcher_; | 98 scoped_ptr<net::URLFetcher> url_fetcher_; |
| 96 | 99 |
| 100 // Recorder that records GCM activities for debugging purpose. Not owned. |
| 101 GCMStatsRecorder* recorder_; |
| 102 |
| 97 base::WeakPtrFactory<UnregistrationRequest> weak_ptr_factory_; | 103 base::WeakPtrFactory<UnregistrationRequest> weak_ptr_factory_; |
| 98 | 104 |
| 99 DISALLOW_COPY_AND_ASSIGN(UnregistrationRequest); | 105 DISALLOW_COPY_AND_ASSIGN(UnregistrationRequest); |
| 100 }; | 106 }; |
| 101 | 107 |
| 102 } // namespace gcm | 108 } // namespace gcm |
| 103 | 109 |
| 104 #endif // GOOGLE_APIS_GCM_ENGINE_UNREGISTRATION_REQUEST_H_ | 110 #endif // GOOGLE_APIS_GCM_ENGINE_UNREGISTRATION_REQUEST_H_ |
| OLD | NEW |