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

Side by Side Diff: google_apis/gcm/engine/instance_id_delete_token_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/instance_id_delete_token_request_handler.h"
6
7 #include "base/strings/string_number_conversions.h"
8 #include "google_apis/gcm/base/gcm_util.h"
9 #include "net/url_request/url_fetcher.h"
10 #include "net/url_request/url_request_context_getter.h"
11
12 namespace gcm {
13
14 namespace {
15
16 // Request constants.
17 const char kGMSVersionKey[] = "gmsv";
18 const char kInstanceIDKey[] = "appid";
19 const char kSenderKey[] = "sender";
20 const char kScopeKey[] = "scope";
21
22 // Response constants.
23 const char kTokenPrefix[] = "token=";
24
25 } // namespace
26
27 InstanceIDDeleteTokenRequestHandler::InstanceIDDeleteTokenRequestHandler(
28 const std::string& instance_id,
29 const std::string& authorized_entity,
30 const std::string& scope,
31 int gcm_version)
32 : instance_id_(instance_id),
33 authorized_entity_(authorized_entity),
34 scope_(scope),
35 gcm_version_(gcm_version) {
36 DCHECK(!instance_id.empty());
37 DCHECK(!authorized_entity.empty());
38 DCHECK(!scope.empty());
39 }
40
41 InstanceIDDeleteTokenRequestHandler::~InstanceIDDeleteTokenRequestHandler() {}
42
43 void InstanceIDDeleteTokenRequestHandler::BuildRequestBody(std::string* body){
44 BuildFormEncoding(kInstanceIDKey, instance_id_, body);
45 BuildFormEncoding(kSenderKey, authorized_entity_, body);
46 BuildFormEncoding(kScopeKey, scope_, body);
47 BuildFormEncoding(kGMSVersionKey, base::IntToString(gcm_version_), body);
48 }
49
50 UnregistrationRequest::Status
51 InstanceIDDeleteTokenRequestHandler::ParseResponse(
52 const net::URLFetcher* source) {
53 std::string response;
54 if (!source->GetResponseAsString(&response)) {
55 DVLOG(1) << "Failed to get response body.";
56 return UnregistrationRequest::NO_RESPONSE_BODY;
57 }
58
59 if (response.find(kTokenPrefix) == std::string::npos)
60 return UnregistrationRequest::RESPONSE_PARSING_FAILED;
61
62 return UnregistrationRequest::SUCCESS;
63 }
64
65 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698