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

Side by Side Diff: chrome/common/net/gaia/oauth2_mint_token_fetcher.cc

Issue 10386063: Move URLFetcherDelegate to net/ and split URLFetcher between net/ and content/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync to head, fix win component build Created 8 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/common/net/gaia/oauth2_mint_token_fetcher.h" 5 #include "chrome/common/net/gaia/oauth2_mint_token_fetcher.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 state_ = MINT_TOKEN_STARTED; 102 state_ = MINT_TOKEN_STARTED;
103 fetcher_.reset(CreateFetcher( 103 fetcher_.reset(CreateFetcher(
104 getter_, 104 getter_,
105 MakeMintTokenUrl(), 105 MakeMintTokenUrl(),
106 MakeMintTokenHeader(oauth_login_access_token_), 106 MakeMintTokenHeader(oauth_login_access_token_),
107 MakeMintTokenBody(client_id_, scopes_, origin_), 107 MakeMintTokenBody(client_id_, scopes_, origin_),
108 this)); 108 this));
109 fetcher_->Start(); // OnURLFetchComplete will be called. 109 fetcher_->Start(); // OnURLFetchComplete will be called.
110 } 110 }
111 111
112 void OAuth2MintTokenFetcher::EndMintToken(const URLFetcher* source) { 112 void OAuth2MintTokenFetcher::EndMintToken(const net::URLFetcher* source) {
113 CHECK_EQ(MINT_TOKEN_STARTED, state_); 113 CHECK_EQ(MINT_TOKEN_STARTED, state_);
114 state_ = MINT_TOKEN_DONE; 114 state_ = MINT_TOKEN_DONE;
115 115
116 URLRequestStatus status = source->GetStatus(); 116 URLRequestStatus status = source->GetStatus();
117 if (!status.is_success()) { 117 if (!status.is_success()) {
118 OnMintTokenFailure(CreateAuthError(status)); 118 OnMintTokenFailure(CreateAuthError(status));
119 return; 119 return;
120 } 120 }
121 121
122 if (source->GetResponseCode() != net::HTTP_OK) { 122 if (source->GetResponseCode() != net::HTTP_OK) {
(...skipping 13 matching lines...) Expand all
136 const std::string& access_token) { 136 const std::string& access_token) {
137 consumer_->OnMintTokenSuccess(access_token); 137 consumer_->OnMintTokenSuccess(access_token);
138 } 138 }
139 139
140 void OAuth2MintTokenFetcher::OnMintTokenFailure( 140 void OAuth2MintTokenFetcher::OnMintTokenFailure(
141 const GoogleServiceAuthError& error) { 141 const GoogleServiceAuthError& error) {
142 state_ = ERROR_STATE; 142 state_ = ERROR_STATE;
143 consumer_->OnMintTokenFailure(error); 143 consumer_->OnMintTokenFailure(error);
144 } 144 }
145 145
146 void OAuth2MintTokenFetcher::OnURLFetchComplete(const URLFetcher* source) { 146 void OAuth2MintTokenFetcher::OnURLFetchComplete(const net::URLFetcher* source) {
147 CHECK(source); 147 CHECK(source);
148 CHECK_EQ(MINT_TOKEN_STARTED, state_); 148 CHECK_EQ(MINT_TOKEN_STARTED, state_);
149 EndMintToken(source); 149 EndMintToken(source);
150 } 150 }
151 151
152 // static 152 // static
153 GURL OAuth2MintTokenFetcher::MakeMintTokenUrl() { 153 GURL OAuth2MintTokenFetcher::MakeMintTokenUrl() {
154 return GURL(GaiaUrls::GetInstance()->oauth2_issue_token_url()); 154 return GURL(GaiaUrls::GetInstance()->oauth2_issue_token_url());
155 } 155 }
156 156
(...skipping 10 matching lines...) Expand all
167 const std::string& origin) { 167 const std::string& origin) {
168 return StringPrintf( 168 return StringPrintf(
169 kOAuth2IssueTokenBodyFormat, 169 kOAuth2IssueTokenBodyFormat,
170 net::EscapeUrlEncodedData(JoinString(scopes, ','), true).c_str(), 170 net::EscapeUrlEncodedData(JoinString(scopes, ','), true).c_str(),
171 net::EscapeUrlEncodedData(client_id, true).c_str(), 171 net::EscapeUrlEncodedData(client_id, true).c_str(),
172 net::EscapeUrlEncodedData(origin, true).c_str()); 172 net::EscapeUrlEncodedData(origin, true).c_str());
173 } 173 }
174 174
175 // static 175 // static
176 bool OAuth2MintTokenFetcher::ParseMintTokenResponse( 176 bool OAuth2MintTokenFetcher::ParseMintTokenResponse(
177 const URLFetcher* source, 177 const net::URLFetcher* source,
178 std::string* access_token) { 178 std::string* access_token) {
179 CHECK(source); 179 CHECK(source);
180 CHECK(access_token); 180 CHECK(access_token);
181 std::string data; 181 std::string data;
182 source->GetResponseAsString(&data); 182 source->GetResponseAsString(&data);
183 scoped_ptr<base::Value> value(base::JSONReader::Read(data)); 183 scoped_ptr<base::Value> value(base::JSONReader::Read(data));
184 if (!value.get() || value->GetType() != base::Value::TYPE_DICTIONARY) 184 if (!value.get() || value->GetType() != base::Value::TYPE_DICTIONARY)
185 return false; 185 return false;
186 186
187 DictionaryValue* dict = static_cast<DictionaryValue*>(value.get()); 187 DictionaryValue* dict = static_cast<DictionaryValue*>(value.get());
188 return dict->GetString(kAccessTokenKey, access_token); 188 return dict->GetString(kAccessTokenKey, access_token);
189 } 189 }
OLDNEW
« no previous file with comments | « chrome/common/net/gaia/oauth2_mint_token_fetcher.h ('k') | chrome/common/net/gaia/oauth2_mint_token_flow.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698