Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #ifndef CHROME_COMMON_NET_GAIA_OAUTH2_MINT_TOKEN_FLOW_H_ | 5 #ifndef CHROME_COMMON_NET_GAIA_OAUTH2_MINT_TOKEN_FLOW_H_ |
| 6 #define CHROME_COMMON_NET_GAIA_OAUTH2_MINT_TOKEN_FLOW_H_ | 6 #define CHROME_COMMON_NET_GAIA_OAUTH2_MINT_TOKEN_FLOW_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/memory/ref_counted.h" | |
| 11 #include "chrome/common/net/gaia/oauth2_api_call_flow.h" | 12 #include "chrome/common/net/gaia/oauth2_api_call_flow.h" |
| 12 | 13 |
| 13 class GoogleServiceAuthError; | 14 class GoogleServiceAuthError; |
| 14 class OAuth2MintTokenFlowTest; | 15 class OAuth2MintTokenFlowTest; |
| 15 | 16 |
| 16 namespace base { | 17 namespace base { |
| 17 class DictionaryValue; | 18 class DictionaryValue; |
| 18 } | 19 } |
| 19 | 20 |
| 20 namespace content { | 21 namespace content { |
| 21 class URLFetcher; | 22 class URLFetcher; |
| 22 } | 23 } |
| 23 | 24 |
| 24 namespace net { | 25 namespace net { |
| 25 class URLRequestContextGetter; | 26 class URLRequestContextGetter; |
| 26 } | 27 } |
| 27 | 28 |
| 28 // IssueAdvice: messages to show to the user to get a user's approval. | 29 // IssueAdvice: messages to show to the user to get a user's approval. |
| 29 // The structure is as follows: | 30 // The structure is as follows: |
| 30 // * Descritpion 1 | 31 // * Description 1 |
| 31 // - Detail 1.1 | 32 // - Detail 1.1 |
| 32 // - Details 1.2 | 33 // - Details 1.2 |
| 33 // * Description 2 | 34 // * Description 2 |
| 34 // - Detail 2.1 | 35 // - Detail 2.1 |
| 35 // - Detail 2.2 | 36 // - Detail 2.2 |
| 36 // - Detail 2.3 | 37 // - Detail 2.3 |
| 37 // * Description 3 | 38 // * Description 3 |
| 38 // - Detail 3.1 | 39 // - Detail 3.1 |
| 39 struct IssueAdviceInfoEntry { | 40 struct IssueAdviceInfoEntry { |
| 40 public: | 41 public: |
| 41 IssueAdviceInfoEntry(); | 42 IssueAdviceInfoEntry(); |
| 42 ~IssueAdviceInfoEntry(); | 43 ~IssueAdviceInfoEntry(); |
| 43 | 44 |
| 44 std::string description; | 45 std::string description; |
| 45 std::vector<std::string> details; | 46 std::vector<std::string> details; |
| 46 | 47 |
| 47 bool operator==(const IssueAdviceInfoEntry& rhs) const; | 48 bool operator==(const IssueAdviceInfoEntry& rhs) const; |
| 48 }; | 49 }; |
| 49 | 50 |
| 50 typedef std::vector<IssueAdviceInfoEntry> IssueAdviceInfo; | 51 typedef std::vector<IssueAdviceInfoEntry> IssueAdviceInfo; |
| 51 | 52 |
| 52 // This class implements the OAuth2 flow to Google to mint an OAuth2 | 53 // This class implements the OAuth2 flow to Google to mint an OAuth2 |
| 53 // token for the given client and the given set of scopes from the | 54 // token for the given client and the given set of scopes from the |
| 54 // OAuthLogin scoped "master" OAuth2 token for the user logged in to | 55 // OAuthLogin scoped "master" OAuth2 token for the user logged in to |
| 55 // Chrome. | 56 // Chrome. |
| 56 class OAuth2MintTokenFlow : public OAuth2ApiCallFlow { | 57 class OAuth2MintTokenFlow : public OAuth2ApiCallFlow, |
| 58 public base::RefCounted<OAuth2MintTokenFlow> { | |
|
Munjal (Google)
2012/06/25 20:40:09
Is there anyway we can avoid making this a ref cou
Evan Stade
2012/06/26 00:56:03
changed to use weak ptrs.
| |
| 57 public: | 59 public: |
| 58 // There are four differnt modes when minting a token to grant | 60 // There are four differnt modes when minting a token to grant |
| 59 // access to third-party app for a user. | 61 // access to third-party app for a user. |
| 60 enum Mode { | 62 enum Mode { |
| 61 // Get the messages to display to the user without minting a token. | 63 // Get the messages to display to the user without minting a token. |
| 62 MODE_ISSUE_ADVICE, | 64 MODE_ISSUE_ADVICE, |
| 63 // Record a grant but do not get a token back. | 65 // Record a grant but do not get a token back. |
| 64 MODE_RECORD_GRANT, | 66 MODE_RECORD_GRANT, |
| 65 // Mint a token for an existing grant. | 67 // Mint a token for an existing grant. |
| 66 MODE_MINT_TOKEN_NO_FORCE, | 68 MODE_MINT_TOKEN_NO_FORCE, |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 friend class OAuth2MintTokenFlowTest; | 132 friend class OAuth2MintTokenFlowTest; |
| 131 FRIEND_TEST_ALL_PREFIXES(OAuth2MintTokenFlowTest, CreateApiCallBody); | 133 FRIEND_TEST_ALL_PREFIXES(OAuth2MintTokenFlowTest, CreateApiCallBody); |
| 132 FRIEND_TEST_ALL_PREFIXES(OAuth2MintTokenFlowTest, ParseIssueAdviceResponse); | 134 FRIEND_TEST_ALL_PREFIXES(OAuth2MintTokenFlowTest, ParseIssueAdviceResponse); |
| 133 FRIEND_TEST_ALL_PREFIXES(OAuth2MintTokenFlowTest, ParseMintTokenResponse); | 135 FRIEND_TEST_ALL_PREFIXES(OAuth2MintTokenFlowTest, ParseMintTokenResponse); |
| 134 FRIEND_TEST_ALL_PREFIXES(OAuth2MintTokenFlowTest, ProcessApiCallSuccess); | 136 FRIEND_TEST_ALL_PREFIXES(OAuth2MintTokenFlowTest, ProcessApiCallSuccess); |
| 135 FRIEND_TEST_ALL_PREFIXES(OAuth2MintTokenFlowTest, ProcessApiCallFailure); | 137 FRIEND_TEST_ALL_PREFIXES(OAuth2MintTokenFlowTest, ProcessApiCallFailure); |
| 136 FRIEND_TEST_ALL_PREFIXES(OAuth2MintTokenFlowTest, | 138 FRIEND_TEST_ALL_PREFIXES(OAuth2MintTokenFlowTest, |
| 137 ProcessMintAccessTokenFailure); | 139 ProcessMintAccessTokenFailure); |
| 138 | 140 |
| 139 void ReportSuccess(const std::string& access_token); | 141 void ReportSuccess(const std::string& access_token); |
| 140 void ReportSuccess(const IssueAdviceInfo& issue_advice); | 142 void ReportIssueAdviceSuccess(const IssueAdviceInfo& issue_advice); |
| 141 void ReportFailure(const GoogleServiceAuthError& error); | 143 void ReportFailure(const GoogleServiceAuthError& error); |
| 142 | 144 |
| 143 static bool ParseIssueAdviceResponse( | 145 static bool ParseIssueAdviceResponse( |
| 144 const base::DictionaryValue* dict, IssueAdviceInfo* issue_advice); | 146 const base::DictionaryValue* dict, IssueAdviceInfo* issue_advice); |
| 145 static bool ParseMintTokenResponse( | 147 static bool ParseMintTokenResponse( |
| 146 const base::DictionaryValue* dict, std::string* access_token); | 148 const base::DictionaryValue* dict, std::string* access_token); |
| 147 | 149 |
| 148 net::URLRequestContextGetter* context_; | 150 net::URLRequestContextGetter* context_; |
| 149 Delegate* delegate_; | 151 Delegate* delegate_; |
| 150 Parameters parameters_; | 152 Parameters parameters_; |
| 151 | 153 |
| 152 DISALLOW_COPY_AND_ASSIGN(OAuth2MintTokenFlow); | 154 DISALLOW_COPY_AND_ASSIGN(OAuth2MintTokenFlow); |
| 153 }; | 155 }; |
| 154 | 156 |
| 155 #endif // CHROME_COMMON_NET_GAIA_OAUTH2_MINT_TOKEN_FLOW_H_ | 157 #endif // CHROME_COMMON_NET_GAIA_OAUTH2_MINT_TOKEN_FLOW_H_ |
| OLD | NEW |