Chromium Code Reviews| Index: google_apis/gcm/engine/unregistration_request.cc |
| diff --git a/google_apis/gcm/engine/unregistration_request.cc b/google_apis/gcm/engine/unregistration_request.cc |
| index 9b337786f3e8a9c985fffd4206e242eeeb6566de..0b875990bcaa4bcfe428e0d9d21a6693338a1f02 100644 |
| --- a/google_apis/gcm/engine/unregistration_request.cc |
| +++ b/google_apis/gcm/engine/unregistration_request.cc |
| @@ -35,6 +35,12 @@ const char kUnregistrationCallerKey[] = "gcm_unreg_caller"; |
| // the application. |
| const char kUnregistrationCallerValue[] = "false"; |
| +// Request keys specific to InstanceID's GetToken request. |
| +const char kGMSVersionKey[] = "gmsv"; |
| +const char kInstanceIDKey[] = "appid"; |
| +const char kSenderKey[] = "sender"; |
| +const char kScopeKey[] = "scope"; |
| + |
| // Response constants. |
| const char kDeletedPrefix[] = "deleted="; |
| const char kErrorPrefix[] = "Error="; |
| @@ -98,26 +104,60 @@ UnregistrationRequest::Status ParseFetcherResponse( |
| } // namespace |
| -UnregistrationRequest::RequestInfo::RequestInfo( |
| - uint64 android_id, |
| - uint64 security_token, |
| - const std::string& app_id) |
| - : android_id(android_id), |
| - security_token(security_token), |
| - app_id(app_id) { |
| -} |
| +UnregistrationRequest::RequestInfo::RequestInfo() {} |
| UnregistrationRequest::RequestInfo::~RequestInfo() {} |
| +void UnregistrationRequest::RequestInfo::BuildRequestHeaders( |
| + std::string* extra_headers) { |
| + net::HttpRequestHeaders headers; |
| + headers.SetHeader( |
| + net::HttpRequestHeaders::kAuthorization, |
| + std::string(kLoginHeader) + " " + base::Uint64ToString(android_id) + ":" + |
| + base::Uint64ToString(security_token)); |
| + headers.SetHeader(kAppIdKey, app_id); |
| + *extra_headers = headers.ToString(); |
| +} |
| + |
| +void UnregistrationRequest::RequestInfo::BuildRequestBody(std::string* body){ |
| + BuildFormEncoding(kAppIdKey, app_id, body); |
|
fgorski
2015/05/13 18:32:41
does app id need to be present in both cases?
I th
jianli
2015/05/13 22:42:57
I confirmed with Costin that this was still requir
|
| + BuildFormEncoding(kDeviceIdKey, base::Uint64ToString(android_id), body); |
| + BuildFormEncoding(kDeleteKey, kDeleteValue, body); |
| +} |
| + |
| +UnregistrationRequest::GCMRequestInfo::GCMRequestInfo() {} |
| + |
| +UnregistrationRequest::GCMRequestInfo::~GCMRequestInfo() {} |
| + |
| +void UnregistrationRequest::GCMRequestInfo::BuildRequestBody(std::string* body){ |
| + RequestInfo::BuildRequestBody(body); |
| + |
| + BuildFormEncoding(kUnregistrationCallerKey, kUnregistrationCallerValue, body); |
| +} |
| + |
| +UnregistrationRequest::InstanceIDRequestInfo::InstanceIDRequestInfo() {} |
| + |
| +UnregistrationRequest::InstanceIDRequestInfo::~InstanceIDRequestInfo() {} |
| + |
| +void UnregistrationRequest::InstanceIDRequestInfo::BuildRequestBody( |
| + std::string* body){ |
| + RequestInfo::BuildRequestBody(body); |
| + |
| + BuildFormEncoding(kGMSVersionKey, chrome_version, body); |
| + BuildFormEncoding(kInstanceIDKey, instance_id, body); |
| + BuildFormEncoding(kSenderKey, authorized_entity, body); |
| + BuildFormEncoding(kScopeKey, scope, body); |
| +} |
| + |
| UnregistrationRequest::UnregistrationRequest( |
| const GURL& registration_url, |
| - const RequestInfo& request_info, |
| + scoped_ptr<RequestInfo> request_info, |
| const net::BackoffEntry::Policy& backoff_policy, |
| const UnregistrationCallback& callback, |
| scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
| GCMStatsRecorder* recorder) |
| : callback_(callback), |
| - request_info_(request_info), |
| + request_info_(request_info.Pass()), |
| registration_url_(registration_url), |
| backoff_entry_(&backoff_policy), |
| request_context_getter_(request_context_getter), |
| @@ -129,36 +169,26 @@ UnregistrationRequest::~UnregistrationRequest() {} |
| void UnregistrationRequest::Start() { |
| DCHECK(!callback_.is_null()); |
| - DCHECK(request_info_.android_id != 0UL); |
| - DCHECK(request_info_.security_token != 0UL); |
| + DCHECK(request_info_->android_id != 0UL); |
| + DCHECK(request_info_->security_token != 0UL); |
| DCHECK(!url_fetcher_.get()); |
| url_fetcher_ = |
| net::URLFetcher::Create(registration_url_, net::URLFetcher::POST, this); |
| url_fetcher_->SetRequestContext(request_context_getter_.get()); |
| - std::string android_id = base::Uint64ToString(request_info_.android_id); |
| - std::string auth_header = |
| - std::string(kLoginHeader) + " " + android_id + ":" + |
| - base::Uint64ToString(request_info_.security_token); |
| - net::HttpRequestHeaders headers; |
| - headers.SetHeader(net::HttpRequestHeaders::kAuthorization, auth_header); |
| - headers.SetHeader(kAppIdKey, request_info_.app_id); |
| - url_fetcher_->SetExtraRequestHeaders(headers.ToString()); |
| + std::string extra_headers; |
| + request_info_->BuildRequestHeaders(&extra_headers); |
| + url_fetcher_->SetExtraRequestHeaders(extra_headers); |
| std::string body; |
| - BuildFormEncoding(kAppIdKey, request_info_.app_id, &body); |
| - BuildFormEncoding(kDeviceIdKey, android_id, &body); |
| - BuildFormEncoding(kDeleteKey, kDeleteValue, &body); |
| - BuildFormEncoding(kUnregistrationCallerKey, |
| - kUnregistrationCallerValue, |
| - &body); |
| + request_info_->BuildRequestBody(&body); |
| DVLOG(1) << "Unregistration request: " << body; |
| url_fetcher_->SetUploadData(kRequestContentType, body); |
| - DVLOG(1) << "Performing unregistration for: " << request_info_.app_id; |
| - recorder_->RecordUnregistrationSent(request_info_.app_id); |
| + DVLOG(1) << "Performing unregistration for: " << request_info_->app_id; |
| + recorder_->RecordUnregistrationSent(request_info_->app_id); |
| request_start_time_ = base::TimeTicks::Now(); |
| url_fetcher_->Start(); |
| } |
| @@ -171,11 +201,11 @@ void UnregistrationRequest::RetryWithBackoff(bool update_backoff) { |
| if (backoff_entry_.ShouldRejectRequest()) { |
| DVLOG(1) << "Delaying GCM unregistration of app: " |
| - << request_info_.app_id << ", for " |
| + << request_info_->app_id << ", for " |
| << backoff_entry_.GetTimeUntilRelease().InMilliseconds() |
| << " milliseconds."; |
| recorder_->RecordUnregistrationRetryDelayed( |
| - request_info_.app_id, |
| + request_info_->app_id, |
| backoff_entry_.GetTimeUntilRelease().InMilliseconds()); |
| base::MessageLoop::current()->PostDelayedTask( |
| FROM_HERE, |
| @@ -191,13 +221,13 @@ void UnregistrationRequest::RetryWithBackoff(bool update_backoff) { |
| void UnregistrationRequest::OnURLFetchComplete(const net::URLFetcher* source) { |
| UnregistrationRequest::Status status = |
| - ParseFetcherResponse(source, request_info_.app_id); |
| + ParseFetcherResponse(source, request_info_->app_id); |
| DVLOG(1) << "UnregistrationRequestStauts: " << status; |
| UMA_HISTOGRAM_ENUMERATION("GCM.UnregistrationRequestStatus", |
| status, |
| UNREGISTRATION_STATUS_COUNT); |
| - recorder_->RecordUnregistrationResponse(request_info_.app_id, status); |
| + recorder_->RecordUnregistrationResponse(request_info_->app_id, status); |
| if (status == URL_FETCHING_FAILED || |
| status == SERVICE_UNAVAILABLE || |