Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / chrome / browser / local_discovery / privet_confirm_api_flow.cc
blobadc4e957b7201e0ecddf7b2aa48bea0ce8a41d12
1 // Copyright 2013 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.
5 #include "chrome/browser/local_discovery/privet_confirm_api_flow.h"
7 #include "base/strings/stringprintf.h"
8 #include "base/values.h"
9 #include "chrome/browser/local_discovery/gcd_api_flow.h"
10 #include "chrome/browser/local_discovery/gcd_constants.h"
11 #include "chrome/browser/local_discovery/privet_constants.h"
12 #include "chrome/common/cloud_print/cloud_print_constants.h"
13 #include "components/cloud_devices/common/cloud_devices_urls.h"
14 #include "net/base/url_util.h"
16 namespace local_discovery {
18 namespace {
20 GURL GetConfirmFlowUrl(const std::string& token) {
21 return net::AppendQueryParameter(
22 cloud_devices::GetCloudPrintRelativeURL("confirm"), "token", token);
25 } // namespace
27 PrivetConfirmApiCallFlow::PrivetConfirmApiCallFlow(
28 const std::string& token,
29 const ResponseCallback& callback)
30 : callback_(callback), token_(token) {
33 PrivetConfirmApiCallFlow::~PrivetConfirmApiCallFlow() {
36 void PrivetConfirmApiCallFlow::OnGCDAPIFlowError(GCDApiFlow::Status status) {
37 callback_.Run(status);
40 void PrivetConfirmApiCallFlow::OnGCDAPIFlowComplete(
41 const base::DictionaryValue& value) {
42 bool success = false;
44 if (!value.GetBoolean(cloud_print::kSuccessValue, &success)) {
45 callback_.Run(GCDApiFlow::ERROR_MALFORMED_RESPONSE);
46 return;
49 if (success) {
50 callback_.Run(GCDApiFlow::SUCCESS);
51 } else {
52 callback_.Run(GCDApiFlow::ERROR_FROM_SERVER);
56 net::URLFetcher::RequestType PrivetConfirmApiCallFlow::GetRequestType() {
57 return net::URLFetcher::GET;
60 GURL PrivetConfirmApiCallFlow::GetURL() {
61 return GetConfirmFlowUrl(token_);
64 } // namespace local_discovery