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_FETCHER_H_ | 5 #ifndef CHROME_COMMON_NET_GAIA_OAUTH2_MINT_TOKEN_FETCHER_H_ |
6 #define CHROME_COMMON_NET_GAIA_OAUTH2_MINT_TOKEN_FETCHER_H_ | 6 #define CHROME_COMMON_NET_GAIA_OAUTH2_MINT_TOKEN_FETCHER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "chrome/common/net/gaia/oauth2_mint_token_consumer.h" | 14 #include "chrome/common/net/gaia/oauth2_mint_token_consumer.h" |
15 #include "content/public/common/url_fetcher.h" | |
16 #include "content/public/common/url_fetcher_delegate.h" | |
17 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
| 16 #include "net/url_request/url_fetcher_delegate.h" |
18 | 17 |
19 class OAuth2MintTokenFetcherTest; | 18 class OAuth2MintTokenFetcherTest; |
20 | 19 |
21 namespace net { | 20 namespace net { |
| 21 class URLFetcher; |
22 class URLRequestContextGetter; | 22 class URLRequestContextGetter; |
23 class URLRequestStatus; | 23 class URLRequestStatus; |
24 } | 24 } |
25 | 25 |
26 // Abstracts the details to mint new OAuth2 tokens from OAuth2 login scoped | 26 // Abstracts the details to mint new OAuth2 tokens from OAuth2 login scoped |
27 // token. | 27 // token. |
28 // | 28 // |
29 // This class should be used on a single thread, but it can be whichever thread | 29 // This class should be used on a single thread, but it can be whichever thread |
30 // that you like. | 30 // that you like. |
31 // Also, do not reuse the same instance. Once Start() is called, the instance | 31 // Also, do not reuse the same instance. Once Start() is called, the instance |
32 // should not be reused. | 32 // should not be reused. |
33 // | 33 // |
34 // Usage: | 34 // Usage: |
35 // * Create an instance with a consumer. | 35 // * Create an instance with a consumer. |
36 // * Call Start() | 36 // * Call Start() |
37 // * The consumer passed in the constructor will be called on the same | 37 // * The consumer passed in the constructor will be called on the same |
38 // thread Start was called with the results. | 38 // thread Start was called with the results. |
39 // | 39 // |
40 // This class can handle one request at a time. To parallelize requests, | 40 // This class can handle one request at a time. To parallelize requests, |
41 // create multiple instances. | 41 // create multiple instances. |
42 class OAuth2MintTokenFetcher : public content::URLFetcherDelegate { | 42 class OAuth2MintTokenFetcher : public net::URLFetcherDelegate { |
43 public: | 43 public: |
44 OAuth2MintTokenFetcher(OAuth2MintTokenConsumer* consumer, | 44 OAuth2MintTokenFetcher(OAuth2MintTokenConsumer* consumer, |
45 net::URLRequestContextGetter* getter, | 45 net::URLRequestContextGetter* getter, |
46 const std::string& source); | 46 const std::string& source); |
47 virtual ~OAuth2MintTokenFetcher(); | 47 virtual ~OAuth2MintTokenFetcher(); |
48 | 48 |
49 // Start the flow. | 49 // Start the flow. |
50 virtual void Start(const std::string& oauth_login_access_token, | 50 virtual void Start(const std::string& oauth_login_access_token, |
51 const std::string& client_id, | 51 const std::string& client_id, |
52 const std::vector<std::string>& scopes, | 52 const std::vector<std::string>& scopes, |
53 const std::string& origin); | 53 const std::string& origin); |
54 | 54 |
55 void CancelRequest(); | 55 void CancelRequest(); |
56 | 56 |
57 // Implementation of content::URLFetcherDelegate | 57 // Implementation of net::URLFetcherDelegate |
58 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 58 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
59 | 59 |
60 private: | 60 private: |
61 enum State { | 61 enum State { |
62 INITIAL, | 62 INITIAL, |
63 MINT_TOKEN_STARTED, | 63 MINT_TOKEN_STARTED, |
64 MINT_TOKEN_DONE, | 64 MINT_TOKEN_DONE, |
65 ERROR_STATE, | 65 ERROR_STATE, |
66 }; | 66 }; |
67 | 67 |
(...skipping 14 matching lines...) Expand all Loading... |
82 static bool ParseMintTokenResponse(const net::URLFetcher* source, | 82 static bool ParseMintTokenResponse(const net::URLFetcher* source, |
83 std::string* access_token); | 83 std::string* access_token); |
84 | 84 |
85 // State that is set during construction. | 85 // State that is set during construction. |
86 OAuth2MintTokenConsumer* const consumer_; | 86 OAuth2MintTokenConsumer* const consumer_; |
87 net::URLRequestContextGetter* const getter_; | 87 net::URLRequestContextGetter* const getter_; |
88 std::string source_; | 88 std::string source_; |
89 State state_; | 89 State state_; |
90 | 90 |
91 // While a fetch is in progress. | 91 // While a fetch is in progress. |
92 scoped_ptr<content::URLFetcher> fetcher_; | 92 scoped_ptr<net::URLFetcher> fetcher_; |
93 std::string oauth_login_access_token_; | 93 std::string oauth_login_access_token_; |
94 std::string client_id_; | 94 std::string client_id_; |
95 std::vector<std::string> scopes_; | 95 std::vector<std::string> scopes_; |
96 std::string origin_; | 96 std::string origin_; |
97 | 97 |
98 friend class OAuth2MintTokenFetcherTest; | 98 friend class OAuth2MintTokenFetcherTest; |
99 FRIEND_TEST_ALL_PREFIXES(OAuth2MintTokenFetcherTest, | 99 FRIEND_TEST_ALL_PREFIXES(OAuth2MintTokenFetcherTest, |
100 ParseMintTokenResponse); | 100 ParseMintTokenResponse); |
101 | 101 |
102 DISALLOW_COPY_AND_ASSIGN(OAuth2MintTokenFetcher); | 102 DISALLOW_COPY_AND_ASSIGN(OAuth2MintTokenFetcher); |
103 }; | 103 }; |
104 | 104 |
105 #endif // CHROME_COMMON_NET_GAIA_OAUTH2_MINT_TOKEN_FETCHER_H_ | 105 #endif // CHROME_COMMON_NET_GAIA_OAUTH2_MINT_TOKEN_FETCHER_H_ |
OLD | NEW |