Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: chrome/browser/local_discovery/privet_confirm_api_flow.cc

Issue 298883012: Added GetURL, GetOAuthScope, GetExtraRequestHeaders into GCDBaseApiFlow::Delegate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/local_discovery/privet_confirm_api_flow.h" 5 #include "chrome/browser/local_discovery/privet_confirm_api_flow.h"
6 6
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/local_discovery/gcd_base_api_flow.h" 9 #include "chrome/browser/local_discovery/gcd_base_api_flow.h"
10 #include "chrome/browser/local_discovery/gcd_constants.h" 10 #include "chrome/browser/local_discovery/gcd_constants.h"
11 #include "chrome/browser/local_discovery/privet_constants.h" 11 #include "chrome/browser/local_discovery/privet_constants.h"
12 #include "chrome/common/cloud_print/cloud_print_constants.h" 12 #include "chrome/common/cloud_print/cloud_print_constants.h"
13 #include "components/cloud_devices/common/cloud_devices_urls.h" 13 #include "components/cloud_devices/common/cloud_devices_urls.h"
14 #include "net/base/url_util.h" 14 #include "net/base/url_util.h"
15 15
16 namespace local_discovery { 16 namespace local_discovery {
17 17
18 namespace { 18 namespace {
19 19
20 const char kGCDAutomatedClaimUploadData[] = "{ \"userEmail\": \"me\" }"; 20 GURL GetConfirmFlowUrl(const std::string& token) {
21 const char kGCDKindRegistrationTicket[] = "clouddevices#registrationTicket"; 21 return net::AppendQueryParameter(
22 22 cloud_devices::GetCloudPrintRelativeURL("confirm"), "token", token);
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);
27 }
28 return cloud_devices::GetCloudDevicesRelativeURL("registrationTickets/" +
29 token);
30 } 23 }
31 24
32 } // namespace 25 } // namespace
33 26
34 PrivetConfirmApiCallFlow::PrivetConfirmApiCallFlow( 27 PrivetConfirmApiCallFlow::PrivetConfirmApiCallFlow(
35 net::URLRequestContextGetter* request_context, 28 net::URLRequestContextGetter* request_context,
36 OAuth2TokenService* token_service, 29 OAuth2TokenService* token_service,
37 const std::string& account_id, 30 const std::string& account_id,
38 bool is_cloud_print,
39 const std::string& token, 31 const std::string& token,
40 const ResponseCallback& callback) 32 const ResponseCallback& callback)
41 : is_cloud_print_(is_cloud_print), 33 : flow_(request_context,
42 flow_(request_context,
43 token_service, 34 token_service,
44 account_id, 35 account_id,
45 GetConfirmFlowUrl(is_cloud_print, token),
46 this), 36 this),
47 callback_(callback) { 37 callback_(callback),
38 token_(token) {
48 } 39 }
49 40
50 PrivetConfirmApiCallFlow::~PrivetConfirmApiCallFlow() { 41 PrivetConfirmApiCallFlow::~PrivetConfirmApiCallFlow() {
51 } 42 }
52 43
53 void PrivetConfirmApiCallFlow::Start() { 44 void PrivetConfirmApiCallFlow::Start() {
54 flow_.Start(); 45 flow_.Start();
55 } 46 }
56 47
57 void PrivetConfirmApiCallFlow::OnGCDAPIFlowError( 48 void PrivetConfirmApiCallFlow::OnGCDAPIFlowError(
58 GCDBaseApiFlow* flow, 49 GCDBaseApiFlow* flow,
59 GCDBaseApiFlow::Status status) { 50 GCDBaseApiFlow::Status status) {
60 callback_.Run(status); 51 callback_.Run(status);
61 } 52 }
62 53
63 void PrivetConfirmApiCallFlow::OnGCDAPIFlowComplete( 54 void PrivetConfirmApiCallFlow::OnGCDAPIFlowComplete(
64 GCDBaseApiFlow* flow, 55 GCDBaseApiFlow* flow,
65 const base::DictionaryValue* value) { 56 const base::DictionaryValue* value) {
66 bool success = false; 57 bool success = false;
67 58
68 if (is_cloud_print_) { 59 if (!value->GetBoolean(cloud_print::kSuccessValue, &success)) {
69 if (!value->GetBoolean(cloud_print::kSuccessValue, &success)) { 60 callback_.Run(GCDBaseApiFlow::ERROR_MALFORMED_RESPONSE);
70 callback_.Run(GCDBaseApiFlow::ERROR_MALFORMED_RESPONSE); 61 return;
71 return;
72 }
73 } else {
74 std::string kind;
75 value->GetString(kGCDKeyKind, &kind);
76 success = (kind == kGCDKindRegistrationTicket);
77 } 62 }
78 63
79 if (success) { 64 if (success) {
80 callback_.Run(GCDBaseApiFlow::SUCCESS); 65 callback_.Run(GCDBaseApiFlow::SUCCESS);
81 } else { 66 } else {
82 callback_.Run(GCDBaseApiFlow::ERROR_FROM_SERVER); 67 callback_.Run(GCDBaseApiFlow::ERROR_FROM_SERVER);
83 } 68 }
84 } 69 }
85 70
86 bool PrivetConfirmApiCallFlow::GCDIsCloudPrint() { return is_cloud_print_; }
87
88 net::URLFetcher::RequestType PrivetConfirmApiCallFlow::GetRequestType() { 71 net::URLFetcher::RequestType PrivetConfirmApiCallFlow::GetRequestType() {
89 return (is_cloud_print_) ? net::URLFetcher::GET : net::URLFetcher::PATCH; 72 return net::URLFetcher::GET;
90 } 73 }
91 74
92 void PrivetConfirmApiCallFlow::GetUploadData(std::string* upload_type, 75 GURL PrivetConfirmApiCallFlow::GetURL() {
93 std::string* upload_data) { 76 return GetConfirmFlowUrl(token_);
94 if (is_cloud_print_) {
95 *upload_type = "";
96 *upload_data = "";
97 } else {
98 *upload_type = cloud_print::kContentTypeJSON;
99 *upload_data = kGCDAutomatedClaimUploadData;
100 }
101 } 77 }
102 78
103 } // namespace local_discovery 79 } // namespace local_discovery
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698