Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / local_discovery / privet_confirm_api_flow.cc
blob2f4219402067dad7459eabe356c67987bf3e08b0
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 "base/values.h"
6 #include "chrome/browser/local_discovery/cloud_print_base_api_flow.h"
7 #include "chrome/browser/local_discovery/privet_confirm_api_flow.h"
8 #include "chrome/common/cloud_print/cloud_print_constants.h"
10 namespace local_discovery {
12 PrivetConfirmApiCallFlow::PrivetConfirmApiCallFlow(
13 net::URLRequestContextGetter* request_context,
14 OAuth2TokenService* token_service,
15 const std::string& account_id,
16 const GURL& automated_claim_url,
17 const ResponseCallback& callback)
18 : flow_(request_context,
19 token_service,
20 account_id,
21 automated_claim_url,
22 this),
23 callback_(callback) {
26 PrivetConfirmApiCallFlow::PrivetConfirmApiCallFlow(
27 net::URLRequestContextGetter* request_context,
28 int user_index,
29 const std::string& xsrf_token,
30 const GURL& automated_claim_url,
31 const ResponseCallback& callback)
32 : flow_(request_context,
33 user_index,
34 xsrf_token,
35 automated_claim_url,
36 this),
37 callback_(callback) {
40 PrivetConfirmApiCallFlow::~PrivetConfirmApiCallFlow() {
43 void PrivetConfirmApiCallFlow::Start() {
44 flow_.Start();
47 void PrivetConfirmApiCallFlow::OnCloudPrintAPIFlowError(
48 CloudPrintBaseApiFlow* flow,
49 CloudPrintBaseApiFlow::Status status) {
50 callback_.Run(status);
53 void PrivetConfirmApiCallFlow::OnCloudPrintAPIFlowComplete(
54 CloudPrintBaseApiFlow* flow,
55 const base::DictionaryValue* value) {
56 bool success = false;
58 if (!value->GetBoolean(cloud_print::kSuccessValue, &success)) {
59 callback_.Run(CloudPrintBaseApiFlow::ERROR_MALFORMED_RESPONSE);
60 return;
63 if (success) {
64 callback_.Run(CloudPrintBaseApiFlow::SUCCESS);
65 } else {
66 callback_.Run(CloudPrintBaseApiFlow::ERROR_FROM_SERVER);
70 } // namespace local_discovery