OLD | NEW |
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/string_number_conversions.h" | 6 #include "base/strings/string_number_conversions.h" |
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/cloud_print_base_api_flow.h" | 9 #include "chrome/browser/local_discovery/cloud_print_base_api_flow.h" |
10 #include "chrome/common/cloud_print/cloud_print_constants.h" | 10 #include "chrome/common/cloud_print/cloud_print_constants.h" |
11 #include "google_apis/gaia/google_service_auth_error.h" | 11 #include "google_apis/gaia/google_service_auth_error.h" |
12 #include "net/base/load_flags.h" | 12 #include "net/base/load_flags.h" |
13 #include "net/base/url_util.h" | 13 #include "net/base/url_util.h" |
14 #include "net/http/http_status_code.h" | 14 #include "net/http/http_status_code.h" |
15 #include "net/url_request/url_request_status.h" | 15 #include "net/url_request/url_request_status.h" |
16 | 16 |
17 namespace local_discovery { | 17 namespace local_discovery { |
18 | 18 |
19 namespace { | 19 namespace { |
20 const char kCloudPrintOAuthHeaderFormat[] = "Authorization: Bearer %s"; | 20 const char kCloudPrintOAuthHeaderFormat[] = "Authorization: Bearer %s"; |
21 const char kXSRFURLParameterKey[] = "xsrf"; | 21 const char kXSRFURLParameterKey[] = "xsrf"; |
22 const char kUserURLParameterKey[] = "user"; | 22 const char kUserURLParameterKey[] = "user"; |
23 } | 23 } |
24 | 24 |
25 CloudPrintBaseApiFlow::CloudPrintBaseApiFlow( | 25 CloudPrintBaseApiFlow::CloudPrintBaseApiFlow( |
26 net::URLRequestContextGetter* request_context, | 26 net::URLRequestContextGetter* request_context, |
27 OAuth2TokenService* token_service, | 27 OAuth2TokenService* token_service, |
| 28 const std::string& account_id, |
28 const GURL& automated_claim_url, | 29 const GURL& automated_claim_url, |
29 Delegate* delegate) | 30 Delegate* delegate) |
30 : request_context_(request_context), | 31 : request_context_(request_context), |
31 token_service_(token_service), | 32 token_service_(token_service), |
| 33 account_id_(account_id), |
32 user_index_(kAccountIndexUseOAuth2), | 34 user_index_(kAccountIndexUseOAuth2), |
33 url_(automated_claim_url), | 35 url_(automated_claim_url), |
34 delegate_(delegate) { | 36 delegate_(delegate) { |
35 } | 37 } |
36 | 38 |
37 CloudPrintBaseApiFlow::CloudPrintBaseApiFlow( | 39 CloudPrintBaseApiFlow::CloudPrintBaseApiFlow( |
38 net::URLRequestContextGetter* request_context, | 40 net::URLRequestContextGetter* request_context, |
39 int user_index, | 41 int user_index, |
40 const std::string& xsrf_token, | 42 const std::string& xsrf_token, |
41 const GURL& automated_claim_url, | 43 const GURL& automated_claim_url, |
42 Delegate* delegate) | 44 Delegate* delegate) |
43 : request_context_(request_context), | 45 : request_context_(request_context), |
44 token_service_(NULL), | 46 token_service_(NULL), |
| 47 account_id_(""), |
45 user_index_(user_index), | 48 user_index_(user_index), |
46 xsrf_token_(xsrf_token), | 49 xsrf_token_(xsrf_token), |
47 url_(automated_claim_url), | 50 url_(automated_claim_url), |
48 delegate_(delegate) { | 51 delegate_(delegate) { |
49 } | 52 } |
50 | 53 |
51 CloudPrintBaseApiFlow::CloudPrintBaseApiFlow( | 54 CloudPrintBaseApiFlow::CloudPrintBaseApiFlow( |
52 net::URLRequestContextGetter* request_context, | 55 net::URLRequestContextGetter* request_context, |
53 int user_index, | 56 int user_index, |
54 const GURL& automated_claim_url, | 57 const GURL& automated_claim_url, |
55 Delegate* delegate) | 58 Delegate* delegate) |
56 : request_context_(request_context), | 59 : request_context_(request_context), |
57 token_service_(NULL), | 60 token_service_(NULL), |
| 61 account_id_(""), |
58 user_index_(user_index), | 62 user_index_(user_index), |
59 url_(automated_claim_url), | 63 url_(automated_claim_url), |
60 delegate_(delegate) { | 64 delegate_(delegate) { |
61 } | 65 } |
62 | 66 |
63 CloudPrintBaseApiFlow::~CloudPrintBaseApiFlow() { | 67 CloudPrintBaseApiFlow::~CloudPrintBaseApiFlow() { |
64 } | 68 } |
65 | 69 |
66 void CloudPrintBaseApiFlow::Start() { | 70 void CloudPrintBaseApiFlow::Start() { |
67 if (UseOAuth2()) { | 71 if (UseOAuth2()) { |
68 OAuth2TokenService::ScopeSet oauth_scopes; | 72 OAuth2TokenService::ScopeSet oauth_scopes; |
69 oauth_scopes.insert(cloud_print::kCloudPrintAuth); | 73 oauth_scopes.insert(cloud_print::kCloudPrintAuth); |
70 oauth_request_ = token_service_->StartRequest(oauth_scopes, this); | 74 oauth_request_ = token_service_->StartRequest(account_id_, |
| 75 oauth_scopes, |
| 76 this); |
71 } else { | 77 } else { |
72 GURL cookie_url = url_; | 78 GURL cookie_url = url_; |
73 | 79 |
74 if (!xsrf_token_.empty()) { | 80 if (!xsrf_token_.empty()) { |
75 cookie_url = net::AppendQueryParameter(cookie_url, | 81 cookie_url = net::AppendQueryParameter(cookie_url, |
76 kXSRFURLParameterKey, | 82 kXSRFURLParameterKey, |
77 xsrf_token_); | 83 xsrf_token_); |
78 } | 84 } |
79 | 85 |
80 cookie_url = net::AppendQueryParameter(cookie_url, | 86 cookie_url = net::AppendQueryParameter(cookie_url, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 | 152 |
147 if (!value || !value->GetAsDictionary(&dictionary_value)) { | 153 if (!value || !value->GetAsDictionary(&dictionary_value)) { |
148 delegate_->OnCloudPrintAPIFlowError(this, ERROR_MALFORMED_RESPONSE); | 154 delegate_->OnCloudPrintAPIFlowError(this, ERROR_MALFORMED_RESPONSE); |
149 return; | 155 return; |
150 } | 156 } |
151 | 157 |
152 delegate_->OnCloudPrintAPIFlowComplete(this, dictionary_value); | 158 delegate_->OnCloudPrintAPIFlowComplete(this, dictionary_value); |
153 } | 159 } |
154 | 160 |
155 } // namespace local_discovery | 161 } // namespace local_discovery |
OLD | NEW |