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

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

Issue 23382008: Making OAuth2TokenService multi-login aware, updating callers, minor fixes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updates to AndroidPO2TS and removing the DCHECK(signin_manager) from GetPrimaryAccountId Created 7 years, 3 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
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 "base/json/json_reader.h" 5 #include "base/json/json_reader.h"
6 #include "base/strings/stringprintf.h" 6 #include "base/strings/stringprintf.h"
7 #include "base/values.h" 7 #include "base/values.h"
8 #include "chrome/browser/local_discovery/privet_confirm_api_flow.h" 8 #include "chrome/browser/local_discovery/privet_confirm_api_flow.h"
9 #include "chrome/common/cloud_print/cloud_print_constants.h" 9 #include "chrome/common/cloud_print/cloud_print_constants.h"
10 #include "google_apis/gaia/google_service_auth_error.h" 10 #include "google_apis/gaia/google_service_auth_error.h"
11 #include "net/base/load_flags.h" 11 #include "net/base/load_flags.h"
12 #include "net/http/http_status_code.h" 12 #include "net/http/http_status_code.h"
13 #include "net/url_request/url_request_status.h" 13 #include "net/url_request/url_request_status.h"
14 14
15 namespace local_discovery { 15 namespace local_discovery {
16 16
17 namespace { 17 namespace {
18 const char kCloudPrintOAuthHeaderFormat[] = "Authorization: Bearer %s"; 18 const char kCloudPrintOAuthHeaderFormat[] = "Authorization: Bearer %s";
19 const char kCookieURLFormat[] = "%s&xsrf=%s&user=%d"; 19 const char kCookieURLFormat[] = "%s&xsrf=%s&user=%d";
20 } 20 }
21 21
22 PrivetConfirmApiCallFlow::PrivetConfirmApiCallFlow( 22 PrivetConfirmApiCallFlow::PrivetConfirmApiCallFlow(
23 net::URLRequestContextGetter* request_context, 23 net::URLRequestContextGetter* request_context,
24 OAuth2TokenService* token_service, 24 OAuth2TokenService* token_service,
25 const std::string& account_id,
25 const GURL& automated_claim_url, 26 const GURL& automated_claim_url,
26 const ResponseCallback& callback) 27 const ResponseCallback& callback)
27 : request_context_(request_context), 28 : request_context_(request_context),
28 token_service_(token_service), 29 token_service_(token_service),
30 account_id_(account_id),
29 automated_claim_url_(automated_claim_url), 31 automated_claim_url_(automated_claim_url),
30 callback_(callback) { 32 callback_(callback) {
31 } 33 }
32 34
33 PrivetConfirmApiCallFlow::PrivetConfirmApiCallFlow( 35 PrivetConfirmApiCallFlow::PrivetConfirmApiCallFlow(
34 net::URLRequestContextGetter* request_context, 36 net::URLRequestContextGetter* request_context,
35 int user_index, 37 int user_index,
36 const std::string& xsrf_token, 38 const std::string& xsrf_token,
37 const GURL& automated_claim_url, 39 const GURL& automated_claim_url,
38 const ResponseCallback& callback) 40 const ResponseCallback& callback)
39 : request_context_(request_context), 41 : request_context_(request_context),
40 token_service_(NULL), 42 token_service_(NULL),
41 user_index_(user_index), 43 user_index_(user_index),
42 xsrf_token_(xsrf_token), 44 xsrf_token_(xsrf_token),
43 automated_claim_url_(automated_claim_url), 45 automated_claim_url_(automated_claim_url),
44 callback_(callback) { 46 callback_(callback) {
45 } 47 }
46 48
47 PrivetConfirmApiCallFlow::~PrivetConfirmApiCallFlow() { 49 PrivetConfirmApiCallFlow::~PrivetConfirmApiCallFlow() {
48 } 50 }
49 51
50 void PrivetConfirmApiCallFlow::Start() { 52 void PrivetConfirmApiCallFlow::Start() {
51 if (UseOAuth2()) { 53 if (UseOAuth2()) {
52 OAuth2TokenService::ScopeSet oauth_scopes; 54 OAuth2TokenService::ScopeSet oauth_scopes;
53 oauth_scopes.insert(cloud_print::kCloudPrintAuth); 55 oauth_scopes.insert(cloud_print::kCloudPrintAuth);
54 oauth_request_ = token_service_->StartRequest(oauth_scopes, this); 56 oauth_request_ = token_service_->StartRequest(account_id_, oauth_scopes,
57 this);
55 } else { 58 } else {
56 GURL cookie_url( 59 GURL cookie_url(
57 base::StringPrintf(kCookieURLFormat, 60 base::StringPrintf(kCookieURLFormat,
58 automated_claim_url_.spec().c_str(), 61 automated_claim_url_.spec().c_str(),
59 xsrf_token_.c_str(), 62 xsrf_token_.c_str(),
60 user_index_)); 63 user_index_));
61 64
62 CreateRequest(cookie_url); 65 CreateRequest(cookie_url);
63 66
64 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES); 67 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 } 133 }
131 134
132 if (success) { 135 if (success) {
133 callback_.Run(SUCCESS); 136 callback_.Run(SUCCESS);
134 } else { 137 } else {
135 callback_.Run(ERROR_FROM_SERVER); 138 callback_.Run(ERROR_FROM_SERVER);
136 } 139 }
137 } 140 }
138 141
139 } // namespace local_discovery 142 } // namespace local_discovery
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698