Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / local_discovery / privet_confirm_api_flow.cc
blobc12a9773e45f3e63b6366e4e7e89fa27e064e536
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_base_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 const char kGCDAutomatedClaimUploadData[] = "{ \"userEmail\": \"me\" }";
21 const char kGCDKindRegistrationTicket[] = "clouddevices#registrationTicket";
23 GURL GetConfirmFlowUrl(bool is_cloud_print, const std::string& token) {
24 if (is_cloud_print) {
25 return net::AppendQueryParameter(
26 cloud_devices::GetCloudPrintRelativeURL("confirm"), "token", token);
28 return cloud_devices::GetCloudDevicesRelativeURL("registrationTickets/" +
29 token);
32 } // namespace
34 PrivetConfirmApiCallFlow::PrivetConfirmApiCallFlow(
35 net::URLRequestContextGetter* request_context,
36 OAuth2TokenService* token_service,
37 const std::string& account_id,
38 bool is_cloud_print,
39 const std::string& token,
40 const ResponseCallback& callback)
41 : is_cloud_print_(is_cloud_print),
42 flow_(request_context,
43 token_service,
44 account_id,
45 GetConfirmFlowUrl(is_cloud_print, token),
46 this),
47 callback_(callback) {
50 PrivetConfirmApiCallFlow::~PrivetConfirmApiCallFlow() {
53 void PrivetConfirmApiCallFlow::Start() {
54 flow_.Start();
57 void PrivetConfirmApiCallFlow::OnGCDAPIFlowError(
58 GCDBaseApiFlow* flow,
59 GCDBaseApiFlow::Status status) {
60 callback_.Run(status);
63 void PrivetConfirmApiCallFlow::OnGCDAPIFlowComplete(
64 GCDBaseApiFlow* flow,
65 const base::DictionaryValue* value) {
66 bool success = false;
68 if (is_cloud_print_) {
69 if (!value->GetBoolean(cloud_print::kSuccessValue, &success)) {
70 callback_.Run(GCDBaseApiFlow::ERROR_MALFORMED_RESPONSE);
71 return;
73 } else {
74 std::string kind;
75 value->GetString(kGCDKeyKind, &kind);
76 success = (kind == kGCDKindRegistrationTicket);
79 if (success) {
80 callback_.Run(GCDBaseApiFlow::SUCCESS);
81 } else {
82 callback_.Run(GCDBaseApiFlow::ERROR_FROM_SERVER);
86 bool PrivetConfirmApiCallFlow::GCDIsCloudPrint() { return is_cloud_print_; }
88 net::URLFetcher::RequestType PrivetConfirmApiCallFlow::GetRequestType() {
89 return (is_cloud_print_) ? net::URLFetcher::GET : net::URLFetcher::PATCH;
92 void PrivetConfirmApiCallFlow::GetUploadData(std::string* upload_type,
93 std::string* upload_data) {
94 if (is_cloud_print_) {
95 *upload_type = "";
96 *upload_data = "";
97 } else {
98 *upload_type = cloud_print::kContentTypeJSON;
99 *upload_data = kGCDAutomatedClaimUploadData;
103 } // namespace local_discovery