privet_confirm_api_flow.cc revision 68043e1e95eeb07d5cae7aca370b26518b0867d6
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 "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"
9
10namespace local_discovery {
11
12PrivetConfirmApiCallFlow::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) {
24}
25
26PrivetConfirmApiCallFlow::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) {
38}
39
40PrivetConfirmApiCallFlow::~PrivetConfirmApiCallFlow() {
41}
42
43void PrivetConfirmApiCallFlow::Start() {
44  flow_.Start();
45}
46
47void PrivetConfirmApiCallFlow::OnCloudPrintAPIFlowError(
48    CloudPrintBaseApiFlow* flow,
49    CloudPrintBaseApiFlow::Status status) {
50  callback_.Run(status);
51}
52
53void PrivetConfirmApiCallFlow::OnCloudPrintAPIFlowComplete(
54    CloudPrintBaseApiFlow* flow,
55    const base::DictionaryValue* value) {
56  bool success = false;
57
58  if (!value->GetBoolean(cloud_print::kSuccessValue, &success)) {
59    callback_.Run(CloudPrintBaseApiFlow::ERROR_MALFORMED_RESPONSE);
60    return;
61  }
62
63  if (success) {
64    callback_.Run(CloudPrintBaseApiFlow::SUCCESS);
65  } else {
66    callback_.Run(CloudPrintBaseApiFlow::ERROR_FROM_SERVER);
67  }
68}
69
70}  // namespace local_discovery
71