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

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

Issue 9570063: Add a flow class to abstract all the details of minting a token for an app. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 9 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/common/net/gaia/oauth2_mint_token_flow.h"
6
7 #include <string>
8 #include <vector>
9
10 #include "base/basictypes.h"
11 #include "chrome/common/net/gaia/gaia_urls.h"
12
13 using net::URLRequestContextGetter;
14
15 OAuth2MintTokenFlow::OAuth2MintTokenFlow(
16 URLRequestContextGetter* context,
17 Delegate* delegate)
18 : context_(context),
19 delegate_(delegate),
20 state_(INITIAL) {
21 }
22
23 OAuth2MintTokenFlow::~OAuth2MintTokenFlow() { }
24
25 void OAuth2MintTokenFlow::Start(
26 const std::string& login_refresh_token,
27 const std::string& extension_id,
28 const std::string& client_id,
29 const std::vector<std::string>& scopes) {
30 login_refresh_token_ = login_refresh_token;
31 extension_id_ = extension_id;
32 client_id_ = client_id;
33 scopes_ = scopes;
34
35 BeginGetLoginAccessToken();
36 }
37
38 void OAuth2MintTokenFlow::OnGetTokenSuccess(
39 const std::string& access_token) {
40 login_access_token_ = access_token;
41 EndGetLoginAccessToken(NULL);
42 }
43 void OAuth2MintTokenFlow::OnGetTokenFailure(
44 const GoogleServiceAuthError& error) {
45 EndGetLoginAccessToken(&error);
46 }
47
48 void OAuth2MintTokenFlow::BeginGetLoginAccessToken() {
49 CHECK_EQ(INITIAL, state_);
50 state_ = FETCH_LOGIN_ACCESS_TOKEN_STARTED;
51
52 oauth2_access_token_fetcher_.reset(CreateAccessTokenFetcher());
53 oauth2_access_token_fetcher_->Start(
54 GaiaUrls::GetInstance()->oauth2_chrome_client_id(),
55 GaiaUrls::GetInstance()->oauth2_chrome_client_secret(),
56 login_refresh_token_,
57 std::vector<std::string>());
58 }
59
60 void OAuth2MintTokenFlow::EndGetLoginAccessToken(
61 const GoogleServiceAuthError* error) {
62 CHECK_EQ(FETCH_LOGIN_ACCESS_TOKEN_STARTED, state_);
63 if (!error) {
64 state_ = FETCH_LOGIN_ACCESS_TOKEN_DONE;
65 BeginMintAccessToken();
66 } else {
67 state_ = ERROR_STATE;
68 ReportFailure(*error);
69 }
70 }
71
72 void OAuth2MintTokenFlow::OnMintTokenSuccess(
73 const std::string& access_token) {
74 app_access_token_ = access_token;
75 EndMintAccessToken(NULL);
76 }
77 void OAuth2MintTokenFlow::OnMintTokenFailure(
78 const GoogleServiceAuthError& error) {
79 EndMintAccessToken(&error);
80 }
81
82 void OAuth2MintTokenFlow::BeginMintAccessToken() {
83 CHECK_EQ(FETCH_LOGIN_ACCESS_TOKEN_DONE, state_);
84 state_ = MINT_ACCESS_TOKEN_STARTED;
85
86 oauth2_mint_token_fetcher_.reset(CreateMintTokenFetcher());
87 oauth2_mint_token_fetcher_->Start(
88 login_access_token_,
89 client_id_,
90 scopes_,
91 extension_id_);
92 }
93
94 void OAuth2MintTokenFlow::EndMintAccessToken(
95 const GoogleServiceAuthError* error) {
96 CHECK_EQ(MINT_ACCESS_TOKEN_STARTED, state_);
97
98 if (!error) {
99 state_ = MINT_ACCESS_TOKEN_DONE;
100 ReportSuccess();
101 } else {
102 state_ = ERROR_STATE;
103 ReportFailure(*error);
104 }
105 }
106
107 void OAuth2MintTokenFlow::ReportSuccess() {
108 CHECK_EQ(MINT_ACCESS_TOKEN_DONE, state_);
109
110 if (delegate_) {
111 delegate_->OnMintTokenSuccess(app_access_token_);
112 }
113 }
114
115 void OAuth2MintTokenFlow::ReportFailure(
116 const GoogleServiceAuthError& error) {
117 CHECK_EQ(ERROR_STATE, state_);
118
119 if (delegate_) {
120 delegate_->OnMintTokenFailure(error);
121 }
122 }
123
124 OAuth2AccessTokenFetcher* OAuth2MintTokenFlow::CreateAccessTokenFetcher() {
125 return new OAuth2AccessTokenFetcher(this, context_);
126 }
127
128 OAuth2MintTokenFetcher* OAuth2MintTokenFlow::CreateMintTokenFetcher() {
129 return new OAuth2MintTokenFetcher(this, context_, "OAuth2MintTokenFlow");
130 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698