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 "base/time/time.h" | 13 #include "base/time/time.h" |
14 #include "google_apis/gcm/base/gcm_export.h" | 14 #include "google_apis/gcm/base/gcm_export.h" |
15 #include "net/base/backoff_entry.h" | 15 #include "net/base/backoff_entry.h" |
16 #include "net/url_request/url_fetcher_delegate.h" | 16 #include "net/url_request/url_fetcher_delegate.h" |
17 #include "url/gurl.h" | 17 #include "url/gurl.h" |
18 | 18 |
19 namespace net { | 19 namespace net { |
20 class URLRequestContextGetter; | 20 class URLRequestContextGetter; |
21 } | 21 } |
22 | 22 |
23 namespace gcm { | 23 namespace gcm { |
24 | 24 |
25 class GCMStatsRecorder; | 25 class GCMStatsRecorder; |
26 | 26 |
27 // Unregistration request is used to revoke registration IDs for applications | 27 // Encapsulates the common logic applying to both GCM unregistration requests |
28 // that were uninstalled and should no longer receive GCM messages. In case an | 28 // and InstanceID delete-token requests. In case an attempt fails, it will retry |
29 // attempt to unregister fails, it will retry using the backoff policy. | 29 // using the backoff policy. |
30 // TODO(fgorski): Consider sharing code with RegistrationRequest if possible. | 30 // TODO(fgorski): Consider sharing code with RegistrationRequest if possible. |
31 class GCM_EXPORT UnregistrationRequest : public net::URLFetcherDelegate { | 31 class GCM_EXPORT UnregistrationRequest : public net::URLFetcherDelegate { |
32 public: | 32 public: |
33 // Outcome of the response parsing. Note that these enums are consumed by a | 33 // Outcome of the response parsing. Note that these enums are consumed by a |
34 // histogram, so ordering should not be modified. | 34 // histogram, so ordering should not be modified. |
35 enum Status { | 35 enum Status { |
36 SUCCESS, // Unregistration completed successfully. | 36 SUCCESS, // Unregistration completed successfully. |
37 URL_FETCHING_FAILED, // URL fetching failed. | 37 URL_FETCHING_FAILED, // URL fetching failed. |
38 NO_RESPONSE_BODY, // No response body. | 38 NO_RESPONSE_BODY, // No response body. |
39 RESPONSE_PARSING_FAILED, // Failed to parse a meaningful output from | 39 RESPONSE_PARSING_FAILED, // Failed to parse a meaningful output from |
40 // response | 40 // response |
41 // body. | 41 // body. |
42 INCORRECT_APP_ID, // App ID returned by the fetcher does not match | 42 INCORRECT_APP_ID, // App ID returned by the fetcher does not match |
43 // request. | 43 // request. |
44 INVALID_PARAMETERS, // Request parameters were invalid. | 44 INVALID_PARAMETERS, // Request parameters were invalid. |
45 SERVICE_UNAVAILABLE, // Unregistration service unavailable. | 45 SERVICE_UNAVAILABLE, // Unregistration service unavailable. |
46 INTERNAL_SERVER_ERROR, // Internal server error happened during request. | 46 INTERNAL_SERVER_ERROR, // Internal server error happened during request. |
47 HTTP_NOT_OK, // HTTP response code was not OK. | 47 HTTP_NOT_OK, // HTTP response code was not OK. |
48 UNKNOWN_ERROR, // Unknown error. | 48 UNKNOWN_ERROR, // Unknown error. |
49 // NOTE: Always keep this entry at the end. Add new status types only | 49 // NOTE: Always keep this entry at the end. Add new status types only |
50 // immediately above this line. Make sure to update the corresponding | 50 // immediately above this line. Make sure to update the corresponding |
51 // histogram enum accordingly. | 51 // histogram enum accordingly. |
52 UNREGISTRATION_STATUS_COUNT, | 52 UNREGISTRATION_STATUS_COUNT, |
53 }; | 53 }; |
54 | 54 |
55 // Callback completing the unregistration request. | 55 // Callback completing the unregistration request. |
56 typedef base::Callback<void(Status success)> UnregistrationCallback; | 56 typedef base::Callback<void(Status success)> UnregistrationCallback; |
57 | 57 |
58 // Details of the of the Unregistration Request. All parameters are mandatory. | 58 // Encapsulates the common info about an unregistration/token-deletion |
59 // request. All parameters are mandatory. | |
59 struct GCM_EXPORT RequestInfo { | 60 struct GCM_EXPORT RequestInfo { |
60 RequestInfo(uint64 android_id, | 61 RequestInfo(uint64 android_id, |
61 uint64 security_token, | 62 uint64 security_token, |
62 const std::string& app_id); | 63 const std::string& app_id); |
63 ~RequestInfo(); | 64 ~RequestInfo(); |
64 | 65 |
65 // Android ID of the device. | 66 // Android ID of the device. |
66 uint64 android_id; | 67 uint64 android_id; |
67 // Security token of the device. | 68 // Security token of the device. |
68 uint64 security_token; | 69 uint64 security_token; |
69 // Application ID. | 70 // Application ID. |
70 std::string app_id; | 71 std::string app_id; |
71 }; | 72 }; |
72 | 73 |
73 // Creates an instance of UnregistrationRequest. |callback| will be called | 74 // Creates an instance of UnregistrationRequest. |callback| will be called |
74 // once registration has been revoked or there has been an error that makes | 75 // once registration has been revoked or there has been an error that makes |
75 // further retries pointless. | 76 // further retries pointless. |
76 UnregistrationRequest( | 77 UnregistrationRequest( |
77 const GURL& registration_url, | 78 const GURL& registration_url, |
78 const RequestInfo& request_info, | 79 const RequestInfo& request_info, |
79 const net::BackoffEntry::Policy& backoff_policy, | 80 const net::BackoffEntry::Policy& backoff_policy, |
80 const UnregistrationCallback& callback, | 81 const UnregistrationCallback& callback, |
81 scoped_refptr<net::URLRequestContextGetter> request_context_getter, | 82 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
82 GCMStatsRecorder* recorder); | 83 GCMStatsRecorder* recorder); |
83 ~UnregistrationRequest() override; | 84 ~UnregistrationRequest() override; |
84 | 85 |
85 // Starts an unregistration request. | 86 // Starts an unregistration request. |
86 void Start(); | 87 void Start(); |
87 | 88 |
89 virtual void BuildRequestHeaders(std::string* extra_headers); | |
Nicolas Zea
2015/05/21 21:07:51
Is anything overriding this?
jianli
2015/05/21 23:11:24
No. Removed virtual.
| |
90 virtual void BuildRequestBody(std::string* body); | |
91 virtual bool ParseResponse(const net::URLFetcher* source, Status* status); | |
92 | |
93 protected: | |
94 std::string app_id() const; | |
95 | |
96 private: | |
88 // URLFetcherDelegate implementation. | 97 // URLFetcherDelegate implementation. |
89 void OnURLFetchComplete(const net::URLFetcher* source) override; | 98 void OnURLFetchComplete(const net::URLFetcher* source) override; |
90 | 99 |
91 private: | |
92 // Schedules a retry attempt and informs the backoff of previous request's | 100 // Schedules a retry attempt and informs the backoff of previous request's |
93 // failure, when |update_backoff| is true. | 101 // failure, when |update_backoff| is true. |
94 void RetryWithBackoff(bool update_backoff); | 102 void RetryWithBackoff(bool update_backoff); |
95 | 103 |
96 UnregistrationCallback callback_; | 104 UnregistrationCallback callback_; |
97 RequestInfo request_info_; | 105 RequestInfo request_info_; |
98 GURL registration_url_; | 106 GURL registration_url_; |
99 | 107 |
100 net::BackoffEntry backoff_entry_; | 108 net::BackoffEntry backoff_entry_; |
101 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 109 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
102 scoped_ptr<net::URLFetcher> url_fetcher_; | 110 scoped_ptr<net::URLFetcher> url_fetcher_; |
103 base::TimeTicks request_start_time_; | 111 base::TimeTicks request_start_time_; |
104 | 112 |
105 // Recorder that records GCM activities for debugging purpose. Not owned. | 113 // Recorder that records GCM activities for debugging purpose. Not owned. |
106 GCMStatsRecorder* recorder_; | 114 GCMStatsRecorder* recorder_; |
107 | 115 |
108 base::WeakPtrFactory<UnregistrationRequest> weak_ptr_factory_; | 116 base::WeakPtrFactory<UnregistrationRequest> weak_ptr_factory_; |
109 | 117 |
110 DISALLOW_COPY_AND_ASSIGN(UnregistrationRequest); | 118 DISALLOW_COPY_AND_ASSIGN(UnregistrationRequest); |
111 }; | 119 }; |
112 | 120 |
113 } // namespace gcm | 121 } // namespace gcm |
114 | 122 |
115 #endif // GOOGLE_APIS_GCM_ENGINE_UNREGISTRATION_REQUEST_H_ | 123 #endif // GOOGLE_APIS_GCM_ENGINE_UNREGISTRATION_REQUEST_H_ |
OLD | NEW |