OLD | NEW |
---|---|
(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. | |
Nicolas Zea
2015/05/26 16:39:14
nit: Combine with previous group? (considering the
jianli
2015/05/26 20:49:38
The comment is indeed not the same, one for reques
| |
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() && !authorized_entity.empty() && !scope.empty()); | |
37 } | |
38 | |
39 InstanceIDDeleteTokenRequestHandler::~InstanceIDDeleteTokenRequestHandler() {} | |
40 | |
41 void InstanceIDDeleteTokenRequestHandler::BuildRequestBody(std::string* body){ | |
42 BuildFormEncoding(kInstanceIDKey, instance_id_, body); | |
43 BuildFormEncoding(kSenderKey, authorized_entity_, body); | |
44 BuildFormEncoding(kScopeKey, scope_, body); | |
45 BuildFormEncoding(kGMSVersionKey, base::IntToString(gcm_version_), body); | |
46 } | |
47 | |
48 UnregistrationRequest::Status | |
49 InstanceIDDeleteTokenRequestHandler::ParseResponse( | |
50 const net::URLFetcher* source) { | |
51 std::string response; | |
52 if (!source->GetResponseAsString(&response)) { | |
53 DVLOG(1) << "Failed to get response body."; | |
54 return UnregistrationRequest::NO_RESPONSE_BODY; | |
55 } | |
56 | |
57 if (response.find(kTokenPrefix) == std::string::npos) | |
58 return UnregistrationRequest::RESPONSE_PARSING_FAILED; | |
59 | |
60 return UnregistrationRequest::SUCCESS; | |
61 } | |
62 | |
63 } // namespace gcm | |
OLD | NEW |