Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef GOOGLE_APIS_GCM_ENGINE_UNREGISTRATION_REQUEST_H_ | |
| 6 #define GOOGLE_APIS_GCM_ENGINE_UNREGISTRATION_REQUEST_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <vector> | |
|
jianli
2014/02/14 18:36:18
Are these 2 includes needed?
fgorski
2014/02/14 18:48:42
Done.
| |
| 10 | |
| 11 #include "base/basictypes.h" | |
|
Nicolas Zea
2014/02/14 19:05:05
keep basic types (defines uint64 and the like)
fgorski
2014/02/14 19:56:34
Done.
| |
| 12 #include "base/callback.h" | |
| 13 #include "base/memory/ref_counted.h" | |
| 14 #include "base/memory/scoped_ptr.h" | |
| 15 #include "base/memory/weak_ptr.h" | |
| 16 #include "google_apis/gcm/base/gcm_export.h" | |
| 17 #include "net/base/backoff_entry.h" | |
| 18 #include "net/url_request/url_fetcher_delegate.h" | |
| 19 | |
| 20 namespace net { | |
| 21 class URLRequestContextGetter; | |
| 22 } | |
| 23 | |
| 24 namespace gcm { | |
| 25 | |
| 26 // Unregistration request is used to revoke registration IDs for applications | |
| 27 // that were uninstalled and should no longer receive GCM messages. In case an | |
| 28 // attempt to unregister fails, it will retry using the backoff policy. | |
| 29 class GCM_EXPORT UnregistrationRequest : public net::URLFetcherDelegate { | |
| 30 public: | |
| 31 // Callback completing the unregistration request. | |
| 32 typedef base::Callback<void(bool success)> UnregistrationCallback; | |
| 33 | |
| 34 // Details of the of the Unregistration Request. All parameters are mandatory. | |
| 35 struct GCM_EXPORT RequestInfo { | |
| 36 RequestInfo(uint64 android_id, | |
| 37 uint64 security_token, | |
| 38 const std::string& app_id); | |
| 39 ~RequestInfo(); | |
| 40 | |
| 41 // Android ID of the device. | |
| 42 uint64 android_id; | |
| 43 // Security token of the device. | |
| 44 uint64 security_token; | |
| 45 // Application ID. | |
| 46 std::string app_id; | |
| 47 }; | |
| 48 | |
| 49 // Creates an instance of UnregistrationRequest. |callback| will be called | |
| 50 // once registration has been revoked or there has been an error that makes | |
| 51 // further retries pointless. | |
| 52 UnregistrationRequest( | |
| 53 const RequestInfo& request_info, | |
| 54 const net::BackoffEntry::Policy& backoff_policy, | |
| 55 const UnregistrationCallback& callback, | |
| 56 scoped_refptr<net::URLRequestContextGetter> request_context_getter); | |
| 57 virtual ~UnregistrationRequest(); | |
| 58 | |
| 59 // Starts an unregistration request. | |
| 60 void Start(); | |
| 61 | |
| 62 // URLFetcherDelegate implementation. | |
| 63 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | |
| 64 | |
| 65 private: | |
| 66 // Schedules a retry attempt and informs the backoff of previous request's | |
| 67 // failure, when |update_backoff| is true. | |
| 68 void RetryWithBackoff(bool update_backoff); | |
| 69 | |
| 70 UnregistrationCallback callback_; | |
| 71 RequestInfo request_info_; | |
| 72 | |
| 73 net::BackoffEntry backoff_entry_; | |
| 74 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | |
| 75 scoped_ptr<net::URLFetcher> url_fetcher_; | |
| 76 | |
| 77 base::WeakPtrFactory<UnregistrationRequest> weak_ptr_factory_; | |
| 78 | |
| 79 DISALLOW_COPY_AND_ASSIGN(UnregistrationRequest); | |
| 80 }; | |
| 81 | |
| 82 } // namespace gcm | |
| 83 | |
| 84 #endif // GOOGLE_APIS_GCM_ENGINE_UNREGISTRATION_REQUEST_H_ | |
| OLD | NEW |