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. 4 5 #include "chrome/browser/local_discovery/privet_confirm_api_flow.h" 6 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" 15 16 namespace local_discovery { 17 18 namespace { 19 20 GURL GetConfirmFlowUrl(const std::string& token) { 21 return net::AppendQueryParameter( 22 cloud_devices::GetCloudPrintRelativeURL("confirm"), "token", token); 23 } 24 25 } // namespace 26 27 PrivetConfirmApiCallFlow::PrivetConfirmApiCallFlow( 28 const std::string& token, 29 const ResponseCallback& callback) 30 : callback_(callback), token_(token) { 31 } 32 33 PrivetConfirmApiCallFlow::~PrivetConfirmApiCallFlow() { 34 } 35 36 void PrivetConfirmApiCallFlow::OnGCDAPIFlowError(GCDApiFlow::Status status) { 37 callback_.Run(status); 38 } 39 40 void PrivetConfirmApiCallFlow::OnGCDAPIFlowComplete( 41 const base::DictionaryValue& value) { 42 bool success = false; 43 44 if (!value.GetBoolean(cloud_print::kSuccessValue, &success)) { 45 callback_.Run(GCDApiFlow::ERROR_MALFORMED_RESPONSE); 46 return; 47 } 48 49 if (success) { 50 callback_.Run(GCDApiFlow::SUCCESS); 51 } else { 52 callback_.Run(GCDApiFlow::ERROR_FROM_SERVER); 53 } 54 } 55 56 net::URLFetcher::RequestType PrivetConfirmApiCallFlow::GetRequestType() { 57 return net::URLFetcher::GET; 58 } 59 60 GURL PrivetConfirmApiCallFlow::GetURL() { 61 return GetConfirmFlowUrl(token_); 62 } 63 64 } // namespace local_discovery 65