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

Side by Side Diff: chrome/browser/supervised_user/legacy/supervised_user_refresh_token_fetcher.cc

Issue 1165323004: We should use UserID object to identify users instead of username. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/supervised_user/legacy/supervised_user_refresh_token_fe tcher.h" 5 #include "chrome/browser/supervised_user/legacy/supervised_user_refresh_token_fe tcher.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "components/user_manager/user_id.h"
12 #include "google_apis/gaia/gaia_constants.h" 13 #include "google_apis/gaia/gaia_constants.h"
13 #include "google_apis/gaia/gaia_oauth_client.h" 14 #include "google_apis/gaia/gaia_oauth_client.h"
14 #include "google_apis/gaia/gaia_urls.h" 15 #include "google_apis/gaia/gaia_urls.h"
15 #include "google_apis/gaia/google_service_auth_error.h" 16 #include "google_apis/gaia/google_service_auth_error.h"
16 #include "google_apis/gaia/oauth2_api_call_flow.h" 17 #include "google_apis/gaia/oauth2_api_call_flow.h"
17 #include "google_apis/gaia/oauth2_token_service.h" 18 #include "google_apis/gaia/oauth2_token_service.h"
18 #include "net/base/escape.h" 19 #include "net/base/escape.h"
19 #include "net/base/load_flags.h" 20 #include "net/base/load_flags.h"
20 #include "net/base/net_errors.h" 21 #include "net/base/net_errors.h"
21 #include "net/http/http_status_code.h" 22 #include "net/http/http_status_code.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 public GaiaOAuthClient::Delegate { 57 public GaiaOAuthClient::Delegate {
57 public: 58 public:
58 SupervisedUserRefreshTokenFetcherImpl( 59 SupervisedUserRefreshTokenFetcherImpl(
59 OAuth2TokenService* oauth2_token_service, 60 OAuth2TokenService* oauth2_token_service,
60 const std::string& account_id, 61 const std::string& account_id,
61 const std::string& device_id, 62 const std::string& device_id,
62 URLRequestContextGetter* context); 63 URLRequestContextGetter* context);
63 ~SupervisedUserRefreshTokenFetcherImpl() override; 64 ~SupervisedUserRefreshTokenFetcherImpl() override;
64 65
65 // SupervisedUserRefreshTokenFetcher implementation: 66 // SupervisedUserRefreshTokenFetcher implementation:
66 void Start(const std::string& supervised_user_id, 67 void Start(const user_manager::UserID& supervised_user_id,
67 const std::string& device_name, 68 const std::string& device_name,
68 const TokenCallback& callback) override; 69 const TokenCallback& callback) override;
69 70
70 protected: 71 protected:
71 // OAuth2TokenService::Consumer implementation: 72 // OAuth2TokenService::Consumer implementation:
72 void OnGetTokenSuccess(const OAuth2TokenService::Request* request, 73 void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
73 const std::string& access_token, 74 const std::string& access_token,
74 const Time& expiration_time) override; 75 const Time& expiration_time) override;
75 void OnGetTokenFailure(const OAuth2TokenService::Request* request, 76 void OnGetTokenFailure(const OAuth2TokenService::Request* request,
76 const GoogleServiceAuthError& error) override; 77 const GoogleServiceAuthError& error) override;
(...skipping 17 matching lines...) Expand all
94 95
95 void DispatchNetworkError(int error_code); 96 void DispatchNetworkError(int error_code);
96 void DispatchGoogleServiceAuthError(const GoogleServiceAuthError& error, 97 void DispatchGoogleServiceAuthError(const GoogleServiceAuthError& error,
97 const std::string& token); 98 const std::string& token);
98 OAuth2TokenService* oauth2_token_service_; 99 OAuth2TokenService* oauth2_token_service_;
99 std::string account_id_; 100 std::string account_id_;
100 std::string device_id_; 101 std::string device_id_;
101 URLRequestContextGetter* context_; 102 URLRequestContextGetter* context_;
102 103
103 std::string device_name_; 104 std::string device_name_;
104 std::string supervised_user_id_; 105 user_manager::UserID supervised_user_id_;
105 TokenCallback callback_; 106 TokenCallback callback_;
106 107
107 scoped_ptr<OAuth2TokenService::Request> access_token_request_; 108 scoped_ptr<OAuth2TokenService::Request> access_token_request_;
108 std::string access_token_; 109 std::string access_token_;
109 bool access_token_expired_; 110 bool access_token_expired_;
110 scoped_ptr<URLFetcher> url_fetcher_; 111 scoped_ptr<URLFetcher> url_fetcher_;
111 scoped_ptr<GaiaOAuthClient> gaia_oauth_client_; 112 scoped_ptr<GaiaOAuthClient> gaia_oauth_client_;
112 }; 113 };
113 114
114 SupervisedUserRefreshTokenFetcherImpl::SupervisedUserRefreshTokenFetcherImpl( 115 SupervisedUserRefreshTokenFetcherImpl::SupervisedUserRefreshTokenFetcherImpl(
115 OAuth2TokenService* oauth2_token_service, 116 OAuth2TokenService* oauth2_token_service,
116 const std::string& account_id, 117 const std::string& account_id,
117 const std::string& device_id, 118 const std::string& device_id,
118 URLRequestContextGetter* context) 119 URLRequestContextGetter* context)
119 : OAuth2TokenService::Consumer("supervised_user"), 120 : OAuth2TokenService::Consumer("supervised_user"),
120 oauth2_token_service_(oauth2_token_service), 121 oauth2_token_service_(oauth2_token_service),
121 account_id_(account_id), 122 account_id_(account_id),
122 device_id_(device_id), 123 device_id_(device_id),
123 context_(context), 124 context_(context),
125 supervised_user_id_(std::string(), std::string()),
124 access_token_expired_(false) {} 126 access_token_expired_(false) {}
125 127
126 SupervisedUserRefreshTokenFetcherImpl:: 128 SupervisedUserRefreshTokenFetcherImpl::
127 ~SupervisedUserRefreshTokenFetcherImpl() {} 129 ~SupervisedUserRefreshTokenFetcherImpl() {}
128 130
129 void SupervisedUserRefreshTokenFetcherImpl::Start( 131 void SupervisedUserRefreshTokenFetcherImpl::Start(
130 const std::string& supervised_user_id, 132 const user_manager::UserID& supervised_user_id,
131 const std::string& device_name, 133 const std::string& device_name,
132 const TokenCallback& callback) { 134 const TokenCallback& callback) {
133 DCHECK(callback_.is_null()); 135 DCHECK(callback_.is_null());
134 supervised_user_id_ = supervised_user_id; 136 supervised_user_id_ = supervised_user_id;
135 device_name_ = device_name; 137 device_name_ = device_name;
136 callback_ = callback; 138 callback_ = callback;
137 StartFetching(); 139 StartFetching();
138 } 140 }
139 141
140 void SupervisedUserRefreshTokenFetcherImpl::StartFetching() { 142 void SupervisedUserRefreshTokenFetcherImpl::StartFetching() {
(...skipping 22 matching lines...) Expand all
163 net::LOAD_DO_NOT_SAVE_COOKIES); 165 net::LOAD_DO_NOT_SAVE_COOKIES);
164 url_fetcher_->SetAutomaticallyRetryOnNetworkChanges(kNumRetries); 166 url_fetcher_->SetAutomaticallyRetryOnNetworkChanges(kNumRetries);
165 url_fetcher_->AddExtraRequestHeader( 167 url_fetcher_->AddExtraRequestHeader(
166 base::StringPrintf(kAuthorizationHeaderFormat, access_token.c_str())); 168 base::StringPrintf(kAuthorizationHeaderFormat, access_token.c_str()));
167 169
168 std::string body = base::StringPrintf( 170 std::string body = base::StringPrintf(
169 kIssueTokenBodyFormat, 171 kIssueTokenBodyFormat,
170 net::EscapeUrlEncodedData( 172 net::EscapeUrlEncodedData(
171 GaiaUrls::GetInstance()->oauth2_chrome_client_id(), true).c_str(), 173 GaiaUrls::GetInstance()->oauth2_chrome_client_id(), true).c_str(),
172 net::EscapeUrlEncodedData(kChromeSyncSupervisedOAuth2Scope, true).c_str(), 174 net::EscapeUrlEncodedData(kChromeSyncSupervisedOAuth2Scope, true).c_str(),
173 net::EscapeUrlEncodedData(supervised_user_id_, true).c_str(), 175 net::EscapeUrlEncodedData(supervised_user_id_.GetUserEmail(), true).c_str( ),
174 net::EscapeUrlEncodedData(device_name_, true).c_str()); 176 net::EscapeUrlEncodedData(device_name_, true).c_str());
175 if (!device_id_.empty()) { 177 if (!device_id_.empty()) {
176 body.append(base::StringPrintf( 178 body.append(base::StringPrintf(
177 kIssueTokenBodyFormatDeviceIdAddendum, 179 kIssueTokenBodyFormatDeviceIdAddendum,
178 net::EscapeUrlEncodedData(device_id_, true).c_str())); 180 net::EscapeUrlEncodedData(device_id_, true).c_str()));
179 } 181 }
180 url_fetcher_->SetUploadData("application/x-www-form-urlencoded", body); 182 url_fetcher_->SetUploadData("application/x-www-form-urlencoded", body);
181 183
182 url_fetcher_->Start(); 184 url_fetcher_->Start();
183 } 185 }
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 URLRequestContextGetter* context) { 296 URLRequestContextGetter* context) {
295 scoped_ptr<SupervisedUserRefreshTokenFetcher> fetcher( 297 scoped_ptr<SupervisedUserRefreshTokenFetcher> fetcher(
296 new SupervisedUserRefreshTokenFetcherImpl(oauth2_token_service, 298 new SupervisedUserRefreshTokenFetcherImpl(oauth2_token_service,
297 account_id, 299 account_id,
298 device_id, 300 device_id,
299 context)); 301 context));
300 return fetcher.Pass(); 302 return fetcher.Pass();
301 } 303 }
302 304
303 SupervisedUserRefreshTokenFetcher::~SupervisedUserRefreshTokenFetcher() {} 305 SupervisedUserRefreshTokenFetcher::~SupervisedUserRefreshTokenFetcher() {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698