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

Side by Side Diff: chrome/common/net/gaia/oauth2_access_token_fetcher.h

Issue 8728038: Allow passing in a list of scopes to the access token fetcher class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years 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
« no previous file with comments | « no previous file | chrome/common/net/gaia/oauth2_access_token_fetcher.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 25 matching lines...) Expand all
36 // * Create an instance with a consumer. 36 // * Create an instance with a consumer.
37 // * Call Start() 37 // * Call Start()
38 // * The consumer passed in the constructor will be called on the same 38 // * The consumer passed in the constructor will be called on the same
39 // thread Start was called with the results. 39 // thread Start was called with the results.
40 // 40 //
41 // This class can handle one request at a time. To parallelize requests, 41 // This class can handle one request at a time. To parallelize requests,
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);
48 virtual ~OAuth2AccessTokenFetcher(); 47 virtual ~OAuth2AccessTokenFetcher();
49 48
49 // Starts the flow with the given parameters.
50 // |scopes| can be empty. If it is empty then the access token will have the
51 // same scope as the refresh token. If not empty, then access token will have
52 // the scopes specified. In this case, the access token will successfully be
53 // generated only if refresh token has login scope of a list of scopes that is
54 // a super-set of the specified scopes.
50 void Start(const std::string& client_id, 55 void Start(const std::string& client_id,
51 const std::string& client_secret, 56 const std::string& client_secret,
52 const std::string& refresh_token); 57 const std::string& refresh_token,
58 const std::vector<std::string>& scopes);
53 59
54 void CancelRequest(); 60 void CancelRequest();
55 61
56 // Implementation of content::URLFetcherDelegate 62 // Implementation of content::URLFetcherDelegate
57 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; 63 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE;
58 64
59 private: 65 private:
60 enum State { 66 enum State {
61 INITIAL, 67 INITIAL,
62 GET_ACCESS_TOKEN_STARTED, 68 GET_ACCESS_TOKEN_STARTED,
63 GET_ACCESS_TOKEN_DONE, 69 GET_ACCESS_TOKEN_DONE,
64 ERROR_STATE, 70 ERROR_STATE,
65 }; 71 };
66 72
67 // Helper methods for the flow. 73 // Helper methods for the flow.
68 void StartGetAccessToken(); 74 void StartGetAccessToken();
69 void EndGetAccessToken(const content::URLFetcher* source); 75 void EndGetAccessToken(const content::URLFetcher* source);
70 76
71 // Helper mehtods for reporting back results. 77 // Helper mehtods for reporting back results.
72 void OnGetTokenSuccess(const std::string& access_token); 78 void OnGetTokenSuccess(const std::string& access_token);
73 void OnGetTokenFailure(GoogleServiceAuthError error); 79 void OnGetTokenFailure(GoogleServiceAuthError error);
74 80
75 // Other helpers. 81 // Other helpers.
76 static GURL MakeGetAccessTokenUrl(); 82 static GURL MakeGetAccessTokenUrl();
77 static std::string MakeGetAccessTokenBody(const std::string& client_id, 83 static std::string MakeGetAccessTokenBody(
78 const std::string& client_secret, 84 const std::string& client_id,
79 const std::string& refresh_token); 85 const std::string& client_secret,
86 const std::string& refresh_token,
87 const std::vector<std::string>& scopes);
80 static bool ParseGetAccessTokenResponse(const content::URLFetcher* source, 88 static bool ParseGetAccessTokenResponse(const content::URLFetcher* source,
81 std::string* access_token); 89 std::string* access_token);
82 90
83 // State that is set during construction. 91 // State that is set during construction.
84 OAuth2AccessTokenConsumer* const consumer_; 92 OAuth2AccessTokenConsumer* const consumer_;
85 net::URLRequestContextGetter* const getter_; 93 net::URLRequestContextGetter* const getter_;
86 std::string source_;
87 State state_; 94 State state_;
88 95
89 // While a fetch is in progress. 96 // While a fetch is in progress.
90 scoped_ptr<content::URLFetcher> fetcher_; 97 scoped_ptr<content::URLFetcher> fetcher_;
91 std::string client_id_; 98 std::string client_id_;
92 std::string client_secret_; 99 std::string client_secret_;
93 std::string refresh_token_; 100 std::string refresh_token_;
101 std::vector<std::string> scopes_;
94 102
95 friend class OAuth2AccessTokenFetcherTest; 103 friend class OAuth2AccessTokenFetcherTest;
96 FRIEND_TEST_ALL_PREFIXES(OAuth2AccessTokenFetcherTest, 104 FRIEND_TEST_ALL_PREFIXES(OAuth2AccessTokenFetcherTest,
97 ParseGetAccessTokenResponse); 105 ParseGetAccessTokenResponse);
106 FRIEND_TEST_ALL_PREFIXES(OAuth2AccessTokenFetcherTest,
107 MakeGetAccessTokenBody);
98 108
99 DISALLOW_COPY_AND_ASSIGN(OAuth2AccessTokenFetcher); 109 DISALLOW_COPY_AND_ASSIGN(OAuth2AccessTokenFetcher);
100 }; 110 };
101 111
102 #endif // CHROME_COMMON_NET_GAIA_OAUTH2_ACCESS_TOKEN_FETCHER_H_ 112 #endif // CHROME_COMMON_NET_GAIA_OAUTH2_ACCESS_TOKEN_FETCHER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/common/net/gaia/oauth2_access_token_fetcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698