OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_ACCESS_TOKEN_FETCHER_H_ | 5 #ifndef CHROME_COMMON_NET_GAIA_OAUTH2_ACCESS_TOKEN_FETCHER_H_ |
6 #define CHROME_COMMON_NET_GAIA_OAUTH2_ACCESS_TOKEN_FETCHER_H_ | 6 #define CHROME_COMMON_NET_GAIA_OAUTH2_ACCESS_TOKEN_FETCHER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 // create multiple instances. | 42 // create multiple instances. |
43 class OAuth2AccessTokenFetcher : public content::URLFetcherDelegate { | 43 class OAuth2AccessTokenFetcher : public content::URLFetcherDelegate { |
44 public: | 44 public: |
45 OAuth2AccessTokenFetcher(OAuth2AccessTokenConsumer* consumer, | 45 OAuth2AccessTokenFetcher(OAuth2AccessTokenConsumer* consumer, |
46 net::URLRequestContextGetter* getter, | 46 net::URLRequestContextGetter* getter, |
47 const std::string& source); | 47 const std::string& source); |
48 virtual ~OAuth2AccessTokenFetcher(); | 48 virtual ~OAuth2AccessTokenFetcher(); |
49 | 49 |
50 void Start(const std::string& client_id, | 50 void Start(const std::string& client_id, |
51 const std::string& client_secret, | 51 const std::string& client_secret, |
52 const std::string& refresh_token); | 52 const std::string& refresh_token, |
| 53 const std::vector<std::string>& scopes); |
53 | 54 |
54 void CancelRequest(); | 55 void CancelRequest(); |
55 | 56 |
56 // Implementation of content::URLFetcherDelegate | 57 // Implementation of content::URLFetcherDelegate |
57 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; | 58 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; |
58 | 59 |
59 private: | 60 private: |
60 enum State { | 61 enum State { |
61 INITIAL, | 62 INITIAL, |
62 GET_ACCESS_TOKEN_STARTED, | 63 GET_ACCESS_TOKEN_STARTED, |
63 GET_ACCESS_TOKEN_DONE, | 64 GET_ACCESS_TOKEN_DONE, |
64 ERROR_STATE, | 65 ERROR_STATE, |
65 }; | 66 }; |
66 | 67 |
67 // Helper methods for the flow. | 68 // Helper methods for the flow. |
68 void StartGetAccessToken(); | 69 void StartGetAccessToken(); |
69 void EndGetAccessToken(const content::URLFetcher* source); | 70 void EndGetAccessToken(const content::URLFetcher* source); |
70 | 71 |
71 // Helper mehtods for reporting back results. | 72 // Helper mehtods for reporting back results. |
72 void OnGetTokenSuccess(const std::string& access_token); | 73 void OnGetTokenSuccess(const std::string& access_token); |
73 void OnGetTokenFailure(GoogleServiceAuthError error); | 74 void OnGetTokenFailure(GoogleServiceAuthError error); |
74 | 75 |
75 // Other helpers. | 76 // Other helpers. |
76 static GURL MakeGetAccessTokenUrl(); | 77 static GURL MakeGetAccessTokenUrl(); |
77 static std::string MakeGetAccessTokenBody(const std::string& client_id, | 78 static std::string MakeGetAccessTokenBody( |
78 const std::string& client_secret, | 79 const std::string& client_id, |
79 const std::string& refresh_token); | 80 const std::string& client_secret, |
| 81 const std::string& refresh_token, |
| 82 const std::vector<std::string>& scopes); |
80 static bool ParseGetAccessTokenResponse(const content::URLFetcher* source, | 83 static bool ParseGetAccessTokenResponse(const content::URLFetcher* source, |
81 std::string* access_token); | 84 std::string* access_token); |
82 | 85 |
83 // State that is set during construction. | 86 // State that is set during construction. |
84 OAuth2AccessTokenConsumer* const consumer_; | 87 OAuth2AccessTokenConsumer* const consumer_; |
85 net::URLRequestContextGetter* const getter_; | 88 net::URLRequestContextGetter* const getter_; |
86 std::string source_; | 89 std::string source_; |
87 State state_; | 90 State state_; |
88 | 91 |
89 // While a fetch is in progress. | 92 // While a fetch is in progress. |
90 scoped_ptr<content::URLFetcher> fetcher_; | 93 scoped_ptr<content::URLFetcher> fetcher_; |
91 std::string client_id_; | 94 std::string client_id_; |
92 std::string client_secret_; | 95 std::string client_secret_; |
93 std::string refresh_token_; | 96 std::string refresh_token_; |
| 97 std::vector<std::string> scopes_; |
94 | 98 |
95 friend class OAuth2AccessTokenFetcherTest; | 99 friend class OAuth2AccessTokenFetcherTest; |
96 FRIEND_TEST_ALL_PREFIXES(OAuth2AccessTokenFetcherTest, | 100 FRIEND_TEST_ALL_PREFIXES(OAuth2AccessTokenFetcherTest, |
97 ParseGetAccessTokenResponse); | 101 ParseGetAccessTokenResponse); |
| 102 FRIEND_TEST_ALL_PREFIXES(OAuth2AccessTokenFetcherTest, |
| 103 MakeGetAccessTokenBody); |
98 | 104 |
99 DISALLOW_COPY_AND_ASSIGN(OAuth2AccessTokenFetcher); | 105 DISALLOW_COPY_AND_ASSIGN(OAuth2AccessTokenFetcher); |
100 }; | 106 }; |
101 | 107 |
102 #endif // CHROME_COMMON_NET_GAIA_OAUTH2_ACCESS_TOKEN_FETCHER_H_ | 108 #endif // CHROME_COMMON_NET_GAIA_OAUTH2_ACCESS_TOKEN_FETCHER_H_ |
OLD | NEW |