Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(337)

Side by Side Diff: google_apis/gcm/engine/unregistration_request.h

Issue 1137463003: Support getting and deleting token for Instance ID. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More changes Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 // Defines the common info about an unregistration/token-deletion request.
59 // 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
74 // Encapsulates the custom logic that is needed to build and process the
75 // unregistration request.
76 class GCM_EXPORT CustomRequestHandler {
77 public:
78 CustomRequestHandler();
79 virtual ~CustomRequestHandler();
80
81 virtual void BuildRequestBody(std::string* body) = 0;
Nicolas Zea 2015/05/26 16:39:15 Comment when these are called? (i.e. this is calle
jianli 2015/05/26 20:49:39 Done.
82 virtual Status ParseResponse(const net::URLFetcher* source) = 0;
83 };
84
73 // Creates an instance of UnregistrationRequest. |callback| will be called 85 // Creates an instance of UnregistrationRequest. |callback| will be called
74 // once registration has been revoked or there has been an error that makes 86 // once registration has been revoked or there has been an error that makes
75 // further retries pointless. 87 // further retries pointless.
76 UnregistrationRequest( 88 UnregistrationRequest(
77 const GURL& registration_url, 89 const GURL& registration_url,
78 const RequestInfo& request_info, 90 const RequestInfo& request_info,
91 scoped_ptr<CustomRequestHandler> custom_request_handler,
79 const net::BackoffEntry::Policy& backoff_policy, 92 const net::BackoffEntry::Policy& backoff_policy,
80 const UnregistrationCallback& callback, 93 const UnregistrationCallback& callback,
81 scoped_refptr<net::URLRequestContextGetter> request_context_getter, 94 scoped_refptr<net::URLRequestContextGetter> request_context_getter,
82 GCMStatsRecorder* recorder); 95 GCMStatsRecorder* recorder);
83 ~UnregistrationRequest() override; 96 ~UnregistrationRequest() override;
84 97
85 // Starts an unregistration request. 98 // Starts an unregistration request.
86 void Start(); 99 void Start();
87 100
101 private:
88 // URLFetcherDelegate implementation. 102 // URLFetcherDelegate implementation.
89 void OnURLFetchComplete(const net::URLFetcher* source) override; 103 void OnURLFetchComplete(const net::URLFetcher* source) override;
90 104
91 private: 105 void BuildRequestHeaders(std::string* extra_headers);
106 void BuildRequestBody(std::string* body);
107 Status ParseResponse(const net::URLFetcher* source);
108
92 // Schedules a retry attempt and informs the backoff of previous request's 109 // Schedules a retry attempt and informs the backoff of previous request's
93 // failure, when |update_backoff| is true. 110 // failure, when |update_backoff| is true.
94 void RetryWithBackoff(bool update_backoff); 111 void RetryWithBackoff(bool update_backoff);
95 112
96 UnregistrationCallback callback_; 113 UnregistrationCallback callback_;
97 RequestInfo request_info_; 114 RequestInfo request_info_;
115 scoped_ptr<CustomRequestHandler> custom_request_handler_;
98 GURL registration_url_; 116 GURL registration_url_;
99 117
100 net::BackoffEntry backoff_entry_; 118 net::BackoffEntry backoff_entry_;
101 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; 119 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
102 scoped_ptr<net::URLFetcher> url_fetcher_; 120 scoped_ptr<net::URLFetcher> url_fetcher_;
103 base::TimeTicks request_start_time_; 121 base::TimeTicks request_start_time_;
104 122
105 // Recorder that records GCM activities for debugging purpose. Not owned. 123 // Recorder that records GCM activities for debugging purpose. Not owned.
106 GCMStatsRecorder* recorder_; 124 GCMStatsRecorder* recorder_;
107 125
108 base::WeakPtrFactory<UnregistrationRequest> weak_ptr_factory_; 126 base::WeakPtrFactory<UnregistrationRequest> weak_ptr_factory_;
109 127
110 DISALLOW_COPY_AND_ASSIGN(UnregistrationRequest); 128 DISALLOW_COPY_AND_ASSIGN(UnregistrationRequest);
111 }; 129 };
112 130
113 } // namespace gcm 131 } // namespace gcm
114 132
115 #endif // GOOGLE_APIS_GCM_ENGINE_UNREGISTRATION_REQUEST_H_ 133 #endif // GOOGLE_APIS_GCM_ENGINE_UNREGISTRATION_REQUEST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698