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

Side by Side Diff: google_apis/gcm/engine/gcm_unregistration_request_handler.cc

Issue 1137463003: Support getting and deleting token for Instance ID. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Patch to land Created 5 years, 6 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
(Empty)
1 // Copyright 2015 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 #include "google_apis/gcm/engine/gcm_unregistration_request_handler.h"
6
7 #include "google_apis/gcm/base/gcm_util.h"
8 #include "net/url_request/url_fetcher.h"
9
10 namespace gcm {
11
12 namespace {
13
14 // Request constants.
15 const char kUnregistrationCallerKey[] = "gcm_unreg_caller";
16 // We are going to set the value to "false" in order to forcefully unregister
17 // the application.
18 const char kUnregistrationCallerValue[] = "false";
19
20 // Response constants.
21 const char kDeletedPrefix[] = "deleted=";
22 const char kErrorPrefix[] = "Error=";
23 const char kInvalidParameters[] = "INVALID_PARAMETERS";
24
25 } // namespace
26
27 GCMUnregistrationRequestHandler::GCMUnregistrationRequestHandler(
28 const std::string& app_id)
29 : app_id_(app_id) {
30 }
31
32 GCMUnregistrationRequestHandler::~GCMUnregistrationRequestHandler() {}
33
34 void GCMUnregistrationRequestHandler::BuildRequestBody(std::string* body){
35 BuildFormEncoding(kUnregistrationCallerKey, kUnregistrationCallerValue, body);
36 }
37
38 UnregistrationRequest::Status GCMUnregistrationRequestHandler::ParseResponse(
39 const net::URLFetcher* source) {
40 std::string response;
41 if (!source->GetResponseAsString(&response)) {
42 DVLOG(1) << "Failed to get response body.";
43 return UnregistrationRequest::NO_RESPONSE_BODY;
44 }
45
46 DVLOG(1) << "Parsing unregistration response.";
47 if (response.find(kDeletedPrefix) != std::string::npos) {
48 std::string deleted_app_id = response.substr(
49 response.find(kDeletedPrefix) + arraysize(kDeletedPrefix) - 1);
50 return deleted_app_id == app_id_ ?
51 UnregistrationRequest::SUCCESS :
52 UnregistrationRequest::INCORRECT_APP_ID;
53 }
54
55 if (response.find(kErrorPrefix) != std::string::npos) {
56 std::string error = response.substr(
57 response.find(kErrorPrefix) + arraysize(kErrorPrefix) - 1);
58 return error == kInvalidParameters ?
59 UnregistrationRequest::INVALID_PARAMETERS :
60 UnregistrationRequest::UNKNOWN_ERROR;
61 }
62
63 DVLOG(1) << "Not able to parse a meaningful output from response body."
64 << response;
65 return UnregistrationRequest::RESPONSE_PARSING_FAILED;
66 }
67
68 } // namespace gcm
OLDNEW
« no previous file with comments | « google_apis/gcm/engine/gcm_unregistration_request_handler.h ('k') | google_apis/gcm/engine/gservices_settings_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698